forked from virtual-kubelet/azure-aci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
94 lines (79 loc) · 1.86 KB
/
config_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
package azure
import (
"bytes"
"strings"
"testing"
)
const cfg = `
Region = "westus"
ResourceGroup = "virtual-kubeletrg"
CPU = "100"
Memory = "100Gi"
Pods = "20"`
func TestConfig(t *testing.T) {
br := bytes.NewReader([]byte(cfg))
var p ACIProvider
err := p.loadConfig(br)
if err != nil {
t.Error(err)
}
wanted := "westus"
if p.region != wanted {
t.Errorf("Wanted %s, got %s.", wanted, p.region)
}
wanted = "virtual-kubeletrg"
if p.resourceGroup != wanted {
t.Errorf("Wanted %s, got %s.", wanted, p.resourceGroup)
}
wanted = "100"
if p.cpu != wanted {
t.Errorf("Wanted %s, got %s.", wanted, p.cpu)
}
wanted = "100Gi"
if p.memory != wanted {
t.Errorf("Wanted %s, got %s.", wanted, p.memory)
}
wanted = "20"
if p.pods != wanted {
t.Errorf("Wanted %s, got %s.", wanted, p.pods)
}
}
const cfgBad = `
Region = "westus"
ResourceGroup = "virtual-kubeletrg"
OperatingSystem = "noop"`
func TestBadConfig(t *testing.T) {
br := bytes.NewReader([]byte(cfgBad))
var p ACIProvider
err := p.loadConfig(br)
if err == nil {
t.Fatal("expected loadConfig to fail with bad operating system option")
}
if !strings.Contains(err.Error(), "is not a valid operating system") {
t.Fatalf("expected loadConfig to fail with 'is not a valid operating system' but got: %v", err)
}
}
const defCfg = `
Region = "westus"
ResourceGroup = "virtual-kubeletrg"`
func TestDefaultedConfig(t *testing.T) {
br := bytes.NewReader([]byte(defCfg))
var p ACIProvider
err := p.loadConfig(br)
if err != nil {
t.Error(err)
}
// Test that defaults work with no settings in config.
wanted := "20"
if p.cpu != wanted {
t.Errorf("Wanted default %s, got %s.", wanted, p.cpu)
}
wanted = "100Gi"
if p.memory != wanted {
t.Errorf("Wanted default %s, got %s.", wanted, p.memory)
}
wanted = "20"
if p.pods != wanted {
t.Errorf("Wanted default %s, got %s.", wanted, p.pods)
}
}