-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
component_test.go
48 lines (38 loc) · 1.05 KB
/
component_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package goyave
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"goyave.dev/goyave/v5/config"
_ "goyave.dev/goyave/v5/database/dialect/sqlite"
)
func TestComponent(t *testing.T) {
cfg := config.LoadDefault()
cfg.Set("database.connection", "sqlite3")
cfg.Set("database.name", "test_component.db")
cfg.Set("database.options", "mode=memory")
server, err := New(Options{Config: cfg})
require.NoError(t, err)
defer func() {
assert.NoError(t, server.CloseDB())
}()
service := &DummyService{}
server.RegisterService(service)
c := &Component{}
c.Init(server)
s, ok := c.LookupService("dummy")
assert.Equal(t, service, s)
assert.True(t, ok)
s = c.Service("dummy")
assert.Equal(t, service, s)
s, ok = c.LookupService("not_a_service")
assert.Nil(t, s)
assert.False(t, ok)
assert.Panics(t, func() {
server.Service("not_a_service")
})
assert.Equal(t, server.Logger, c.Logger())
assert.Equal(t, server.config, c.Config())
assert.Equal(t, server.Lang, c.Lang())
assert.Equal(t, server.db, c.DB())
}