Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service: cleanup tests #871

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions service/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ func testDependencyLogs(t *testing.T, do func(s *Service, c container.Container,
go wstd.Write(stdData)
go werr.Write(errData)

s := &Service{
Hash: "1",
Dependencies: []*Dependency{
{Key: dependencyKey},
},
}
mc := &mocks.Container{}
var (
s = &Service{
Hash: "1",
Dependencies: []*Dependency{
{Key: dependencyKey},
},
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
mc.On("ServiceLogs", d.namespace(s.namespace())).Once().Return(rp, nil)
Expand Down
2 changes: 2 additions & 0 deletions service/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestGetEvent(t *testing.T) {
},
}
)

e, err := s.GetEvent(eventKey)
require.NoError(t, err)
require.Equal(t, eventKey, e.Key)
Expand All @@ -31,6 +32,7 @@ func TestGetEventNonExistent(t *testing.T) {
},
}
)

e, err := s.GetEvent(eventKey)
require.Zero(t, e)
require.Equal(t, &EventNotFoundError{
Expand Down
62 changes: 34 additions & 28 deletions service/logs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ import (
)

func TestIntegrationLogs(t *testing.T) {
service := &Service{
Hash: "1",
Name: "TestLogs",
Dependencies: []*Dependency{
{
Key: "test",
Image: "http-server",
var (
service = &Service{
Hash: "1",
Name: "TestLogs",
Dependencies: []*Dependency{
{
Key: "test",
Image: "http-server",
},
{
Key: "test2",
Image: "http-server",
},
},
{
Key: "test2",
Image: "http-server",
},
},
}
c := newIntegrationContainer(t)
}
c = newIntegrationContainer(t)
)

service.Start(c)
defer service.Stop(c)
readers, err := service.Logs(c)
Expand All @@ -32,21 +35,24 @@ func TestIntegrationLogs(t *testing.T) {
}

func TestIntegrationLogsOnlyOneDependency(t *testing.T) {
service := &Service{
Hash: "1",
Name: "TestLogsOnlyOneDependency",
Dependencies: []*Dependency{
{
Key: "test",
Image: "http-server",
var (
service = &Service{
Hash: "1",
Name: "TestLogsOnlyOneDependency",
Dependencies: []*Dependency{
{
Key: "test",
Image: "http-server",
},
{
Key: "test2",
Image: "http-server",
},
},
{
Key: "test2",
Image: "http-server",
},
},
}
c := newIntegrationContainer(t)
}
c = newIntegrationContainer(t)
)

service.Start(c)
defer service.Stop(c)
readers, err := service.Logs(c, "test2")
Expand Down
17 changes: 10 additions & 7 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func TestNew(t *testing.T) {
var (
path = "../service-test/task"
hash = "1"
mc = &mocks.Container{}
)

mc := &mocks.Container{}
mc.On("Build", mock.Anything).Once().Return(hash, nil)

statuses := make(chan DeployStatus, 4)
Expand Down Expand Up @@ -45,9 +45,9 @@ func TestNewWithDefaultEnv(t *testing.T) {
path = "../service-test/env"
hash = "1"
env = []string{"A=1", "B=2"}
mc = &mocks.Container{}
)

mc := &mocks.Container{}
mc.On("Build", mock.Anything).Once().Return(hash, nil)

s, err := New(path, mc, nil, nil)
Expand All @@ -64,9 +64,9 @@ func TestNewWithOverwrittenEnv(t *testing.T) {
path = "../service-test/env"
hash = "1"
env = []string{"A=3", "B=4"}
mc = &mocks.Container{}
)

mc := &mocks.Container{}
mc.On("Build", mock.Anything).Once().Return(hash, nil)

s, err := New(path, mc, nil, xos.EnvSliceToMap(env))
Expand All @@ -81,10 +81,9 @@ func TestNewWithOverwrittenEnv(t *testing.T) {
func TestNewWitNotDefinedEnv(t *testing.T) {
var (
path = "../service-test/task"
mc = &mocks.Container{}
)

mc := &mocks.Container{}

_, err := New(path, mc, nil, xos.EnvSliceToMap([]string{"A=1", "B=2"}))
require.Equal(t, ErrNotDefinedEnv{[]string{"A", "B"}}, err)

Expand All @@ -97,8 +96,11 @@ func TestErrNotDefinedEnv(t *testing.T) {
}

func TestInjectDefinitionWithConfig(t *testing.T) {
command := "xxx"
s := &Service{}
var (
command = "xxx"
s = &Service{}
)

s.injectDefinition(&importer.ServiceDefinition{
Configuration: &importer.Dependency{
Command: command,
Expand All @@ -112,6 +114,7 @@ func TestInjectDefinitionWithDependency(t *testing.T) {
s = &Service{}
image = "xxx"
)

s.injectDefinition(&importer.ServiceDefinition{
Dependencies: map[string]*importer.Dependency{
"test": {
Expand Down
Loading