forked from openshift/azure-disk-csi-driver-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure_stack_hub_test.go
97 lines (86 loc) · 2.69 KB
/
azure_stack_hub_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package azurestackhub
import (
"context"
"testing"
cfgV1 "github.com/openshift/api/config/v1"
"github.com/openshift/azure-disk-csi-driver-operator/assets"
"github.com/openshift/client-go/config/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
appsV1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"
)
func TestAzureStackHubDetectionHappyPath(t *testing.T) {
ctx := context.Background()
infrastructure := mockInfra(cfgV1.AzureStackCloud)
cfg := fake.NewSimpleClientset(infrastructure).ConfigV1()
hub, err := RunningOnAzureStackHub(ctx, cfg)
assert.Nil(t, err)
assert.True(t, hub)
}
func TestAzureStackHubDetectionOnAzurePublicCloud(t *testing.T) {
ctx := context.Background()
infrastructure := mockInfra(cfgV1.AzurePublicCloud)
cfg := fake.NewSimpleClientset(infrastructure).ConfigV1()
hub, err := RunningOnAzureStackHub(ctx, cfg)
assert.Nil(t, err)
assert.False(t, hub)
}
func TestInjectPodSpecHappyPath(t *testing.T) {
file, err := assets.ReadFile("controller.yaml")
assert.Nil(t, err)
dep := &appsV1.Deployment{}
assert.Nil(t, yaml.Unmarshal(file, dep))
injectEnvAndMounts(&dep.Spec.Template.Spec)
assert.Len(t, dep.Spec.Template.Spec.Volumes, 7)
foundCfgVolume := false
for _, v := range dep.Spec.Template.Spec.Volumes {
if v.Name == azureCfgName {
assert.Equal(t, configMapName, v.VolumeSource.ConfigMap.Name)
foundCfgVolume = true
}
}
assert.Truef(t, foundCfgVolume, "did not find volume with name %s", azureCfgName)
var csiDriver v1.Container
for _, c := range dep.Spec.Template.Spec.Containers {
if c.Name == "csi-driver" {
csiDriver = c
break
}
}
assert.NotNil(t, csiDriver, "no csi-driver container found")
assert.Len(t, csiDriver.VolumeMounts, 5)
foundCfgVolumeMount := false
for _, v := range csiDriver.VolumeMounts {
if v.Name == azureCfgName {
assert.Equal(t, azureStackCloudConfig, v.MountPath)
foundCfgVolumeMount = true
}
}
assert.Truef(t, foundCfgVolumeMount, "did not find volume mount with name %s", azureCfgName)
foundStackEnv := false
for _, env := range csiDriver.Env {
if env.Name == configEnvName {
foundStackEnv = true
assert.Equal(t, azureStackCloudConfig, env.Value)
break
}
}
assert.Truef(t, foundStackEnv, "did not find env with name %s", configEnvName)
}
func mockInfra(cloudName cfgV1.AzureCloudEnvironment) *cfgV1.Infrastructure {
infrastructure := &cfgV1.Infrastructure{
ObjectMeta: metaV1.ObjectMeta{
Name: infraConfigName,
},
Status: cfgV1.InfrastructureStatus{
PlatformStatus: &cfgV1.PlatformStatus{
Azure: &cfgV1.AzurePlatformStatus{
CloudName: cloudName,
},
},
},
}
return infrastructure
}