diff --git a/pkg/domain/dockerCompose/config.go b/pkg/domain/dockerCompose/config.go index 05dcffb..63e8cd0 100644 --- a/pkg/domain/dockerCompose/config.go +++ b/pkg/domain/dockerCompose/config.go @@ -540,7 +540,7 @@ func (sdr *ServiceDeployResources) Equal(equalable Equalable) bool { return false default: return sdr.Limits.Equal(serviceDeployResources.Limits) && - sdr.Reservations.Equal(serviceDeployResources) + sdr.Reservations.Equal(serviceDeployResources.Reservations) } } diff --git a/pki/domain/dockerCompose/config_test.go b/pki/domain/dockerCompose/config_test.go index 9a3f645..10c4d44 100644 --- a/pki/domain/dockerCompose/config_test.go +++ b/pki/domain/dockerCompose/config_test.go @@ -464,6 +464,104 @@ func TestService_Equal(t *testing.T) { } } +func TestSecretDeploy_Equal(t *testing.T) { + require := require.New(t) + + testCases := []struct { + equalableA dockerCompose.Equalable + equalableB dockerCompose.Equalable + expectedResult bool + }{ + { + equalableA: &dockerCompose.ServiceDeploy{}, + equalableB: &dockerCompose.Service{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceDeploy{}, + equalableB: nil, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceDeploy{ + Resources: dockerCompose.NewServiceDeployResources(), + }, + equalableB: &dockerCompose.ServiceDeploy{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceDeploy{ + Resources: dockerCompose.NewServiceDeployResources(), + }, + equalableB: &dockerCompose.ServiceDeploy{ + Resources: dockerCompose.NewServiceDeployResources(), + }, + expectedResult: false, + }, + } + + for i, testCase := range testCases { + require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i) + } +} + +func TestSecretDeployResources_Equal(t *testing.T) { + require := require.New(t) + + testCases := []struct { + equalableA dockerCompose.Equalable + equalableB dockerCompose.Equalable + expectedResult bool + }{ + { + equalableA: &dockerCompose.ServiceDeployResources{}, + equalableB: &dockerCompose.Service{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceDeployResources{}, + equalableB: nil, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceDeployResources{ + Limits: dockerCompose.NewServiceDeployResourcesLimits(), + }, + equalableB: &dockerCompose.ServiceDeployResources{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceDeployResources{ + Limits: dockerCompose.NewServiceDeployResourcesLimits(), + }, + equalableB: &dockerCompose.ServiceDeployResources{ + Limits: dockerCompose.NewServiceDeployResourcesLimits(), + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.ServiceDeployResources{ + Reservations: dockerCompose.NewServiceDeployResourcesLimits(), + }, + equalableB: &dockerCompose.ServiceDeployResources{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceDeployResources{ + Reservations: dockerCompose.NewServiceDeployResourcesLimits(), + }, + equalableB: &dockerCompose.ServiceDeployResources{ + Reservations: dockerCompose.NewServiceDeployResourcesLimits(), + }, + 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)