fix: TestServiceDeploy_MergeLastWin

This commit is contained in:
Markus Pesch 2023-07-24 11:25:11 +02:00
parent 7a65eb8099
commit ff25c22051
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 70 additions and 1 deletions

View File

@ -508,7 +508,14 @@ func (sd *ServiceDeploy) MergeLastWin(serviceDeploy *ServiceDeploy) {
}
func (sd *ServiceDeploy) mergeLastWinDeployResources(resources *ServiceDeployResources) {
if !sd.Resources.Equal(resources) {
switch {
case sd.Resources == nil && resources != nil:
sd.Resources = resources
case sd.Resources != nil && resources == nil:
fallthrough
case sd.Resources == nil && resources == nil:
return
default:
sd.Resources.MergeLastWin(resources)
}
}

View File

@ -505,6 +505,68 @@ func TestSecretDeploy_Equal(t *testing.T) {
}
}
func TestServiceDeploy_MergeLastWin(t *testing.T) {
require := require.New(t)
testCases := []struct {
serviceDeploymentA *dockerCompose.ServiceDeploy
serviceDeploymentB *dockerCompose.ServiceDeploy
expectedServiceDeployment *dockerCompose.ServiceDeploy
}{
{
serviceDeploymentA: nil,
serviceDeploymentB: nil,
expectedServiceDeployment: nil,
},
{
serviceDeploymentA: &dockerCompose.ServiceDeploy{
Resources: nil,
},
serviceDeploymentB: &dockerCompose.ServiceDeploy{
Resources: nil,
},
expectedServiceDeployment: &dockerCompose.ServiceDeploy{
Resources: nil,
},
},
{
serviceDeploymentA: &dockerCompose.ServiceDeploy{
Resources: &dockerCompose.ServiceDeployResources{
Limits: nil,
},
},
serviceDeploymentB: &dockerCompose.ServiceDeploy{
Resources: nil,
},
expectedServiceDeployment: &dockerCompose.ServiceDeploy{
Resources: &dockerCompose.ServiceDeployResources{
Limits: nil,
},
},
},
{
serviceDeploymentA: &dockerCompose.ServiceDeploy{
Resources: nil,
},
serviceDeploymentB: &dockerCompose.ServiceDeploy{
Resources: &dockerCompose.ServiceDeployResources{
Limits: nil,
},
},
expectedServiceDeployment: &dockerCompose.ServiceDeploy{
Resources: &dockerCompose.ServiceDeployResources{
Limits: nil,
},
},
},
}
for i, testCase := range testCases {
testCase.serviceDeploymentA.MergeLastWin(testCase.serviceDeploymentB)
require.True(testCase.expectedServiceDeployment.Equal(testCase.serviceDeploymentA), "Failed test case %v", i)
}
}
func TestSecretDeployResources_Equal(t *testing.T) {
require := require.New(t)