2021-07-03 09:36:55 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidConfig(t *testing.T) {
|
|
|
|
var testCase = struct {
|
|
|
|
name string
|
|
|
|
description string
|
|
|
|
file string
|
|
|
|
want Config
|
|
|
|
}{
|
|
|
|
name: "Test case: A valid Config",
|
|
|
|
description: "Testing the parsing of valid configuration.",
|
|
|
|
file: "./testdata/config-valid.json",
|
|
|
|
want: Config{
|
|
|
|
ProjectName: "forge-platform-test-config",
|
|
|
|
Docker: DockerConfig{
|
|
|
|
Network: DockerNetworkConfig{
|
|
|
|
Name: "forge-platform-test-netwwork",
|
|
|
|
Subnet: "172.17.1.0/24",
|
|
|
|
Driver: "default",
|
|
|
|
},
|
2021-07-11 13:32:01 +01:00
|
|
|
SharedVolume: DockerSharedVolumeConfig{
|
|
|
|
Name: "shared-volume",
|
|
|
|
},
|
2021-07-03 09:36:55 +01:00
|
|
|
},
|
2021-07-10 12:41:15 +01:00
|
|
|
Services: ServicesConfig{
|
|
|
|
Traefik: TraefikConfig{
|
|
|
|
CheckNewVersion: true,
|
|
|
|
SendAnonymousUsage: false,
|
|
|
|
Version: "v2.4.9",
|
|
|
|
ContainerIp: "172.17.1.2",
|
|
|
|
LogLevel: "info",
|
|
|
|
},
|
|
|
|
},
|
2021-07-03 09:36:55 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
testFunc := func(t *testing.T) {
|
|
|
|
t.Log(testCase.description)
|
|
|
|
got, err := NewConfig(testCase.file)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to create the configuration from file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(got, testCase.want) {
|
|
|
|
t.Errorf("Unexpected Config value created. Got %v, want %v", got, testCase.want)
|
|
|
|
} else {
|
|
|
|
t.Log("Test passed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(testCase.name, testFunc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidConfig(t *testing.T) {
|
|
|
|
var testCase = struct {
|
|
|
|
name string
|
|
|
|
description string
|
|
|
|
file string
|
|
|
|
}{
|
|
|
|
name: "Test case: An invalid Config",
|
|
|
|
description: "Testing the handling of invalid configuration.",
|
|
|
|
file: "./testdata/config-invalid.json",
|
|
|
|
}
|
|
|
|
|
|
|
|
testFunc := func(t *testing.T) {
|
|
|
|
t.Log(testCase.description)
|
|
|
|
_, err := NewConfig(testCase.file)
|
|
|
|
if err == nil {
|
|
|
|
t.Error("Expected an error with this invalid configuration.")
|
|
|
|
} else {
|
|
|
|
t.Log("Test passed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(testCase.name, testFunc)
|
|
|
|
}
|