forked from virtual-kubelet/virtual-kubelet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acsCredential_test.go
129 lines (108 loc) · 2.95 KB
/
acsCredential_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package azure
import (
"io/ioutil"
"os"
"testing"
)
const cred = `
{
"cloud":"AzurePublicCloud",
"tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"subscriptionId": "11122233-4444-5555-6666-777888999000",
"aadClientId": "123",
"aadClientSecret": "456",
"resourceGroup": "vk-test-rg",
"location": "westcentralus",
"subnetName": "k8s-subnet",
"securityGroupName": "k8s-master-nsg",
"vnetName": "k8s-vnet",
"routeTableName": "k8s-master-routetable",
"primaryAvailabilitySetName": "agentpool1-availabilitySet",
"cloudProviderBackoff": true,
"cloudProviderBackoffRetries": 6,
"cloudProviderBackoffExponent": 1.5,
"cloudProviderBackoffDuration": 5,
"cloudProviderBackoffJitter": 1,
"cloudProviderRatelimit": true,
"cloudProviderRateLimitQPS": 3,
"cloudProviderRateLimitBucket": 10
}`
func TestAcsCred(t *testing.T) {
file, err := ioutil.TempFile("", "acs_test")
if err != nil {
t.Error(err)
}
defer os.Remove(file.Name())
if _, err := file.Write([]byte(cred)); err != nil {
t.Error(err)
}
cred, err := NewAcsCredential(file.Name())
if err != nil {
t.Error(err)
}
wanted := "AzurePublicCloud"
if cred.Cloud != wanted {
t.Errorf("Wanted %s, got %s.", wanted, cred.Cloud)
}
wanted = "72f988bf-86f1-41af-91ab-2d7cd011db47"
if cred.TenantID != wanted {
t.Errorf("Wanted %s, got %s.", wanted, cred.TenantID)
}
wanted = "11122233-4444-5555-6666-777888999000"
if cred.SubscriptionID != wanted {
t.Errorf("Wanted %s, got %s.", wanted, cred.SubscriptionID)
}
wanted = "123"
if cred.ClientID != wanted {
t.Errorf("Wanted %s, got %s.", wanted, cred.ClientID)
}
wanted = "456"
if cred.ClientSecret != wanted {
t.Errorf("Wanted %s, got %s.", wanted, cred.ClientSecret)
}
wanted = "vk-test-rg"
if cred.ResourceGroup != wanted {
t.Errorf("Wanted %s, got %s.", wanted, cred.ResourceGroup)
}
wanted = "westcentralus"
if cred.Region != wanted {
t.Errorf("Wanted %s, got %s.", wanted, cred.Region)
}
}
func TestAcsCredFileNotFound(t *testing.T) {
file, err := ioutil.TempFile("", "acs_test")
if err != nil {
t.Error(err)
}
fileName := file.Name()
if err := file.Close(); err != nil {
t.Error(err)
}
os.Remove(fileName)
if _, err := NewAcsCredential(fileName); err == nil {
t.Fatal("expected to fail with bad json")
}
}
const credBad = `
{
"cloud":"AzurePublicCloud",
"tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"subscriptionId": "11122233-4444-5555-6666-777888999000",
"aadClientId": "123",
"aadClientSecret": "456",
"resourceGroup": "vk-test-rg",
"location": "westcentralus",
"subnetName": "k8s-subnet",`
func TestAcsCredBadJson(t *testing.T) {
file, err := ioutil.TempFile("", "acs_test")
if err != nil {
t.Error(err)
}
defer os.Remove(file.Name())
if _, err := file.Write([]byte(credBad)); err != nil {
t.Error(err)
}
if _, err := NewAcsCredential(file.Name()); err == nil {
t.Fatal("expected to fail with bad json")
}
}