1
1
/*
2
2
Copyright 2019 The Kubernetes Authors.
3
-
4
3
Licensed under the Apache License, Version 2.0 (the "License");
5
4
you may not use this file except in compliance with the License.
6
5
You may obtain a copy of the License at
7
-
8
6
http://www.apache.org/licenses/LICENSE-2.0
9
-
10
7
Unless required by applicable law or agreed to in writing, software
11
8
distributed under the License is distributed on an "AS IS" BASIS,
12
9
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,48 +14,76 @@ limitations under the License.
17
14
package vsphere
18
15
19
16
import (
20
- "os"
21
17
"strings"
22
18
"testing"
23
19
)
24
20
25
- const basicConfig = `
21
+ const subnetCidrConfig = `
22
+ [Global]
23
+ server = 0.0.0.0
24
+ port = 443
25
+ user = user
26
+ password = password
27
+ insecure-flag = true
28
+ datacenters = us-west
29
+ ca-file = /some/path/to/a/ca.pem
30
+
31
+ [Nodes]
32
+ internal-network-subnet-cidr = "192.0.2.0/24"
33
+ external-network-subnet-cidr = "198.51.100.0/24"
34
+ `
35
+
36
+ const networkNameConfig = `
37
+ [Global]
38
+ server = 0.0.0.0
39
+ port = 443
40
+ user = user
41
+ password = password
42
+ insecure-flag = true
43
+ datacenters = us-west
44
+ ca-file = /some/path/to/a/ca.pem
45
+
26
46
[Nodes]
27
- internal-network-subnet-cidr = 192.0.2.0/24
28
- external-network-subnet-cidr = 198.51.100.0/24
47
+ internal-vm- network-name = "Internal K8s Traffic"
48
+ external-vm- network-name = "External/Outbound Traffic"
29
49
`
30
50
31
- func TestReadConfigGlobal (t * testing.T ) {
51
+ func TestReadConfigSubnetCidr (t * testing.T ) {
32
52
_ , err := ReadCPIConfig (nil )
33
53
if err == nil {
34
54
t .Errorf ("Should fail when no config is provided: %s" , err )
35
55
}
36
56
37
- cfg , err := ReadCPIConfig (strings .NewReader (basicConfig ))
57
+ cfg , err := ReadCPIConfig (strings .NewReader (subnetCidrConfig ))
38
58
if err != nil {
39
59
t .Fatalf ("Should succeed when a valid config is provided: %s" , err )
40
60
}
41
61
42
62
if cfg .Nodes .InternalNetworkSubnetCIDR != "192.0.2.0/24" {
43
- t .Errorf ("incorrect vcenter ip : %s" , cfg .Nodes .InternalNetworkSubnetCIDR )
63
+ t .Errorf ("incorrect internal network subnet cidr : %s" , cfg .Nodes .InternalNetworkSubnetCIDR )
44
64
}
45
65
46
66
if cfg .Nodes .ExternalNetworkSubnetCIDR != "198.51.100.0/24" {
47
- t .Errorf ("incorrect datacenter : %s" , cfg .Nodes .ExternalNetworkSubnetCIDR )
67
+ t .Errorf ("incorrect external network subnet cidr : %s" , cfg .Nodes .ExternalNetworkSubnetCIDR )
48
68
}
49
69
}
50
70
51
- func TestEnvOverridesFile (t * testing.T ) {
52
- subnet := "203.0.113.0/24"
53
- os .Setenv ("VSPHERE_NODES_INTERNAL_NETWORK_SUBNET_CIDR" , subnet )
54
- defer os .Unsetenv ("VSPHERE_NODES_INTERNAL_NETWORK_SUBNET_CIDR" )
71
+ func TestReadConfigNetworkName (t * testing.T ) {
72
+ _ , err := ReadCPIConfig (nil )
73
+ if err == nil {
74
+ t .Errorf ("Should fail when no config is provided: %s" , err )
75
+ }
55
76
56
- cfg , err := ReadCPIConfig (strings .NewReader (basicConfig ))
77
+ cfg , err := ReadCPIConfig (strings .NewReader (networkNameConfig ))
57
78
if err != nil {
58
79
t .Fatalf ("Should succeed when a valid config is provided: %s" , err )
59
80
}
60
81
61
- if cfg .Nodes .InternalNetworkSubnetCIDR != subnet {
62
- t .Errorf ("expected subnet: \" %s\" , got: \" %s\" " , subnet , cfg .Nodes .InternalNetworkSubnetCIDR )
82
+ if cfg .Nodes .InternalVMNetworkName != "Internal K8s Traffic" {
83
+ t .Errorf ("incorrect internal vm network name: %s" , cfg .Nodes .InternalVMNetworkName )
84
+ }
85
+
86
+ if cfg .Nodes .ExternalVMNetworkName != "External/Outbound Traffic" {
87
+ t .Errorf ("incorrect internal vm network name: %s" , cfg .Nodes .ExternalVMNetworkName )
63
88
}
64
89
}
0 commit comments