-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathworkspaces_test.go
More file actions
54 lines (46 loc) · 1.24 KB
/
workspaces_test.go
File metadata and controls
54 lines (46 loc) · 1.24 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
package commands
import (
"bytes"
"fmt"
"net/http"
"testing"
"github.com/drycc/workflow-cli/pkg/testutil"
"github.com/stretchr/testify/assert"
)
func TestWorkspacesSwitch(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/workspaces/my-workspace/", func(w http.ResponseWriter, _ *http.Request) {
testutil.SetHeaders(w)
fmt.Fprintf(w, `{
"name": "my-workspace",
"email": "test@example.com",
"created": "2016-08-22T17:40:16Z",
"updated": "2016-08-22T17:40:16Z"
}`)
})
err = cmdr.WorkspacesSwitch("my-workspace")
assert.NoError(t, err)
assert.Contains(t, b.String(), "Switched to workspace my-workspace")
}
func TestWorkspacesSwitchNotFound(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/workspaces/nonexistent/", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
err = cmdr.WorkspacesSwitch("nonexistent")
assert.Error(t, err)
}