From 70f33eb0df42c3473d629c31b421dcc8f296ce5a Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Fri, 21 Jul 2023 16:36:24 +0200 Subject: [PATCH] test: serviceULimitsNoFile --- pki/domain/dockerCompose/config_test.go | 117 ++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/pki/domain/dockerCompose/config_test.go b/pki/domain/dockerCompose/config_test.go index 2398a2a..3a01a2e 100644 --- a/pki/domain/dockerCompose/config_test.go +++ b/pki/domain/dockerCompose/config_test.go @@ -199,3 +199,120 @@ func TestServiceNetwork_Equal(t *testing.T) { require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i) } } + +func TestServiceULimits_Equal(t *testing.T) { + require := require.New(t) + + testCases := []struct { + equalableA dockerCompose.Equalable + equalableB dockerCompose.Equalable + expectedResult bool + }{ + { + equalableA: &dockerCompose.ServiceULimits{}, + equalableB: &dockerCompose.NetworkIPAM{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceULimits{}, + equalableB: nil, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceULimits{ + NProc: 0, + NoFile: dockerCompose.NewServiceULimitsNoFile(), + }, + equalableB: &dockerCompose.ServiceULimits{ + NProc: 0, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceULimits{ + NProc: 0, + NoFile: &dockerCompose.ServiceULimitsNoFile{ + Hard: 10, + }, + }, + equalableB: &dockerCompose.ServiceULimits{ + NProc: 0, + NoFile: &dockerCompose.ServiceULimitsNoFile{ + Soft: 10, + }, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceULimits{ + NProc: 20, + NoFile: &dockerCompose.ServiceULimitsNoFile{ + Hard: 10, + Soft: 10, + }, + }, + equalableB: &dockerCompose.ServiceULimits{ + NProc: 20, + NoFile: &dockerCompose.ServiceULimitsNoFile{ + Hard: 10, + Soft: 10, + }, + }, + expectedResult: true, + }, + } + + for i, testCase := range testCases { + require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i) + } +} + +func TestServiceULimitsNoFile_Equal(t *testing.T) { + require := require.New(t) + + testCases := []struct { + equalableA dockerCompose.Equalable + equalableB dockerCompose.Equalable + expectedResult bool + }{ + { + equalableA: &dockerCompose.ServiceULimitsNoFile{}, + equalableB: &dockerCompose.NetworkIPAM{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceULimitsNoFile{}, + equalableB: nil, + expectedResult: false, + }, + { + equalableA: dockerCompose.NewServiceULimitsNoFile(), + equalableB: dockerCompose.NewServiceULimitsNoFile(), + expectedResult: true, + }, + { + equalableA: &dockerCompose.ServiceULimitsNoFile{ + Hard: 10, + }, + equalableB: &dockerCompose.ServiceULimitsNoFile{ + Soft: 10, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceULimitsNoFile{ + Hard: 10, + Soft: 10, + }, + equalableB: &dockerCompose.ServiceULimitsNoFile{ + Hard: 10, + Soft: 10, + }, + expectedResult: true, + }, + } + + for i, testCase := range testCases { + require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i) + } +}