-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathautoscale_test.go
More file actions
104 lines (91 loc) · 2.89 KB
/
autoscale_test.go
File metadata and controls
104 lines (91 loc) · 2.89 KB
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
package cmd
import (
"bytes"
"fmt"
"net/http"
"testing"
"github.com/arschles/assert"
"github.com/deis/controller-sdk-go/api"
"github.com/deis/workflow-cli/pkg/testutil"
)
func TestAutoscaleList(t *testing.T) {
t.Parallel()
cf, server, err := testutil.NewTestServerAndClient()
if err != nil {
t.Fatal(err)
}
defer server.Close()
var b bytes.Buffer
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}
server.Mux.HandleFunc("/v2/apps/rivendell/settings/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
fmt.Fprintf(w, `{
"owner": "elrond",
"app": "rivendell",
"autoscale": {"cmd": {"min": 3, "max": 8, "cpu_percent": 40}},
"created": "2014-01-01T00:00:00UTC",
"updated": "2014-01-01T00:00:00UTC",
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
}`)
})
err = cmdr.AutoscaleList("rivendell")
assert.NoErr(t, err)
assert.Equal(t, b.String(), "=== rivendell Autoscale\n\n--- cmd:\nMin Replicas: 3\nMax Replicas: 8\nCPU: 40%\n", "output")
server.Mux.HandleFunc("/v2/apps/mordor/settings/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
fmt.Fprintf(w, `{
"owner": "sauron",
"app": "mordor",
"created": "2014-01-01T00:00:00UTC",
"updated": "2014-01-01T00:00:00UTC",
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
}`)
})
b.Reset()
err = cmdr.AutoscaleList("mordor")
assert.NoErr(t, err)
assert.Equal(t, b.String(), "=== mordor Autoscale\n\nNo autoscale rules found.\n", "output")
}
func TestAutoscaleSet(t *testing.T) {
t.Parallel()
cf, server, err := testutil.NewTestServerAndClient()
if err != nil {
t.Fatal(err)
}
defer server.Close()
var b bytes.Buffer
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}
server.Mux.HandleFunc("/v2/apps/lothlorien/settings/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
data := map[string]*api.Autoscale{
"cmd": {
Min: 3,
Max: 8,
CPUPercent: 40,
},
}
testutil.AssertBody(t, api.AppSettings{Autoscale: data}, r)
fmt.Fprintf(w, `{}`)
})
err = cmdr.AutoscaleSet("lothlorien", "cmd", 3, 8, 40)
assert.NoErr(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Applying autoscale settings for process type cmd on lothlorien... done\n", "output")
}
func TestAutoscaleUnset(t *testing.T) {
t.Parallel()
cf, server, err := testutil.NewTestServerAndClient()
if err != nil {
t.Fatal(err)
}
defer server.Close()
var b bytes.Buffer
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}
server.Mux.HandleFunc("/v2/apps/bree/settings/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
testutil.AssertBody(t, api.AppSettings{Autoscale: map[string]*api.Autoscale{"cmd": nil}}, r)
fmt.Fprintf(w, `{"autoscale":{"cmd":null}}`)
})
err = cmdr.AutoscaleUnset("bree", "cmd")
assert.NoErr(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Removing autoscale for process type cmd on bree... done\n", "output")
}