forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_test.go
125 lines (117 loc) · 4.92 KB
/
transform_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
package transform
import (
"encoding/json"
"fmt"
"io/ioutil"
"testing"
"github.com/Azure/acs-engine/pkg/helpers"
"github.com/Azure/acs-engine/pkg/i18n"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
)
func TestNormalizeForVMSSScaling(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeForVMSSScaling")
fileContents, e := ioutil.ReadFile("./transformtestfiles/dcos_template.json")
Expect(e).To(BeNil())
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/dcos_scale_template.json")
Expect(e).To(BeNil())
templateJSON := string(fileContents)
var template interface{}
json.Unmarshal([]byte(templateJSON), &template)
templateMap := template.(map[string]interface{})
transformer := Transformer{}
e = transformer.NormalizeForVMSSScaling(logger, templateMap)
Expect(e).To(BeNil())
ValidateTemplate(templateMap, expectedFileContents, "TestNormalizeForVMSSScaling")
}
func TestNormalizeForK8sVMASScalingUp(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeForK8sVMASScalingUp")
fileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_template.json")
Expect(e).To(BeNil())
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_scale_template.json")
Expect(e).To(BeNil())
templateJSON := string(fileContents)
var template interface{}
json.Unmarshal([]byte(templateJSON), &template)
templateMap := template.(map[string]interface{})
transformer := Transformer{}
e = transformer.NormalizeForK8sVMASScalingUp(logger, templateMap)
Expect(e).To(BeNil())
ValidateTemplate(templateMap, expectedFileContents, "TestNormalizeForK8sVMASScalingUp")
}
func TestNormalizeForK8sVMASScalingUpWithVnet(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeForK8sVMASScalingUp")
fileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_vnet_template.json")
Expect(e).To(BeNil())
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_vnet_scale_template.json")
Expect(e).To(BeNil())
templateJSON := string(fileContents)
var template interface{}
json.Unmarshal([]byte(templateJSON), &template)
templateMap := template.(map[string]interface{})
transformer := Transformer{}
e = transformer.NormalizeForK8sVMASScalingUp(logger, templateMap)
Expect(e).To(BeNil())
ValidateTemplate(templateMap, expectedFileContents, "TestNormalizeForK8sVMASScalingUpWithVnet")
}
func TestNormalizeResourcesForK8sMasterUpgrade(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeResourcesForK8sMasterUpgrade")
fileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_template.json")
Expect(e).To(BeNil())
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_master_upgrade_template.json")
Expect(e).To(BeNil())
templateJSON := string(fileContents)
var template interface{}
json.Unmarshal([]byte(templateJSON), &template)
templateMap := template.(map[string]interface{})
transformer := &Transformer{
Translator: &i18n.Translator{
Locale: nil,
},
}
agentsToKeepMap := make(map[string]bool)
agentsToKeepMap["agentpool1"] = true
agentsToKeepMap["agentpool2"] = true
e = transformer.NormalizeResourcesForK8sMasterUpgrade(logger, templateMap, false, agentsToKeepMap)
Expect(e).To(BeNil())
ValidateTemplate(templateMap, expectedFileContents, "TestNormalizeResourcesForK8sMasterUpgrade")
}
func TestNormalizeResourcesForK8sAgentUpgrade(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeResourcesForK8sAgentUpgrade")
fileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_template.json")
Expect(e).To(BeNil())
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_agent_upgrade_template.json")
Expect(e).To(BeNil())
templateJSON := string(fileContents)
var template interface{}
json.Unmarshal([]byte(templateJSON), &template)
templateMap := template.(map[string]interface{})
transformer := &Transformer{
Translator: &i18n.Translator{
Locale: nil,
},
}
agentsToKeepMap := make(map[string]bool)
agentsToKeepMap["agentpool1"] = true
agentsToKeepMap["agentpool2"] = false
e = transformer.NormalizeResourcesForK8sAgentUpgrade(logger, templateMap, false, agentsToKeepMap)
Expect(e).To(BeNil())
ValidateTemplate(templateMap, expectedFileContents, "TestNormalizeResourcesForK8sAgentUpgrade")
}
func ValidateTemplate(templateMap map[string]interface{}, expectedFileContents []byte, testFileName string) {
output, e := helpers.JSONMarshal(templateMap, false)
Expect(e).To(BeNil())
prettyOutput, e := PrettyPrintArmTemplate(string(output))
Expect(e).To(BeNil())
prettyExpectedOutput, e := PrettyPrintArmTemplate(string(expectedFileContents))
Expect(e).To(BeNil())
if prettyOutput != prettyExpectedOutput {
ioutil.WriteFile(fmt.Sprintf("./transformtestfiles/%s.failure.json", testFileName), []byte(prettyOutput), 0600)
}
Expect(prettyOutput).To(Equal(prettyExpectedOutput))
}