From f6b1891d98f133ba788b8d637fca0776be1e0551 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Fri, 21 Jul 2023 16:15:35 +0200 Subject: [PATCH] test: network equal --- pki/domain/dockerCompose/config_test.go | 67 ++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/pki/domain/dockerCompose/config_test.go b/pki/domain/dockerCompose/config_test.go index 976863b..2398a2a 100644 --- a/pki/domain/dockerCompose/config_test.go +++ b/pki/domain/dockerCompose/config_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestServiceDeployResourcesLimits_EqualAndMergeLastWin(t *testing.T) { +func TestServiceDeployResourcesLimits_Equal(t *testing.T) { require := require.New(t) testCases := []struct { @@ -134,3 +134,68 @@ func TestServiceDeployResourcesLimits_MergeLastWin(t *testing.T) { require.True(testCase.expectedResult.Equal(testCase.serviceDeploymentResourcesLimitsA), "Failed test case %v", i) } } + +func TestServiceNetwork_Equal(t *testing.T) { + require := require.New(t) + + testCases := []struct { + equalableA dockerCompose.Equalable + equalableB dockerCompose.Equalable + expectedResult bool + }{ + { + equalableA: &dockerCompose.ServiceNetwork{ + Aliases: []string{}, + }, + equalableB: &dockerCompose.NetworkIPAM{}, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceNetwork{ + Aliases: []string{}, + }, + equalableB: nil, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceNetwork{ + Aliases: []string{}, + }, + equalableB: &dockerCompose.ServiceNetwork{ + Aliases: []string{}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.ServiceNetwork{ + Aliases: []string{"HelloWorld"}, + }, + equalableB: &dockerCompose.ServiceNetwork{ + Aliases: []string{"HelloWorld"}, + }, + expectedResult: true, + }, + { + equalableA: &dockerCompose.ServiceNetwork{ + Aliases: []string{"HelloWorld"}, + }, + equalableB: &dockerCompose.ServiceNetwork{ + Aliases: []string{"FooBar"}, + }, + expectedResult: false, + }, + { + equalableA: &dockerCompose.ServiceNetwork{ + Aliases: []string{"Hello", "World"}, + }, + equalableB: &dockerCompose.ServiceNetwork{ + Aliases: []string{"FooBar"}, + }, + expectedResult: false, + }, + } + + for i, testCase := range testCases { + require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i) + } +}