test: TestServiceDeployResourceLimits_Equal

This commit is contained in:
Markus Pesch 2023-07-24 10:09:14 +02:00
parent c77f0ea1a3
commit c5898b1ce9
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 99 additions and 1 deletions

View File

@ -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)
}
}

View File

@ -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)