diff options
author | Wolfy-J <[email protected]> | 2018-07-08 21:44:14 -0700 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-07-08 21:44:14 -0700 |
commit | 74a9664f7df21ef26d0718aa2f8239a0562566c6 (patch) | |
tree | 38cc86925b1e58f7d9c6bf6e6c829365fc0c35cd | |
parent | 7494ed6d6a9ab94603d017a48d244f077aaa7575 (diff) |
more tests
-rw-r--r-- | service/container_test.go | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/service/container_test.go b/service/container_test.go index d2ca1f03..fbafe809 100644 --- a/service/container_test.go +++ b/service/container_test.go @@ -326,18 +326,46 @@ func TestContainer_ServeErrorMultiple(t *testing.T) { assert.Equal(t, StatusStopped, st) } -//func TestContainer_Init(t *testing.T) { -// logger, hook := test.NewNullLogger() -// logger.SetLevel(logrus.DebugLevel) -// -// svc := &testService{ok: true} -// -// c := NewContainer(logger) -// c.Register("test", svc) -// c.Register("test2", struct{}{}) -// -// assert.Equal(t, 2, len(hook.Entries)) -// -// assert.NoError(t, c.Serve()) -// c.Stop() -//} +type testInitA struct{} + +func (t *testInitA) Init() error { + return nil +} + +type testInitB struct{} + +func (t *testInitB) Init() (int, error) { + return 0, nil +} + +func TestContainer_InitErrorA(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := NewContainer(logger) + c.Register("test", &testInitA{}) + + assert.Error(t, c.Init(&testCfg{`{"test":"something", "test2":"something-else"}`})) +} + +func TestContainer_InitErrorB(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := NewContainer(logger) + c.Register("test", &testInitB{}) + + assert.Error(t, c.Init(&testCfg{`{"test":"something", "test2":"something-else"}`})) +} + +type testInitC struct{} + +func TestContainer_NoInit(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := NewContainer(logger) + c.Register("test", &testInitC{}) + + assert.NoError(t, c.Init(&testCfg{`{"test":"something", "test2":"something-else"}`})) +} |