-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgateways_test.go
More file actions
115 lines (100 loc) · 3.07 KB
/
gateways_test.go
File metadata and controls
115 lines (100 loc) · 3.07 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
package cmd
import (
"bytes"
"fmt"
"net/http"
"testing"
"github.com/drycc/controller-sdk-go/api"
"github.com/stretchr/testify/assert"
"github.com/drycc/workflow-cli/pkg/testutil"
)
func TestGatewaysList(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/gateways/", func(w http.ResponseWriter, _ *http.Request) {
testutil.SetHeaders(w)
fmt.Fprintf(w, `{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"app": "foo",
"name": "foo",
"created": "2023-04-19T00:00:00UTC",
"owner": "test",
"updated": "2023-04-19T00:00:00UTC",
"listeners": [
{
"name": "foo-80-http",
"port": 80,
"protocol": "HTTP",
"allowedRoutes": {"namespaces": {"from": "All"}}
},
{
"name": "foo-443-https",
"port": 443,
"protocol": "HTTPS",
"allowedRoutes": {"namespaces": {"from": "All"}}
}
],
"addresses": [
{
"type": "IPAddress",
"value": "192.168.11.1"
}
]
}
]
}`)
})
err = cmdr.GatewaysList("foo", -1)
assert.NoError(t, err)
assert.Equal(t, b.String(), `NAME LISENTER PORT PROTOCOL ADDRESSES
foo foo-80-http 80 HTTP 192.168.11.1
foo foo-443-https 443 HTTPS 192.168.11.1
`, "output")
}
func TestGatewaysAdd(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/gateways/", func(w http.ResponseWriter, r *http.Request) {
testutil.AssertBody(t, api.GatewayCreateRequest{Name: "example-go", Port: 443, Protocol: "HTTPS"}, r)
testutil.SetHeaders(w)
w.WriteHeader(http.StatusCreated)
// Body isn't used by CLI, so it isn't set.
w.Write([]byte("{}"))
})
err = cmdr.GatewaysAdd("foo", "example-go", 443, "HTTPS")
assert.NoError(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Adding gateway example-go to foo... done\n", "output")
}
func TestGatewaysDelete(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/gateways/", func(w http.ResponseWriter, _ *http.Request) {
testutil.SetHeaders(w)
w.WriteHeader(http.StatusNoContent)
})
err = cmdr.GatewaysRemove("foo", "example-go", 443, "HTTPS")
assert.NoError(t, err)
assert.Equal(t, testutil.StripProgress(b.String()), "Removing gateway example-go to foo... done\n", "output")
}