-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuilds_test.go
More file actions
199 lines (175 loc) · 4.84 KB
/
builds_test.go
File metadata and controls
199 lines (175 loc) · 4.84 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package cmd
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
"github.com/arschles/assert"
"github.com/drycc/controller-sdk-go/api"
"github.com/drycc/workflow-cli/pkg/testutil"
)
func TestParseProcfile(t *testing.T) {
t.Parallel()
procMap, err := parseProcfile([]byte(`web: ./test
foo: test --test
`))
assert.NoErr(t, err)
assert.Equal(t, procMap, map[string]string{"web": "./test", "foo": "test --test"}, "map")
_, err = parseProcfile([]byte(`web: ./test
foo
`))
assert.ExistsErr(t, err, "yaml")
}
func TestBuildsList(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/foo/builds/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
fmt.Fprintf(w, `{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"app": "",
"created": "2014-01-01T00:00:00UTC",
"dockerfile": "",
"image": "",
"owner": "",
"procfile": {},
"sha": "",
"updated": "",
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
},
{
"app": "",
"created": "2014-01-05T00:00:00UTC",
"dockerfile": "",
"image": "",
"owner": "",
"procfile": {},
"sha": "",
"updated": "",
"uuid": "c4aed81c-d1ca-4ff1-ab89-d2151264e1a3"
}
]
}`)
})
err = cmdr.BuildsList("foo", -1)
assert.NoErr(t, err)
assert.Equal(t, b.String(), `=== foo Builds
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 2014-01-01T00:00:00UTC
c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 2014-01-05T00:00:00UTC
`, "output")
}
func TestBuildsListLimit(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/foo/builds/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
fmt.Fprintf(w, `{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"app": "foo",
"created": "2014-01-01T00:00:00UTC",
"dockerfile": "",
"image": "",
"owner": "",
"procfile": {},
"sha": "",
"updated": "",
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
}
]
}`)
})
err = cmdr.BuildsList("foo", 1)
assert.NoErr(t, err)
assert.Equal(t, b.String(), `=== foo Builds (1 of 2)
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 2014-01-01T00:00:00UTC
`, "output")
}
func TestBuildsCreate(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}
// Create a new temporary directory and change to it.
name, err := ioutil.TempDir("", "client")
assert.NoErr(t, err)
err = os.Chdir(name)
assert.NoErr(t, err)
server.Mux.HandleFunc("/v2/apps/enterprise/builds/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
testutil.AssertBody(t, api.CreateBuildRequest{
Image: "ncc/1701:A",
Stack: "container",
}, r)
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "{}")
})
err = cmdr.BuildsCreate("enterprise", "ncc/1701:A", "container", "")
assert.NoErr(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Creating build... done\n", "output")
server.Mux.HandleFunc("/v2/apps/bradbury/builds/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
testutil.AssertBody(t, api.CreateBuildRequest{
Image: "nx/72307:latest",
Stack: "container",
Procfile: map[string]string{
"web": "./drive",
"warp": "./warp 8",
},
}, r)
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "{}")
})
b.Reset()
err = cmdr.BuildsCreate("bradbury", "nx/72307:latest", "container", `web: ./drive
warp: ./warp 8
`)
assert.NoErr(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Creating build... done\n", "output")
server.Mux.HandleFunc("/v2/apps/franklin/builds/", func(w http.ResponseWriter, r *http.Request) {
testutil.SetHeaders(w)
testutil.AssertBody(t, api.CreateBuildRequest{
Image: "nx/326:latest",
Stack: "container",
Procfile: map[string]string{
"web": "./drive",
"warp": "./warp 8",
},
}, r)
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "{}")
})
b.Reset()
err = ioutil.WriteFile("Procfile", []byte(`web: ./drive
warp: ./warp 8
`), os.ModePerm)
assert.NoErr(t, err)
err = cmdr.BuildsCreate("franklin", "nx/326:latest", "container", "")
assert.NoErr(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Creating build... done\n", "output")
}