diff --git a/pki/domain/dockerCompose/config_test.go b/pki/domain/dockerCompose/config_test.go index bb19e86..9a3f645 100644 --- a/pki/domain/dockerCompose/config_test.go +++ b/pki/domain/dockerCompose/config_test.go @@ -116,7 +116,7 @@ func TestNetworkIPAM_Equal(t *testing.T) { } } -func TestNetworkIPAM_Config(t *testing.T) { +func TestNetworkIPAMConfig_Equal(t *testing.T) { require := require.New(t) testCases := []struct { @@ -157,7 +157,7 @@ func TestNetworkIPAM_Config(t *testing.T) { } } -func TestSecret_Config(t *testing.T) { +func TestSecret_Equal(t *testing.T) { require := require.New(t) testCases := []struct { @@ -198,6 +198,272 @@ func TestSecret_Config(t *testing.T) { } } +func TestService_Equal(t *testing.T) { + require := require.New(t) + + testCases := []struct { + equalableA dockerCompose.Equalable + equalableB dockerCompose.Equalable + expectedResult bool + }{ + { + equalableA: &dockerCompose.Service{}, + equalableB: &dockerCompose.Secret{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{}, + equalableB: nil, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{}, + equalableB: &dockerCompose.Service{}, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + CapabilitiesAdd: []string{}, + CapabilitiesDrop: []string{}, + Deploy: nil, + Environments: []string{}, + ExtraHosts: []string{}, + Image: "", + Labels: []string{}, + Networks: map[string]*dockerCompose.ServiceNetwork{}, + Ports: []string{}, + Secrets: []string{}, + ULimits: nil, + Volumes: []string{}, + }, + equalableB: &dockerCompose.Service{ + CapabilitiesAdd: []string{}, + CapabilitiesDrop: []string{}, + Deploy: nil, + Environments: []string{}, + ExtraHosts: []string{}, + Image: "", + Labels: []string{}, + Networks: map[string]*dockerCompose.ServiceNetwork{}, + Ports: []string{}, + Secrets: []string{}, + ULimits: nil, + Volumes: []string{}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + CapabilitiesAdd: []string{"NET_ADMIN"}, + }, + equalableB: &dockerCompose.Service{ + CapabilitiesAdd: []string{"NET_ADMIN"}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + CapabilitiesAdd: []string{"NET_ADMIN"}, + }, + equalableB: &dockerCompose.Service{ + CapabilitiesAdd: []string{}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + CapabilitiesDrop: []string{"NET_ADMIN"}, + }, + equalableB: &dockerCompose.Service{ + CapabilitiesDrop: []string{"NET_ADMIN"}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + CapabilitiesDrop: []string{"NET_ADMIN"}, + }, + equalableB: &dockerCompose.Service{ + CapabilitiesDrop: []string{}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Deploy: &dockerCompose.ServiceDeploy{}, + }, + equalableB: &dockerCompose.Service{ + Deploy: nil, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Environments: []string{"PROXY_HOST=localhost.localdomain"}, + }, + equalableB: &dockerCompose.Service{ + Environments: []string{"PROXY_HOST=localhost.localdomain"}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + Environments: []string{"PROXY_HOST=localhost.localdomain"}, + }, + equalableB: &dockerCompose.Service{ + Environments: []string{"PROXY_HOST=localhost"}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Environments: []string{"PROXY_HOST=localhost.localdomain"}, + }, + equalableB: &dockerCompose.Service{ + Environments: []string{"PROXY_HOST=localdomain.localhost"}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + ExtraHosts: []string{"my-app.u.orbis-healthcare.com"}, + }, + equalableB: &dockerCompose.Service{ + ExtraHosts: []string{"my-app.u.orbis-healthcare.com"}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + ExtraHosts: []string{"my-app.u.orbis-healthcare.com"}, + }, + equalableB: &dockerCompose.Service{ + ExtraHosts: []string{}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Image: "registry.example.local/my/app:latest", + }, + equalableB: &dockerCompose.Service{ + Image: "registry.example.local/my/app:latest", + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + Image: "registry.example.local/my/app:latest", + }, + equalableB: &dockerCompose.Service{ + Image: "", + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Labels: []string{"keyA=valueA"}, + }, + equalableB: &dockerCompose.Service{ + Labels: []string{"keyA=valueA"}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + Labels: []string{"keyA=valueA", "keyA=valueB"}, + }, + equalableB: &dockerCompose.Service{ + Labels: []string{"keyA=valueA"}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Networks: make(map[string]*dockerCompose.ServiceNetwork), + }, + equalableB: &dockerCompose.Service{ + Networks: nil, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + Networks: make(map[string]*dockerCompose.ServiceNetwork), + }, + equalableB: &dockerCompose.Service{ + Networks: make(map[string]*dockerCompose.ServiceNetwork), + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + Ports: []string{"80:80/tcp"}, + }, + equalableB: &dockerCompose.Service{ + Ports: []string{"80:80/tcp"}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + Ports: []string{"80:80/tcp"}, + }, + equalableB: &dockerCompose.Service{ + Ports: []string{"80:80/udp"}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Secrets: make([]string, 0), + }, + equalableB: &dockerCompose.Service{ + Secrets: make([]string, 0), + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + ULimits: dockerCompose.NewServiceULimits(), + }, + equalableB: &dockerCompose.Service{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + ULimits: dockerCompose.NewServiceULimits(), + }, + equalableB: &dockerCompose.Service{ + ULimits: dockerCompose.NewServiceULimits(), + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.Service{ + Volumes: []string{"/var/run/docker/volume/mountA"}, + }, + equalableB: &dockerCompose.Service{ + Volumes: []string{"/var/run/docker/volume/mountB"}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.Service{ + Volumes: []string{"/var/run/docker/volume/mountA"}, + }, + equalableB: &dockerCompose.Service{ + Volumes: []string{"/var/run/docker/volume/mountA"}, + }, + expectedResult: true, + }, + } + + for i, testCase := range testCases { + require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i) + } +} + func TestServiceDeployResourcesLimits_Equal(t *testing.T) { require := require.New(t)