mirror of
https://github.com/rancher/rke.git
synced 2025-09-07 09:50:13 +00:00
more unit tests
This commit is contained in:
43
addons/addons_test.go
Normal file
43
addons/addons_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package addons
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/batch/v1"
|
||||
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
|
||||
)
|
||||
|
||||
const (
|
||||
AddonSuffix = "-deploy-job"
|
||||
FakeAddonName = "example-addon"
|
||||
FakeNodeName = "node1"
|
||||
FakeAddonImage = "example/example:latest"
|
||||
)
|
||||
|
||||
func TestJobManifest(t *testing.T) {
|
||||
jobYaml := GetAddonsExcuteJob(FakeAddonName, FakeNodeName, FakeAddonImage)
|
||||
job := v1.Job{}
|
||||
decoder := yamlutil.NewYAMLToJSONDecoder(bytes.NewReader([]byte(jobYaml)))
|
||||
err := decoder.Decode(&job)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed To decode Job yaml: %v", err)
|
||||
}
|
||||
assertEqual(t, job.Name, FakeAddonName+AddonSuffix,
|
||||
fmt.Sprintf("Failed to verify job name [%s]", FakeAddonName+AddonSuffix))
|
||||
assertEqual(t, job.Spec.Template.Spec.NodeName, FakeNodeName,
|
||||
fmt.Sprintf("Failed to verify node name [%s] in the job", FakeNodeName))
|
||||
assertEqual(t, job.Spec.Template.Spec.Containers[0].Image, FakeAddonImage,
|
||||
fmt.Sprintf("Failed to verify container image [%s] in the job", FakeAddonImage))
|
||||
}
|
||||
|
||||
func assertEqual(t *testing.T, a interface{}, b interface{}, message string) {
|
||||
if a == b {
|
||||
return
|
||||
}
|
||||
if len(message) == 0 {
|
||||
message = fmt.Sprintf("%v != %v", a, b)
|
||||
}
|
||||
t.Fatal(message)
|
||||
}
|
@@ -63,7 +63,7 @@ func TestPKI(t *testing.T) {
|
||||
for _, testDNS := range kubeAPIDNSNames {
|
||||
assertEqual(
|
||||
t,
|
||||
stringInSlice(
|
||||
isStringInSlice(
|
||||
testDNS,
|
||||
certificateMap[KubeAPICertName].Certificate.DNSNames),
|
||||
true,
|
||||
@@ -92,7 +92,7 @@ func TestPKI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func stringInSlice(a string, list []string) bool {
|
||||
func isStringInSlice(a string, list []string) bool {
|
||||
for _, b := range list {
|
||||
if b == a {
|
||||
return true
|
||||
|
59
services/etcd_test.go
Normal file
59
services/etcd_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rancher/rke/hosts"
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
TestInitEtcdClusterString = "etcd-etcd1=http://1.1.1.1:2380,etcd-etcd2=http://2.2.2.2:2380"
|
||||
TestEtcdImage = "etcd/etcdImage:latest"
|
||||
TestEtcdNamePrefix = "--name=etcd-"
|
||||
TestEtcdVolumeBind = "/var/lib/etcd:/etcd-data"
|
||||
TestEtcdExtraArgs = "--foo=bar"
|
||||
)
|
||||
|
||||
func TestEtcdConfig(t *testing.T) {
|
||||
etcdHosts := []*hosts.Host{
|
||||
&hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "1.1.1.1",
|
||||
InternalAddress: "1.1.1.1",
|
||||
Role: []string{"etcd"},
|
||||
HostnameOverride: "etcd1",
|
||||
},
|
||||
DClient: nil,
|
||||
},
|
||||
&hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "2.2.2.2",
|
||||
InternalAddress: "2.2.2.2",
|
||||
Role: []string{"etcd"},
|
||||
HostnameOverride: "etcd2",
|
||||
},
|
||||
DClient: nil,
|
||||
},
|
||||
}
|
||||
|
||||
etcdService := v3.ETCDService{}
|
||||
etcdService.Image = TestEtcdImage
|
||||
etcdService.ExtraArgs = map[string]string{"foo": "bar"}
|
||||
// Test init cluster string
|
||||
initCluster := getEtcdInitialCluster(etcdHosts)
|
||||
assertEqual(t, initCluster, TestInitEtcdClusterString, "")
|
||||
|
||||
for _, host := range etcdHosts {
|
||||
imageCfg, hostCfg := buildEtcdConfig(host, etcdService, TestInitEtcdClusterString)
|
||||
assertEqual(t, isStringInSlice(TestEtcdNamePrefix+host.HostnameOverride, imageCfg.Cmd), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Etcd command", TestEtcdNamePrefix+host.HostnameOverride))
|
||||
assertEqual(t, TestEtcdImage, imageCfg.Image,
|
||||
fmt.Sprintf("Failed to verify [%s] as Etcd Image", TestEtcdImage))
|
||||
assertEqual(t, isStringInSlice(TestEtcdVolumeBind, hostCfg.Binds), true,
|
||||
fmt.Sprintf("Failed to find [%s] in volume binds of Etcd Service", TestEtcdVolumeBind))
|
||||
assertEqual(t, isStringInSlice(TestEtcdExtraArgs, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in extra args of Etcd Service", TestEtcdExtraArgs))
|
||||
}
|
||||
}
|
69
services/kubeapi_test.go
Normal file
69
services/kubeapi_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rancher/rke/hosts"
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
TestEtcdConnString = "http://1.1.1.1:2379,http://2.2.2.2:2379"
|
||||
TestKubeAPIImage = "rancher/k8s:latest"
|
||||
TestInsecureBindAddress = "--insecure-bind-address=127.0.0.1"
|
||||
TestKubeAPIVolumeBind = "/etc/kubernetes:/etc/kubernetes"
|
||||
TestKubeAPIExtraArgs = "--foo=bar"
|
||||
)
|
||||
|
||||
func TestKubeAPIConfig(t *testing.T) {
|
||||
etcdHosts := []*hosts.Host{
|
||||
&hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "1.1.1.1",
|
||||
InternalAddress: "1.1.1.1",
|
||||
Role: []string{"etcd"},
|
||||
HostnameOverride: "etcd1",
|
||||
},
|
||||
DClient: nil,
|
||||
},
|
||||
&hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "2.2.2.2",
|
||||
InternalAddress: "2.2.2.2",
|
||||
Role: []string{"etcd"},
|
||||
HostnameOverride: "etcd2",
|
||||
},
|
||||
DClient: nil,
|
||||
},
|
||||
}
|
||||
|
||||
cpHost := &hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "3.3.3.3",
|
||||
InternalAddress: "3.3.3.3",
|
||||
Role: []string{"controlplane"},
|
||||
HostnameOverride: "node1",
|
||||
},
|
||||
DClient: nil,
|
||||
}
|
||||
|
||||
kubeAPIService := v3.KubeAPIService{}
|
||||
kubeAPIService.Image = TestKubeAPIImage
|
||||
kubeAPIService.ServiceClusterIPRange = "10.0.0.0/16"
|
||||
kubeAPIService.ExtraArgs = map[string]string{"foo": "bar"}
|
||||
// Test init cluster string
|
||||
etcdConnString := GetEtcdConnString(etcdHosts)
|
||||
assertEqual(t, etcdConnString, TestEtcdConnString, "")
|
||||
|
||||
imageCfg, hostCfg := buildKubeAPIConfig(cpHost, kubeAPIService, etcdConnString)
|
||||
// Test image and host config
|
||||
assertEqual(t, isStringInSlice(TestInsecureBindAddress, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Entrypoint of KubeAPI", TestInsecureBindAddress))
|
||||
assertEqual(t, TestKubeAPIImage, imageCfg.Image,
|
||||
fmt.Sprintf("Failed to find correct image [%s] in KubeAPI Config", TestKubeAPIImage))
|
||||
assertEqual(t, isStringInSlice(TestKubeAPIVolumeBind, hostCfg.Binds), true,
|
||||
fmt.Sprintf("Failed to find [%s] in volume binds of KubeAPI", TestKubeAPIVolumeBind))
|
||||
assertEqual(t, isStringInSlice(TestKubeAPIExtraArgs, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in extra args of KubeAPI", TestKubeAPIExtraArgs))
|
||||
}
|
41
services/kubecontroller_test.go
Normal file
41
services/kubecontroller_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
TestKubeControllerClusterCidr = "10.0.0.0/16"
|
||||
TestKubeControllerServiceClusterIPRange = "10.1.0.0/16"
|
||||
TestKubeControllerImage = "rancher/k8s:latest"
|
||||
TestKubeControllerVolumeBind = "/etc/kubernetes:/etc/kubernetes"
|
||||
TestKubeControllerExtraArgs = "--foo=bar"
|
||||
TestClusterCidrPrefix = "--cluster-cidr="
|
||||
TestServiceIPRangePrefix = "--service-cluster-ip-range="
|
||||
)
|
||||
|
||||
func TestKubeControllerConfig(t *testing.T) {
|
||||
|
||||
kubeControllerService := v3.KubeControllerService{}
|
||||
kubeControllerService.Image = TestKubeControllerImage
|
||||
kubeControllerService.ClusterCIDR = TestKubeControllerClusterCidr
|
||||
kubeControllerService.ServiceClusterIPRange = TestKubeControllerServiceClusterIPRange
|
||||
kubeControllerService.ExtraArgs = map[string]string{"foo": "bar"}
|
||||
|
||||
imageCfg, hostCfg := buildKubeControllerConfig(kubeControllerService)
|
||||
// Test image and host config
|
||||
assertEqual(t, isStringInSlice(TestClusterCidrPrefix+TestKubeControllerClusterCidr, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in KubeController Command", TestClusterCidrPrefix+TestKubeControllerClusterCidr))
|
||||
assertEqual(t, isStringInSlice(TestServiceIPRangePrefix+TestKubeControllerServiceClusterIPRange, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in KubeController Command", TestServiceIPRangePrefix+TestKubeControllerServiceClusterIPRange))
|
||||
assertEqual(t, TestKubeControllerImage, imageCfg.Image,
|
||||
fmt.Sprintf("Failed to verify [%s] as KubeController Image", TestKubeControllerImage))
|
||||
assertEqual(t, isStringInSlice(TestKubeControllerVolumeBind, hostCfg.Binds), true,
|
||||
fmt.Sprintf("Failed to find [%s] in volume binds of KubeController", TestKubeControllerVolumeBind))
|
||||
assertEqual(t, isStringInSlice(TestKubeControllerExtraArgs, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in extra args of KubeController", TestKubeControllerExtraArgs))
|
||||
assertEqual(t, true, hostCfg.NetworkMode.IsHost(), "")
|
||||
}
|
74
services/kubelet_test.go
Normal file
74
services/kubelet_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rancher/rke/hosts"
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
TestKubeletClusterDomain = "cluster.local"
|
||||
TestKubeletClusterDNSServer = "10.1.0.3"
|
||||
TestKubeletInfraContainerImage = "test/test:latest"
|
||||
TestKubeletImage = "rancher/k8s:latest"
|
||||
TestKubeletVolumeBind = "/etc/kubernetes:/etc/kubernetes"
|
||||
TestKubeletExtraArgs = "--foo=bar"
|
||||
TestClusterDomainPrefix = "--cluster-domain="
|
||||
TestClusterDNSServerPrefix = "--cluster-dns="
|
||||
TestInfraContainerImagePrefix = "--pod-infra-container-image="
|
||||
TestHostnameOverridePrefix = "--hostname-override="
|
||||
TestKubeletEtcdNodeLabel = "--node-labels=node-role.kubernetes.io/etcd=true"
|
||||
TestKubeletCPNodeLabel = "--node-labels=node-role.kubernetes.io/master=true"
|
||||
TestKubeletWorkerNodeLabel = "--node-labels=node-role.kubernetes.io/worker=true"
|
||||
)
|
||||
|
||||
func TestKubeletConfig(t *testing.T) {
|
||||
|
||||
host := &hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "1.1.1.1",
|
||||
InternalAddress: "1.1.1.1",
|
||||
Role: []string{"worker", "controlplane", "etcd"},
|
||||
HostnameOverride: "node1",
|
||||
},
|
||||
DClient: nil,
|
||||
}
|
||||
|
||||
kubeletService := v3.KubeletService{}
|
||||
kubeletService.Image = TestKubeletImage
|
||||
kubeletService.ClusterDomain = TestKubeletClusterDomain
|
||||
kubeletService.ClusterDNSServer = TestKubeletClusterDNSServer
|
||||
kubeletService.InfraContainerImage = TestKubeletInfraContainerImage
|
||||
kubeletService.ExtraArgs = map[string]string{"foo": "bar"}
|
||||
|
||||
imageCfg, hostCfg := buildKubeletConfig(host, kubeletService)
|
||||
// Test image and host config
|
||||
assertEqual(t, isStringInSlice(TestClusterDomainPrefix+TestKubeletClusterDomain, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Command", TestClusterDomainPrefix+TestKubeletClusterDomain))
|
||||
assertEqual(t, isStringInSlice(TestClusterDNSServerPrefix+TestKubeletClusterDNSServer, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Command", TestClusterDNSServerPrefix+TestKubeletClusterDNSServer))
|
||||
assertEqual(t, isStringInSlice(TestInfraContainerImagePrefix+TestKubeletInfraContainerImage, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Command", TestInfraContainerImagePrefix+TestKubeletInfraContainerImage))
|
||||
assertEqual(t, TestKubeletImage, imageCfg.Image,
|
||||
fmt.Sprintf("Failed to verify [%s] as Kubelet Image", TestKubeletImage))
|
||||
assertEqual(t, isStringInSlice(TestHostnameOverridePrefix+host.HostnameOverride, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Command", TestHostnameOverridePrefix+host.HostnameOverride))
|
||||
assertEqual(t, isStringInSlice(TestKubeletVolumeBind, hostCfg.Binds), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Volume Binds", TestKubeletVolumeBind))
|
||||
assertEqual(t, isStringInSlice(TestKubeletExtraArgs, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet extra args", TestKubeletExtraArgs))
|
||||
assertEqual(t, true, hostCfg.Privileged,
|
||||
"Failed to verify that Kubelet is privileged")
|
||||
assertEqual(t, true, hostCfg.PidMode.IsHost(),
|
||||
"Failed to verify that Kubelet has host PID mode")
|
||||
assertEqual(t, true, hostCfg.NetworkMode.IsHost(),
|
||||
"Failed to verify that Kubelet has host Netowrk mode")
|
||||
assertEqual(t, isStringInSlice(TestKubeletEtcdNodeLabel, imageCfg.Cmd), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Command", TestKubeletEtcdNodeLabel))
|
||||
assertEqual(t, isStringInSlice(TestKubeletCPNodeLabel, imageCfg.Cmd), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Command", TestKubeletCPNodeLabel))
|
||||
assertEqual(t, isStringInSlice(TestKubeletWorkerNodeLabel, imageCfg.Cmd), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Kubelet Command", TestKubeletWorkerNodeLabel))
|
||||
}
|
34
services/kubeproxy_test.go
Normal file
34
services/kubeproxy_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
TestKubeproxyImage = "rancher/k8s:latest"
|
||||
TestKubeproxyVolumeBind = "/etc/kubernetes:/etc/kubernetes"
|
||||
TestKubeproxyExtraArgs = "--foo=bar"
|
||||
)
|
||||
|
||||
func TestKubeproxyConfig(t *testing.T) {
|
||||
|
||||
kubeproxyService := v3.KubeproxyService{}
|
||||
kubeproxyService.Image = TestKubeproxyImage
|
||||
kubeproxyService.ExtraArgs = map[string]string{"foo": "bar"}
|
||||
|
||||
imageCfg, hostCfg := buildKubeproxyConfig(nil, kubeproxyService)
|
||||
// Test image and host config
|
||||
assertEqual(t, TestKubeproxyImage, imageCfg.Image,
|
||||
fmt.Sprintf("Failed to verify [%s] as KubeProxy Image", TestKubeproxyImage))
|
||||
assertEqual(t, isStringInSlice(TestKubeproxyVolumeBind, hostCfg.Binds), true,
|
||||
fmt.Sprintf("Failed to find [%s] in KubeProxy Volume Binds", TestKubeproxyVolumeBind))
|
||||
assertEqual(t, isStringInSlice(TestKubeproxyExtraArgs, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in KubeProxy extra args", TestKubeproxyExtraArgs))
|
||||
assertEqual(t, true, hostCfg.Privileged,
|
||||
"Failed to verify that KubeProxy is privileged")
|
||||
assertEqual(t, true, hostCfg.NetworkMode.IsHost(),
|
||||
"Failed to verify that KubeProxy has host Netowrk mode")
|
||||
}
|
49
services/proxy_test.go
Normal file
49
services/proxy_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rancher/rke/hosts"
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
TestNginxProxyImage = "test/test:latest"
|
||||
TestNginxProxyConnectionString = "1.1.1.1,2.2.2.2"
|
||||
)
|
||||
|
||||
func TestNginxProxyConfig(t *testing.T) {
|
||||
cpHosts := []*hosts.Host{
|
||||
&hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "1.1.1.1",
|
||||
InternalAddress: "1.1.1.1",
|
||||
Role: []string{"controlplane"},
|
||||
HostnameOverride: "cp1",
|
||||
},
|
||||
DClient: nil,
|
||||
},
|
||||
&hosts.Host{
|
||||
RKEConfigNode: v3.RKEConfigNode{
|
||||
Address: "2.2.2.2",
|
||||
InternalAddress: "2.2.2.2",
|
||||
Role: []string{"controlplane"},
|
||||
HostnameOverride: "cp1",
|
||||
},
|
||||
DClient: nil,
|
||||
},
|
||||
}
|
||||
|
||||
nginxProxyImage := TestNginxProxyImage
|
||||
nginxProxyEnv := buildProxyEnv(cpHosts)
|
||||
assertEqual(t, TestNginxProxyConnectionString, nginxProxyEnv,
|
||||
fmt.Sprintf("Failed to verify nginx connection string [%s]", TestNginxProxyConnectionString))
|
||||
|
||||
imageCfg, hostCfg := buildNginxProxyConfig(nil, nginxProxyEnv, nginxProxyImage)
|
||||
// Test image and host config
|
||||
assertEqual(t, TestNginxProxyImage, imageCfg.Image,
|
||||
fmt.Sprintf("Failed to verify [%s] as Nginx Proxy Image", TestNginxProxyImage))
|
||||
assertEqual(t, true, hostCfg.NetworkMode.IsHost(),
|
||||
"Failed to verify that Nginx Proxy has host Netowrk mode")
|
||||
}
|
32
services/scheduler_test.go
Normal file
32
services/scheduler_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
TestSchedulerImage = "rancher/k8s:latest"
|
||||
TestSchedulerVolumeBind = "/etc/kubernetes:/etc/kubernetes"
|
||||
TestSchedulerExtraArgs = "--foo=bar"
|
||||
)
|
||||
|
||||
func TestSchedulerConfig(t *testing.T) {
|
||||
|
||||
schedulerService := v3.SchedulerService{}
|
||||
schedulerService.Image = TestSchedulerImage
|
||||
schedulerService.ExtraArgs = map[string]string{"foo": "bar"}
|
||||
|
||||
imageCfg, hostCfg := buildSchedulerConfig(nil, schedulerService)
|
||||
// Test image and host config
|
||||
assertEqual(t, TestSchedulerImage, imageCfg.Image,
|
||||
fmt.Sprintf("Failed to verify [%s] as Scheduler Image", TestSchedulerImage))
|
||||
assertEqual(t, isStringInSlice(TestSchedulerVolumeBind, hostCfg.Binds), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Scheduler Volume Binds", TestSchedulerVolumeBind))
|
||||
assertEqual(t, isStringInSlice(TestSchedulerExtraArgs, imageCfg.Entrypoint), true,
|
||||
fmt.Sprintf("Failed to find [%s] in Scheduler extra args", TestSchedulerExtraArgs))
|
||||
assertEqual(t, true, hostCfg.NetworkMode.IsHost(),
|
||||
"Failed to verify that Scheduler has host Netowrk mode")
|
||||
}
|
47
services/services_test.go
Normal file
47
services/services_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
TestServiceIP = "10.233.0.1"
|
||||
TestIncorrectClusterServiceIPRange = "#!453.23423.dsf.23"
|
||||
TestClusterServiceIPRange = "10.233.0.0/18"
|
||||
)
|
||||
|
||||
func TestKubernetesServiceIP(t *testing.T) {
|
||||
kubernetesServiceIP, err := GetKubernetesServiceIP(TestClusterServiceIPRange)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertEqual(t, kubernetesServiceIP.String(), TestServiceIP,
|
||||
fmt.Sprintf("Failed to get correct kubernetes service IP [%s] for range [%s]", kubernetesServiceIP.String(), TestClusterServiceIPRange))
|
||||
}
|
||||
|
||||
func TestIncorrectKubernetesServiceIP(t *testing.T) {
|
||||
_, err := GetKubernetesServiceIP(TestIncorrectClusterServiceIPRange)
|
||||
if err == nil {
|
||||
t.Fatalf("Failed to catch error when parsing incorrect cluster service ip range")
|
||||
}
|
||||
}
|
||||
|
||||
func isStringInSlice(a string, list []string) bool {
|
||||
for _, b := range list {
|
||||
if b == a {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func assertEqual(t *testing.T, a interface{}, b interface{}, message string) {
|
||||
if a == b {
|
||||
return
|
||||
}
|
||||
if len(message) == 0 {
|
||||
message = fmt.Sprintf("%v != %v", a, b)
|
||||
}
|
||||
t.Fatal(message)
|
||||
}
|
Reference in New Issue
Block a user