-
Notifications
You must be signed in to change notification settings - Fork 398
/
Copy pathdatabase_user_list_test.go
90 lines (79 loc) · 1.86 KB
/
database_user_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
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("database/user/list", func(t *testing.T, when spec.G, it spec.S) {
var (
expect *require.Assertions
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/databases/some-database-id/users":
auth := req.Header.Get("Authorization")
if auth != "Bearer some-magic-token" {
w.WriteHeader(http.StatusTeapot)
}
if req.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
w.Write([]byte(databaseUserListResponse))
default:
dump, err := httputil.DumpRequest(req, true)
if err != nil {
t.Fatal("failed to dump request")
}
t.Fatalf("received unknown request: %s", dump)
}
}))
})
when("all required flags are passed", func() {
it("lists users for the database", func() {
cmd := exec.Command(builtBinaryPath,
"-t", "some-magic-token",
"-u", server.URL,
"database",
"user",
"list",
"some-database-id",
)
output, err := cmd.CombinedOutput()
expect.NoError(err, fmt.Sprintf("received error output: %s", output))
expect.Equal(strings.TrimSpace(databaseUserListOutput), strings.TrimSpace(string(output)))
})
})
})
const (
databaseUserListOutput = `
Name Role Password
app-01 normal jge5lfxtzhx42iff
doadmin primary wv78n3zpz42xezdk
`
databaseUserListResponse = `
{
"users": [
{
"name": "app-01",
"role": "normal",
"password": "jge5lfxtzhx42iff"
},
{
"name": "doadmin",
"role": "primary",
"password": "wv78n3zpz42xezdk"
}
]
}
`
)