From c5898b1ce92e8e6f7cb01daf7b5cba717691765c Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Mon, 24 Jul 2023 10:09:14 +0200 Subject: [PATCH] test: TestServiceDeployResourceLimits_Equal --- pkg/domain/dockerCompose/config.go | 2 +- pki/domain/dockerCompose/config_test.go | 98 +++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) 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)