forked from digitalocean/doctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloating_ip_list_test.go
116 lines (103 loc) · 2.56 KB
/
floating_ip_list_test.go
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
package integration
import (
"fmt"
"net/http"
"net/http/httptest"
"net/http/httputil"
"os/exec"
"strings"
"testing"
"github.com/sclevine/spec"
"github.com/stretchr/testify/require"
)
var _ = suite("compute/floating-ip/list", func(t *testing.T, when spec.G, it spec.S) {
var (
expect *require.Assertions
cmd *exec.Cmd
server *httptest.Server
)
it.Before(func() {
expect = require.New(t)
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/v2/reserved_ips":
auth := req.Header.Get("Authorization")
if auth != "Bearer some-magic-token" {
w.WriteHeader(http.StatusUnauthorized)
return
}
if req.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
w.Write([]byte(floatingIPListResponse))
default:
dump, err := httputil.DumpRequest(req, true)
if err != nil {
t.Fatal("failed to dump request")
}
t.Fatalf("received unknown request: %s", dump)
}
}))
})
when("required flags are passed", func() {
it("lists all floating-ips", func() {
aliases := []string{"list", "ls"}
for _, alias := range aliases {
cmd = exec.Command(builtBinaryPath,
"-t", "some-magic-token",
"-u", server.URL,
"compute",
"floating-ip",
alias,
)
output, err := cmd.CombinedOutput()
expect.NoError(err, fmt.Sprintf("received error output: %s", output))
expect.Equal(strings.TrimSpace(floatingIPListOutput), strings.TrimSpace(string(output)))
}
})
})
})
const (
floatingIPListOutput = `
IP Region Droplet ID Droplet Name Project ID
8.8.8.8 nyc3 8888 hello c98374fa-35e2-11ed-870f-c7de97c5d5ed
1.1.1.1 nyc3 476dea88-35ea-11ed-8e93-f7eb94d49952
`
floatingIPListResponse = `
{
"reserved_ips": [
{
"ip": "8.8.8.8",
"droplet": {"id": 8888, "name": "hello"},
"region": {
"name": "New York 3",
"slug": "nyc3",
"sizes": [ "s-1vcpu-1gb" ],
"features": [ "metadata" ],
"available": true
},
"locked": false,
"project_id": "c98374fa-35e2-11ed-870f-c7de97c5d5ed"
},
{
"ip": "1.1.1.1",
"droplet":null,
"region": {
"name": "New York 3",
"slug": "nyc3",
"sizes": [ "s-1vcpu-1gb" ],
"features": [ "metadata" ],
"available": true
},
"locked": false,
"project_id": "476dea88-35ea-11ed-8e93-f7eb94d49952"
}
],
"links": {},
"meta": {
"total": 2
}
}
`
)