202 lines
4.9 KiB
Go
202 lines
4.9 KiB
Go
package dockerCompose_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.cryptic.systems/volker.raschek/dcmerge/pki/domain/dockerCompose"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestServiceDeployResourcesLimits_Equal(t *testing.T) {
|
|
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)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|