test: TestServiceDeployResources_MergeLastWin

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

View File

@ -579,7 +579,14 @@ func (sdr *ServiceDeployResources) mergeLastWinLimits(limits *ServiceDeployResou
}
func (sdr *ServiceDeployResources) mergeLastWinReservations(reservations *ServiceDeployResourcesLimits) {
if !sdr.Reservations.Equal(reservations) {
switch {
case sdr.Reservations == nil && reservations != nil:
sdr.Reservations = reservations
case sdr.Reservations != nil && reservations == nil:
fallthrough
case sdr.Reservations == nil && reservations == nil:
return
default:
sdr.Reservations.MergeLastWin(reservations)
}
}

View File

@ -629,6 +629,60 @@ func TestServiceDeployResources_MergeLastWin(t *testing.T) {
},
},
},
{
serviceDeploymentResourcesA: &dockerCompose.ServiceDeployResources{
Reservations: nil,
},
serviceDeploymentResourcesB: &dockerCompose.ServiceDeployResources{
Reservations: &dockerCompose.ServiceDeployResourcesLimits{
CPUs: "1",
Memory: "500",
},
},
expectedServiceDeploymentResources: &dockerCompose.ServiceDeployResources{
Reservations: &dockerCompose.ServiceDeployResourcesLimits{
CPUs: "1",
Memory: "500",
},
},
},
{
serviceDeploymentResourcesA: &dockerCompose.ServiceDeployResources{
Reservations: &dockerCompose.ServiceDeployResourcesLimits{
CPUs: "1",
Memory: "500",
},
},
serviceDeploymentResourcesB: &dockerCompose.ServiceDeployResources{
Reservations: nil,
},
expectedServiceDeploymentResources: &dockerCompose.ServiceDeployResources{
Reservations: &dockerCompose.ServiceDeployResourcesLimits{
CPUs: "1",
Memory: "500",
},
},
},
{
serviceDeploymentResourcesA: &dockerCompose.ServiceDeployResources{
Reservations: &dockerCompose.ServiceDeployResourcesLimits{
CPUs: "1",
Memory: "500",
},
},
serviceDeploymentResourcesB: &dockerCompose.ServiceDeployResources{
Reservations: &dockerCompose.ServiceDeployResourcesLimits{
CPUs: "2",
Memory: "1000",
},
},
expectedServiceDeploymentResources: &dockerCompose.ServiceDeployResources{
Reservations: &dockerCompose.ServiceDeployResourcesLimits{
CPUs: "2",
Memory: "1000",
},
},
},
}
for i, testCase := range testCases {