From 899efb0a74f0d281b8aebee9348607ab98af4845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=CC=87lker=20Go=CC=88ktug=CC=86=20O=CC=88ztu=CC=88rk?= Date: Thu, 11 Apr 2019 12:24:51 +0300 Subject: [PATCH] service: simplify tests by removing unneded newFromServiceAndContainerMocks func --- service/dependency_test.go | 6 ++++-- service/service_test.go | 5 ----- service/start_test.go | 30 ++++++++++++++++++------------ service/status_test.go | 26 ++++++++++++++++---------- service/stop_test.go | 11 +++++++---- service/volume_test.go | 6 ++++-- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/service/dependency_test.go b/service/dependency_test.go index 664e0d7a0..76ddefa61 100644 --- a/service/dependency_test.go +++ b/service/dependency_test.go @@ -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" ) @@ -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) diff --git a/service/service_test.go b/service/service_test.go index 739c00802..5c0baab38 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -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" diff --git a/service/start_test.go b/service/start_test.go index cc6bc49c3..c87049273 100644 --- a/service/start_test.go +++ b/service/start_test.go @@ -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, @@ -96,7 +96,8 @@ func TestStartService(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) @@ -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{ @@ -137,7 +138,8 @@ func TestStartWith2Dependencies(t *testing.T) { Image: dependencyImage2, }, }, - }) + } + mc = &mocks.Container{} ) var ( @@ -169,7 +171,7 @@ func TestStartWith2Dependencies(t *testing.T) { func TestStartServiceRunning(t *testing.T) { var ( dependencyKey = "1" - s, mc = newFromServiceAndContainerMocks(t, &Service{ + s = &Service{ Hash: "1", Dependencies: []*Dependency{ { @@ -177,7 +179,8 @@ func TestStartServiceRunning(t *testing.T) { Image: "2", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) @@ -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{ @@ -210,7 +213,8 @@ func TestPartiallyRunningService(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) var ( @@ -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{ @@ -257,7 +261,8 @@ func TestStartDependency(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) @@ -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{ @@ -287,7 +292,8 @@ func TestServiceStartError(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) diff --git a/service/status_test.go b/service/status_test.go index 34bf28022..6599b19a0 100644 --- a/service/status_test.go +++ b/service/status_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/mesg-foundation/core/container" + "github.com/mesg-foundation/core/container/mocks" "github.com/stretchr/testify/require" ) @@ -12,7 +13,7 @@ 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{ @@ -21,7 +22,8 @@ func TestUnknownServiceStatus(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) @@ -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{ @@ -47,7 +49,8 @@ func TestStoppedServiceStatus(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) @@ -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{ @@ -73,7 +76,8 @@ func TestRunningServiceStatus(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) @@ -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{ @@ -104,7 +108,8 @@ func TestPartialServiceStatus(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) var ( @@ -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{ @@ -134,7 +139,8 @@ func TestDependencyStatus(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) diff --git a/service/stop_test.go b/service/stop_test.go index 628406934..c808ec961 100644 --- a/service/stop_test.go +++ b/service/stop_test.go @@ -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{ @@ -19,7 +20,8 @@ func TestStopRunningService(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) @@ -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{ @@ -46,7 +48,8 @@ func TestStopDependency(t *testing.T) { Image: "http-server", }, }, - }) + } + mc = &mocks.Container{} ) d, _ := s.getDependency(dependencyKey) diff --git a/service/volume_test.go b/service/volume_test.go index 0be160e92..7fdb1d24f 100644 --- a/service/volume_test.go +++ b/service/volume_test.go @@ -3,6 +3,7 @@ package service import ( "testing" + "github.com/mesg-foundation/core/container/mocks" "github.com/stretchr/testify/require" ) @@ -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{ { @@ -26,7 +27,8 @@ func TestDeleteVolumes(t *testing.T) { VolumesFrom: []string{dependencyKey1}, }, }, - }) + } + mc = &mocks.Container{} ) var (