2023-07-21 13:48:24 +00:00
|
|
|
package dockerCompose_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-07-24 07:04:52 +00:00
|
|
|
"git.cryptic.systems/volker.raschek/dcmerge/pkg/domain/dockerCompose"
|
2023-07-21 13:48:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-07-24 07:04:23 +00:00
|
|
|
func TestNetwork_Equal(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
equalableA dockerCompose.Equalable
|
|
|
|
equalableB dockerCompose.Equalable
|
|
|
|
expectedResult bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Network{
|
|
|
|
External: true,
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.NetworkIPAM{},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Network{
|
|
|
|
External: true,
|
|
|
|
},
|
|
|
|
equalableB: nil,
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Network{
|
|
|
|
External: false,
|
|
|
|
Driver: "bridge",
|
|
|
|
IPAM: nil,
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.Network{
|
|
|
|
External: false,
|
|
|
|
Driver: "bridge",
|
|
|
|
IPAM: nil,
|
|
|
|
},
|
|
|
|
expectedResult: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Network{
|
|
|
|
External: false,
|
|
|
|
Driver: "host",
|
|
|
|
IPAM: nil,
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.Network{
|
|
|
|
External: false,
|
|
|
|
Driver: "bride",
|
|
|
|
IPAM: nil,
|
|
|
|
},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Network{
|
|
|
|
External: true,
|
|
|
|
Driver: "bridge",
|
|
|
|
IPAM: nil,
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.Network{
|
|
|
|
External: false,
|
|
|
|
Driver: "bridge",
|
|
|
|
IPAM: nil,
|
|
|
|
},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-24 07:08:03 +00:00
|
|
|
func TestNetworkIPAM_Equal(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
equalableA dockerCompose.Equalable
|
|
|
|
equalableB dockerCompose.Equalable
|
|
|
|
expectedResult bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAM{},
|
|
|
|
equalableB: &dockerCompose.Service{},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAM{},
|
|
|
|
equalableB: nil,
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAM{
|
|
|
|
Configs: make([]*dockerCompose.NetworkIPAMConfig, 0),
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.NetworkIPAM{},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAM{
|
|
|
|
Configs: make([]*dockerCompose.NetworkIPAMConfig, 0),
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.NetworkIPAM{
|
|
|
|
Configs: make([]*dockerCompose.NetworkIPAMConfig, 0),
|
|
|
|
},
|
|
|
|
expectedResult: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-24 07:10:06 +00:00
|
|
|
func TestNetworkIPAM_Config(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
equalableA dockerCompose.Equalable
|
|
|
|
equalableB dockerCompose.Equalable
|
|
|
|
expectedResult bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAMConfig{},
|
|
|
|
equalableB: &dockerCompose.Service{},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAMConfig{},
|
|
|
|
equalableB: nil,
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAMConfig{
|
|
|
|
Subnet: "10.12.13.14/15",
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.NetworkIPAMConfig{},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.NetworkIPAMConfig{
|
|
|
|
Subnet: "10.12.13.14/15",
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.NetworkIPAMConfig{
|
|
|
|
Subnet: "10.12.13.14/15",
|
|
|
|
},
|
|
|
|
expectedResult: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-21 14:15:35 +00:00
|
|
|
func TestServiceDeployResourcesLimits_Equal(t *testing.T) {
|
2023-07-21 13:48:24 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
equalableA dockerCompose.Equalable
|
|
|
|
equalableB dockerCompose.Equalable
|
|
|
|
expectedResult bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.NetworkIPAM{},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
equalableB: nil,
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
expectedResult: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "2",
|
|
|
|
},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
Memory: "1000",
|
|
|
|
},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServiceDeployResourcesLimits_MergeLastWin(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
serviceDeploymentResourcesLimitsA *dockerCompose.ServiceDeployResourcesLimits
|
|
|
|
serviceDeploymentResourcesLimitsB *dockerCompose.ServiceDeployResourcesLimits
|
|
|
|
expectedResult *dockerCompose.ServiceDeployResourcesLimits
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
serviceDeploymentResourcesLimitsA: nil,
|
|
|
|
serviceDeploymentResourcesLimitsB: nil,
|
|
|
|
expectedResult: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
serviceDeploymentResourcesLimitsA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
serviceDeploymentResourcesLimitsB: nil,
|
|
|
|
expectedResult: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
serviceDeploymentResourcesLimitsA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
serviceDeploymentResourcesLimitsB: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
expectedResult: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
serviceDeploymentResourcesLimitsA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "1",
|
|
|
|
},
|
|
|
|
serviceDeploymentResourcesLimitsB: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "2",
|
|
|
|
},
|
|
|
|
expectedResult: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
CPUs: "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
serviceDeploymentResourcesLimitsA: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
Memory: "500",
|
|
|
|
},
|
|
|
|
serviceDeploymentResourcesLimitsB: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
Memory: "1000",
|
|
|
|
},
|
|
|
|
expectedResult: &dockerCompose.ServiceDeployResourcesLimits{
|
|
|
|
Memory: "1000",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
testCase.serviceDeploymentResourcesLimitsA.MergeLastWin(testCase.serviceDeploymentResourcesLimitsB)
|
|
|
|
require.True(testCase.expectedResult.Equal(testCase.serviceDeploymentResourcesLimitsA), "Failed test case %v", i)
|
|
|
|
}
|
|
|
|
}
|
2023-07-21 14:15:35 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2023-07-21 14:36:24 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2023-07-21 14:47:08 +00:00
|
|
|
|
|
|
|
func TestVolume_Equal(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
equalableA dockerCompose.Equalable
|
|
|
|
equalableB dockerCompose.Equalable
|
|
|
|
expectedResult bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Volume{},
|
|
|
|
equalableB: &dockerCompose.NetworkIPAM{},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Volume{},
|
|
|
|
equalableB: nil,
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: dockerCompose.NewVolume(),
|
|
|
|
equalableB: dockerCompose.NewVolume(),
|
|
|
|
expectedResult: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Volume{
|
|
|
|
External: true,
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.Volume{
|
|
|
|
External: false,
|
|
|
|
},
|
|
|
|
expectedResult: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
equalableA: &dockerCompose.Volume{
|
|
|
|
External: true,
|
|
|
|
},
|
|
|
|
equalableB: &dockerCompose.Volume{
|
|
|
|
External: true,
|
|
|
|
},
|
|
|
|
expectedResult: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
require.Equal(testCase.expectedResult, testCase.equalableA.Equal(testCase.equalableB), "Failed test case %v", i)
|
|
|
|
}
|
|
|
|
}
|