fix(dockerCompose): protect of empty attributes

This commit is contained in:
2023-08-28 11:37:24 +02:00
parent 9b469bd8c6
commit 751bb810d2
2 changed files with 141 additions and 0 deletions

View File

@ -1418,6 +1418,17 @@ func TestService_MergeLastWin(t *testing.T) {
CapabilitiesAdd: []string{"NET_RAW"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
CapabilitiesAdd: []string{"NET_RAW"},
},
serviceDeploymentB: &dockerCompose.Service{
CapabilitiesAdd: []string{""},
},
expectedService: &dockerCompose.Service{
CapabilitiesAdd: []string{"NET_RAW"},
},
},
// CapabilitiesDrop
{
@ -1453,6 +1464,17 @@ func TestService_MergeLastWin(t *testing.T) {
CapabilitiesDrop: []string{"NET_RAW"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
CapabilitiesDrop: []string{"NET_RAW"},
},
serviceDeploymentB: &dockerCompose.Service{
CapabilitiesDrop: []string{""},
},
expectedService: &dockerCompose.Service{
CapabilitiesDrop: []string{"NET_RAW"},
},
},
// Deploy
{
@ -1567,6 +1589,17 @@ func TestService_MergeLastWin(t *testing.T) {
Environments: []string{"PROXY_HOST=u.example.local"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
Environments: []string{"PROXY_HOST=u.example.com"},
},
serviceDeploymentB: &dockerCompose.Service{
Environments: []string{""},
},
expectedService: &dockerCompose.Service{
Environments: []string{"PROXY_HOST=u.example.com"},
},
},
// ExtraHosts
{
@ -1635,6 +1668,17 @@ func TestService_MergeLastWin(t *testing.T) {
ExtraHosts: []string{"extra.host.com", "extra.host.local"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
ExtraHosts: []string{"extra.host.local"},
},
serviceDeploymentB: &dockerCompose.Service{
ExtraHosts: []string{""},
},
expectedService: &dockerCompose.Service{
ExtraHosts: []string{"extra.host.local"},
},
},
// Image
{
@ -1738,6 +1782,17 @@ func TestService_MergeLastWin(t *testing.T) {
Labels: []string{"prometheus.io/scrape=true"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
Labels: []string{"prometheus.io/scrape=true"},
},
serviceDeploymentB: &dockerCompose.Service{
Labels: []string{""},
},
expectedService: &dockerCompose.Service{
Labels: []string{"prometheus.io/scrape=true"},
},
},
// Networks
{
@ -1817,6 +1872,23 @@ func TestService_MergeLastWin(t *testing.T) {
},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
Networks: map[string]*dockerCompose.ServiceNetwork{
"proxy": {Aliases: []string{"app.proxy.network"}},
},
},
serviceDeploymentB: &dockerCompose.Service{
Networks: map[string]*dockerCompose.ServiceNetwork{
"proxy": {Aliases: []string{""}},
},
},
expectedService: &dockerCompose.Service{
Networks: map[string]*dockerCompose.ServiceNetwork{
"proxy": {Aliases: []string{"app.proxy.network"}},
},
},
},
// Ports
{
@ -1907,6 +1979,17 @@ func TestService_MergeLastWin(t *testing.T) {
Ports: []string{"10080:80/udp"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
Ports: []string{"80:80"},
},
serviceDeploymentB: &dockerCompose.Service{
Ports: []string{""},
},
expectedService: &dockerCompose.Service{
Ports: []string{"80:80"},
},
},
// Secrets
{
@ -1975,6 +2058,17 @@ func TestService_MergeLastWin(t *testing.T) {
Secrets: []string{"db_pass_credentials", "oauth2_pass_credentials"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
Secrets: []string{"db_pass_credentials"},
},
serviceDeploymentB: &dockerCompose.Service{
Secrets: []string{""},
},
expectedService: &dockerCompose.Service{
Secrets: []string{"db_pass_credentials"},
},
},
// ULimits
{
@ -2147,6 +2241,17 @@ func TestService_MergeLastWin(t *testing.T) {
Volumes: []string{"/usr/share/zoneinfo/Europe/Berlin:/etc/localtime"},
},
},
{
serviceDeploymentA: &dockerCompose.Service{
Volumes: []string{"/etc/localtime:/etc/localtime"},
},
serviceDeploymentB: &dockerCompose.Service{
Volumes: []string{""},
},
expectedService: &dockerCompose.Service{
Volumes: []string{"/etc/localtime:/etc/localtime"},
},
},
}
for i, testCase := range testCases {