test: TestServiceULimits_MergeLastWin

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

View File

@ -751,7 +751,7 @@ func (l *ServiceULimits) MergeLastWin(serviceULimits *ServiceULimits) {
// fallthrough
default:
l.mergeLastWinNProc(l.NProc)
l.mergeLastWinNProc(serviceULimits.NProc)
l.mergeLastWinNoFile(serviceULimits.NoFile)
}
}

View File

@ -822,6 +822,49 @@ func TestServiceULimits_Equal(t *testing.T) {
}
}
func TestServiceULimits_MergeLastWin(t *testing.T) {
require := require.New(t)
testCases := []struct {
ServiceULimitsA *dockerCompose.ServiceULimits
ServiceULimitsB *dockerCompose.ServiceULimits
expectedServiceULimits *dockerCompose.ServiceULimits
}{
{
ServiceULimitsA: &dockerCompose.ServiceULimits{},
ServiceULimitsB: nil,
expectedServiceULimits: &dockerCompose.ServiceULimits{},
},
{
ServiceULimitsA: &dockerCompose.ServiceULimits{
NProc: 10,
},
ServiceULimitsB: &dockerCompose.ServiceULimits{
NProc: 10,
},
expectedServiceULimits: &dockerCompose.ServiceULimits{
NProc: 10,
},
},
{
ServiceULimitsA: &dockerCompose.ServiceULimits{
NProc: 10,
},
ServiceULimitsB: &dockerCompose.ServiceULimits{
NProc: 20,
},
expectedServiceULimits: &dockerCompose.ServiceULimits{
NProc: 20,
},
},
}
for i, testCase := range testCases {
testCase.ServiceULimitsA.MergeLastWin(testCase.ServiceULimitsB)
require.Equal(testCase.expectedServiceULimits, testCase.ServiceULimitsA, "Failed test case %v", i)
}
}
func TestServiceULimitsNoFile_Equal(t *testing.T) {
require := require.New(t)