forked from Azure/aks-engine-azurestack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscale_test.go
137 lines (128 loc) · 3.87 KB
/
scale_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
130
131
132
133
134
135
136
137
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package cmd
import (
"testing"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func TestNewScaleCmd(t *testing.T) {
command := newScaleCmd()
if command.Use != scaleName || command.Short != scaleShortDescription || command.Long != scaleLongDescription {
t.Fatalf("scale command should have use %s equal %s, short %s equal %s and long %s equal to %s", command.Use, scaleName, command.Short, scaleShortDescription, command.Long, scaleLongDescription)
}
expectedFlags := []string{"location", "resource-group", "api-model", "new-node-count", "node-pool", "master-FQDN"}
for _, f := range expectedFlags {
if command.Flags().Lookup(f) == nil {
t.Fatalf("scale command should have flag %s", f)
}
}
command.SetArgs([]string{})
if err := command.Execute(); err == nil {
t.Fatalf("expected an error when calling scale with no arguments")
}
}
func TestScaleCmdValidate(t *testing.T) {
r := &cobra.Command{}
cases := []struct {
sc *scaleCmd
expectedErr error
name string
}{
{
sc: &scaleCmd{
apiModelPath: "./not/used",
deploymentDirectory: "",
location: "centralus",
resourceGroupName: "",
agentPoolToScale: "agentpool1",
newDesiredAgentCount: 5,
masterFQDN: "test",
},
expectedErr: errors.New("--resource-group must be specified"),
name: "NoResourceGroup",
},
{
sc: &scaleCmd{
apiModelPath: "./not/used",
deploymentDirectory: "",
location: "",
resourceGroupName: "testRG",
agentPoolToScale: "agentpool1",
newDesiredAgentCount: 5,
masterFQDN: "test",
},
expectedErr: errors.New("--location must be specified"),
name: "NoLocation",
},
{
sc: &scaleCmd{
apiModelPath: "./not/used",
deploymentDirectory: "",
location: "centralus",
resourceGroupName: "testRG",
agentPoolToScale: "agentpool1",
masterFQDN: "test",
},
expectedErr: errors.New("--new-node-count must be specified"),
name: "NoNewNodeCount",
},
{
sc: &scaleCmd{
apiModelPath: "",
deploymentDirectory: "",
location: "centralus",
resourceGroupName: "testRG",
agentPoolToScale: "agentpool1",
newDesiredAgentCount: 5,
masterFQDN: "test",
},
expectedErr: errors.New("--api-model must be specified"),
name: "NoAPIModel",
},
{
sc: &scaleCmd{
apiModelPath: "some/long/path",
deploymentDirectory: "someDir",
location: "centralus",
resourceGroupName: "testRG",
agentPoolToScale: "agentpool1",
newDesiredAgentCount: 5,
masterFQDN: "test",
},
expectedErr: errors.New("ambiguous, please specify only one of --api-model and --deployment-dir"),
name: "Ambiguous",
},
{
sc: &scaleCmd{
apiModelPath: "./not/used",
deploymentDirectory: "",
location: "centralus",
resourceGroupName: "testRG",
agentPoolToScale: "agentpool1",
newDesiredAgentCount: 5,
masterFQDN: "test",
},
expectedErr: nil,
name: "IsValid",
},
}
for _, tc := range cases {
c := tc
t.Run(c.name, func(t *testing.T) {
t.Parallel()
err := c.sc.validate(r)
if err != nil && c.expectedErr != nil {
if err.Error() != c.expectedErr.Error() {
t.Fatalf("expected validate scale command to return error %s, but instead got %s", c.expectedErr.Error(), err.Error())
}
} else {
if c.expectedErr != nil {
t.Fatalf("expected validate scale command to return error %s, but instead got no error", c.expectedErr.Error())
} else if err != nil {
t.Fatalf("expected validate scale command to return no error, but instead got %s", err.Error())
}
}
})
}
}