Skip to content

Commit

Permalink
Update go test for TestConnectionLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvonthenen committed Aug 30, 2019
1 parent eb639aa commit 2585a90
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pkg/common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ datacenters = us-west
ca-file = /some/path/to/a/ca.pem
`

const twoVCsUsingSecretConfig = `
const multiVCDCsUsingSecretConfig = `
[Global]
port = 443
insecure-flag = true
Expand All @@ -51,6 +51,12 @@ datacenters = "vic1dc"
secret-name = "us-east-secret"
secret-namespace = "kube-system"
# port, insecure-flag will be used from Global section.
[VirtualCenter "10.0.0.3"]
datacenters = "vicdc"
secret-name = "eu-secret"
secret-namespace = "kube-system"
# port, insecure-flag will be used from Global section.
`

func TestReadConfigGlobal(t *testing.T) {
Expand Down Expand Up @@ -156,7 +162,7 @@ func TestIPFamilies(t *testing.T) {
}

func TestConnectionLabels(t *testing.T) {
cfg, err := ReadConfig(strings.NewReader(twoVCsUsingSecretConfig))
cfg, err := ReadConfig(strings.NewReader(multiVCDCsUsingSecretConfig))
if err != nil {
t.Fatalf("Should succeed when a valid config is provided: %s", err)
}
Expand Down Expand Up @@ -198,4 +204,21 @@ func TestConnectionLabels(t *testing.T) {
if !strings.EqualFold(vcConfig2.SecretRef, "kube-system/us-east-secret") {
t.Errorf("vcConfig2 SecretRef should be kube-system/us-east-secret but actual=%s", vcConfig2.SecretRef)
}

vcConfig3 := cfg.VirtualCenter["10.0.0.3"]
if vcConfig3 == nil {
t.Fatalf("Should return a valid vcConfig3")
}
if !vcConfig3.IsSecretInfoProvided() {
t.Error("vcConfig3.IsSecretInfoProvided() should be set.")
}
if !strings.EqualFold(vcConfig3.VCenterIP, "10.0.0.3") {
t.Errorf("vcConfig3 VCenterIP should be 10.0.0.3 but actual=%s", vcConfig3.VCenterIP)
}
if !strings.EqualFold(vcConfig3.ConnectionLabel, "10.0.0.3") {
t.Errorf("vcConfig3 ConnectionLabel should be eu-secret but actual=%s", vcConfig3.ConnectionLabel)
}
if !strings.EqualFold(vcConfig3.SecretRef, "kube-system/eu-secret") {
t.Errorf("vcConfig3 SecretRef should be kube-system/eu-secret but actual=%s", vcConfig3.SecretRef)
}
}

0 comments on commit 2585a90

Please sign in to comment.