test: TestServiceDeployResources_MergeLastWin
This commit is contained in:
parent
78f6a201e5
commit
7a65eb8099
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user