From a8984ead0eb3bbde7280d230b5e9edb73194e72b Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Mon, 24 Jul 2023 10:37:51 +0200 Subject: [PATCH] test: TestServiceNetwork_MergeLastWin --- pkg/domain/dockerCompose/config_test.go | 49 +++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/pkg/domain/dockerCompose/config_test.go b/pkg/domain/dockerCompose/config_test.go index 927fc70..e91117f 100644 --- a/pkg/domain/dockerCompose/config_test.go +++ b/pkg/domain/dockerCompose/config_test.go @@ -755,6 +755,49 @@ func TestServiceNetwork_Equal(t *testing.T) { } } +func TestServiceNetwork_MergeLastWin(t *testing.T) { + require := require.New(t) + + testCases := []struct { + ServiceNetworkA *dockerCompose.ServiceNetwork + ServiceNetworkB *dockerCompose.ServiceNetwork + expectedServiceNetwork *dockerCompose.ServiceNetwork + }{ + { + ServiceNetworkA: &dockerCompose.ServiceNetwork{}, + ServiceNetworkB: nil, + expectedServiceNetwork: &dockerCompose.ServiceNetwork{}, + }, + { + ServiceNetworkA: &dockerCompose.ServiceNetwork{ + Aliases: []string{"my-app.example.com"}, + }, + ServiceNetworkB: &dockerCompose.ServiceNetwork{ + Aliases: []string{"my-app.example.com"}, + }, + expectedServiceNetwork: &dockerCompose.ServiceNetwork{ + Aliases: []string{"my-app.example.com"}, + }, + }, + { + ServiceNetworkA: &dockerCompose.ServiceNetwork{ + Aliases: []string{"my-app.example.com"}, + }, + ServiceNetworkB: &dockerCompose.ServiceNetwork{ + Aliases: []string{"my-app.example.local"}, + }, + expectedServiceNetwork: &dockerCompose.ServiceNetwork{ + Aliases: []string{"my-app.example.com", "my-app.example.local"}, + }, + }, + } + + for i, testCase := range testCases { + testCase.ServiceNetworkA.MergeLastWin(testCase.ServiceNetworkB) + require.True(testCase.expectedServiceNetwork.Equal(testCase.ServiceNetworkA), "Failed test case %v", i) + } +} + func TestServiceULimits_Equal(t *testing.T) { require := require.New(t) @@ -861,7 +904,7 @@ func TestServiceULimits_MergeLastWin(t *testing.T) { for i, testCase := range testCases { testCase.ServiceULimitsA.MergeLastWin(testCase.ServiceULimitsB) - require.Equal(testCase.expectedServiceULimits, testCase.ServiceULimitsA, "Failed test case %v", i) + require.True(testCase.expectedServiceULimits.Equal(testCase.ServiceULimitsA), "Failed test case %v", i) } } @@ -988,7 +1031,7 @@ func TestServiceULimitsNoFile_MergeLastWin(t *testing.T) { for i, testCase := range testCases { testCase.ServiceULimitsNoFileA.MergeLastWin(testCase.ServiceULimitsNoFileB) - require.Equal(testCase.expectedServiceULimitsNoFile, testCase.ServiceULimitsNoFileA, "Failed test case %v", i) + require.True(testCase.expectedServiceULimitsNoFile.Equal(testCase.ServiceULimitsNoFileA), "Failed test case %v", i) } } @@ -1079,6 +1122,6 @@ func TestVolume_MergeLastWin(t *testing.T) { for i, testCase := range testCases { testCase.volumeA.MergeLastWin(testCase.volumeB) - require.Equal(testCase.expectedVolume, testCase.volumeA, "Failed test case %v", i) + require.True(testCase.expectedVolume.Equal(testCase.volumeA), "Failed test case %v", i) } }