-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_test.go
64 lines (57 loc) · 1.3 KB
/
user_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
package ma_test
import (
"encoding/json"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/bzimmer/ma"
)
func TestUser(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/!authuser", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "testdata/user_cmac.json")
})
tests := []harness{
{
name: "authuser",
args: []string{"user"},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
run(t, &tt, mux, ma.CommandUser)
})
}
}
func TestUserError(t *testing.T) {
a := assert.New(t)
mux := http.NewServeMux()
mux.HandleFunc("/!authuser", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNotFound)
enc := json.NewEncoder(w)
a.NoError(enc.Encode(map[string]any{
"Response": map[string]any{
"Uri": "/api/v2/!authuser?_pretty=true",
"Locator": "User",
"LocatorType": "Object",
"UriDescription": "Node with the given id.",
"EndpointType": "Node"},
"Code": 404,
"Message": "Not Found",
}))
})
tests := []harness{
{
name: "authuser",
args: []string{"user"},
err: http.StatusText(http.StatusNotFound),
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
run(t, &tt, mux, ma.CommandUser)
})
}
}