fix(dockerCompose): add ServiceNetwork.MergeFirstWin()

This commit is contained in:
2023-08-27 19:12:00 +02:00
parent 462299d5cd
commit 405a0258f1
2 changed files with 91 additions and 1 deletions

View File

@ -1736,6 +1736,65 @@ func TestServiceNetwork_Equal(t *testing.T) {
}
}
func TestServiceNetwork_MergeFirstWin(t *testing.T) {
require := require.New(t)
testCases := []struct {
ServiceNetworkA *dockerCompose.ServiceNetwork
ServiceNetworkB *dockerCompose.ServiceNetwork
expectedServiceNetwork *dockerCompose.ServiceNetwork
}{
{
ServiceNetworkA: nil,
ServiceNetworkB: nil,
expectedServiceNetwork: nil,
},
{
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"},
},
},
{
ServiceNetworkA: &dockerCompose.ServiceNetwork{
Aliases: []string{"my-app.example.com"},
},
ServiceNetworkB: &dockerCompose.ServiceNetwork{
Aliases: []string{""},
},
expectedServiceNetwork: &dockerCompose.ServiceNetwork{
Aliases: []string{"my-app.example.com"},
},
},
}
for i, testCase := range testCases {
testCase.ServiceNetworkA.MergeFirstWin(testCase.ServiceNetworkB)
require.True(testCase.expectedServiceNetwork.Equal(testCase.ServiceNetworkA), "Failed test case %v", i)
}
}
func TestServiceNetwork_MergeLastWin(t *testing.T) {
require := require.New(t)