fix: TestServiceDeploy_MergeLastWin
This commit is contained in:
parent
7a65eb8099
commit
ff25c22051
@ -508,7 +508,14 @@ func (sd *ServiceDeploy) MergeLastWin(serviceDeploy *ServiceDeploy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sd *ServiceDeploy) mergeLastWinDeployResources(resources *ServiceDeployResources) {
|
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)
|
sd.Resources.MergeLastWin(resources)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
func TestSecretDeployResources_Equal(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user