-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlabels_test.go
More file actions
113 lines (100 loc) · 2.97 KB
/
labels_test.go
File metadata and controls
113 lines (100 loc) · 2.97 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
105
106
107
108
109
110
111
112
113
package cmd
import (
"bytes"
"fmt"
"net/http"
"testing"
"github.com/arschles/assert"
"github.com/drycc/controller-sdk-go/api"
"github.com/drycc/workflow-cli/pkg/testutil"
"strings"
)
func TestLabelsList(t *testing.T) {
t.Parallel()
cf, server, err := testutil.NewTestServerAndClient()
if err != nil {
t.Fatal(err)
}
defer server.Close()
var b bytes.Buffer
cmdr := DryccCmd{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": "jim",
"app": "rivendell",
"label": {"team" : "drycc", "git_repo": "https://github.com/drycc/controller-sdk-go"},
"created": "2014-01-01T00:00:00UTC",
"updated": "2014-01-01T00:00:00UTC",
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
}`)
})
err = cmdr.LabelsList("rivendell")
assert.NoErr(t, err)
assert.Equal(t, strings.TrimSpace(b.String()), `=== rivendell Label
git_repo: https://github.com/drycc/controller-sdk-go
team: drycc`, "output")
server.Mux.HandleFunc("/v2/apps/mordor/settings/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
fmt.Fprintf(w, `{
"owner": "priw",
"app": "mordor",
"created": "2014-01-01T00:00:00UTC",
"updated": "2014-01-01T00:00:00UTC",
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
}`)
})
b.Reset()
err = cmdr.LabelsList("mordor")
assert.NoErr(t, err)
assert.Equal(t, b.String(), "=== mordor Label\nNo labels found.\n", "output")
}
func TestListsSet(t *testing.T) {
t.Parallel()
cf, server, err := testutil.NewTestServerAndClient()
if err != nil {
t.Fatal(err)
}
defer server.Close()
var b bytes.Buffer
cmdr := DryccCmd{WOut: &b, ConfigFile: cf}
server.Mux.HandleFunc("/v2/apps/lothlorien/settings/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
data := map[string]interface{}{
"git_repo": "https://github.com/drycc/controller-sdk-go",
"team": "drycc",
}
testutil.AssertBody(t, api.AppSettings{Label: data}, r)
fmt.Fprintf(w, "{}")
})
err = cmdr.LabelsSet("lothlorien", []string{
"team=drycc",
"git_repo=https://github.com/drycc/controller-sdk-go",
})
assert.NoErr(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Applying labels on lothlorien... done\n", "output")
}
func TestListsUnset(t *testing.T) {
t.Parallel()
cf, server, err := testutil.NewTestServerAndClient()
if err != nil {
t.Fatal(err)
}
defer server.Close()
var b bytes.Buffer
cmdr := DryccCmd{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{Label: map[string]interface{}{
"team": nil,
"git_repo": nil,
}}, r)
fmt.Fprintf(w, "{}")
})
err = cmdr.LabelsUnset("bree", []string{
"team",
"git_repo",
})
assert.NoErr(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Removing labels on bree... done\n", "output")
}