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: simplify tests #870

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
6 changes: 4 additions & 2 deletions service/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/docker/docker/pkg/stdcopy"
"github.com/mesg-foundation/core/container"
"github.com/mesg-foundation/core/container/mocks"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -34,12 +35,13 @@ func testDependencyLogs(t *testing.T, do func(s *Service, c container.Container,
go wstd.Write(stdData)
go werr.Write(errData)

s, mc := newFromServiceAndContainerMocks(t, &Service{
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
5 changes: 0 additions & 5 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
"github.com/stretchr/testify/require"
)

func newFromServiceAndContainerMocks(t *testing.T, s *Service) (*Service, *mocks.Container) {
_ = t
return s, &mocks.Container{}
}

func TestNew(t *testing.T) {
var (
path = "../service-test/task"
Expand Down
30 changes: 18 additions & 12 deletions service/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestStartService(t *testing.T) {
Sid = "SidStartService"
networkID = "3"
sharedNetworkID = "4"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: serviceName,
Sid: Sid,
Expand All @@ -96,7 +96,8 @@ func TestStartService(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestStartWith2Dependencies(t *testing.T) {
networkID = "7"
sharedNetworkID = "8"
serviceName = "TestStartWith2Dependencies"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: serviceName,
Dependencies: []*Dependency{
Expand All @@ -137,7 +138,8 @@ func TestStartWith2Dependencies(t *testing.T) {
Image: dependencyImage2,
},
},
})
}
mc = &mocks.Container{}
)

var (
Expand Down Expand Up @@ -169,15 +171,16 @@ func TestStartWith2Dependencies(t *testing.T) {
func TestStartServiceRunning(t *testing.T) {
var (
dependencyKey = "1"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Dependencies: []*Dependency{
{
Key: dependencyKey,
Image: "2",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand All @@ -197,7 +200,7 @@ func TestPartiallyRunningService(t *testing.T) {
networkID = "3"
sharedNetworkID = "4"
containerServiceIDs = []string{"5", "6"}
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestPartiallyRunningService",
Dependencies: []*Dependency{
Expand All @@ -210,7 +213,8 @@ func TestPartiallyRunningService(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

var (
Expand Down Expand Up @@ -248,7 +252,7 @@ func TestStartDependency(t *testing.T) {
networkID = "3"
sharedNetworkID = "4"
containerServiceID = "5"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestStartDependency",
Dependencies: []*Dependency{
Expand All @@ -257,7 +261,8 @@ func TestStartDependency(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand All @@ -278,7 +283,7 @@ func TestServiceStartError(t *testing.T) {
networkID = "3"
sharedNetworkID = "4"
startErr = errors.New("ops")
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestNetworkCreated",
Dependencies: []*Dependency{
Expand All @@ -287,7 +292,8 @@ func TestServiceStartError(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand Down
26 changes: 16 additions & 10 deletions service/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"testing"

"github.com/mesg-foundation/core/container"
"github.com/mesg-foundation/core/container/mocks"
"github.com/stretchr/testify/require"
)

func TestUnknownServiceStatus(t *testing.T) {
var (
dependencyKey = "1"
statusErr = errors.New("ops")
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestUnknownServiceStatus",
Dependencies: []*Dependency{
Expand All @@ -21,7 +22,8 @@ func TestUnknownServiceStatus(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand All @@ -38,7 +40,7 @@ func TestUnknownServiceStatus(t *testing.T) {
func TestStoppedServiceStatus(t *testing.T) {
var (
dependencyKey = "1"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestStoppedServiceStatus",
Dependencies: []*Dependency{
Expand All @@ -47,7 +49,8 @@ func TestStoppedServiceStatus(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand All @@ -64,7 +67,7 @@ func TestStoppedServiceStatus(t *testing.T) {
func TestRunningServiceStatus(t *testing.T) {
var (
dependencyKey = "1"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestRunningServiceStatus",
Dependencies: []*Dependency{
Expand All @@ -73,7 +76,8 @@ func TestRunningServiceStatus(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand All @@ -91,7 +95,7 @@ func TestPartialServiceStatus(t *testing.T) {
var (
dependencyKey = "1"
dependencyKey2 = "2"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestPartialServiceStatus",
Dependencies: []*Dependency{
Expand All @@ -104,7 +108,8 @@ func TestPartialServiceStatus(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

var (
Expand All @@ -125,7 +130,7 @@ func TestPartialServiceStatus(t *testing.T) {
func TestDependencyStatus(t *testing.T) {
var (
dependencyKey = "1"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestDependencyStatus",
Dependencies: []*Dependency{
Expand All @@ -134,7 +139,8 @@ func TestDependencyStatus(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand Down
11 changes: 7 additions & 4 deletions service/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"testing"

"github.com/mesg-foundation/core/container"
"github.com/mesg-foundation/core/container/mocks"
"github.com/stretchr/testify/require"
)

func TestStopRunningService(t *testing.T) {
var (
dependencyKey = "1"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestStopRunningService",
Dependencies: []*Dependency{
Expand All @@ -19,7 +20,8 @@ func TestStopRunningService(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand All @@ -37,7 +39,7 @@ func TestStopRunningService(t *testing.T) {
func TestStopDependency(t *testing.T) {
var (
dependencyKey = "1"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Hash: "1",
Name: "TestStopService",
Dependencies: []*Dependency{
Expand All @@ -46,7 +48,8 @@ func TestStopDependency(t *testing.T) {
Image: "http-server",
},
},
})
}
mc = &mocks.Container{}
)

d, _ := s.getDependency(dependencyKey)
Expand Down
6 changes: 4 additions & 2 deletions service/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"testing"

"github.com/mesg-foundation/core/container/mocks"
"github.com/stretchr/testify/require"
)

Expand All @@ -12,7 +13,7 @@ func TestDeleteVolumes(t *testing.T) {
dependencyKey2 = "2"
volumeA = "a"
volumeB = "b"
s, mc = newFromServiceAndContainerMocks(t, &Service{
s = &Service{
Name: "TestCreateVolumes",
Dependencies: []*Dependency{
{
Expand All @@ -26,7 +27,8 @@ func TestDeleteVolumes(t *testing.T) {
VolumesFrom: []string{dependencyKey1},
},
},
})
}
mc = &mocks.Container{}
)

var (
Expand Down