-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprincipals_test.go
More file actions
47 lines (42 loc) · 1.16 KB
/
Copy pathprincipals_test.go
File metadata and controls
47 lines (42 loc) · 1.16 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
package cinc
import (
"context"
"testing"
"github.com/tas50/cinc-api/internal/cinctest"
)
func TestPrincipals_Get(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /organizations/o/principals/normal_user", cinctest.Route{
Body: `{"principals":[{
"name":"normal_user",
"type":"user",
"public_key":"-----BEGIN PUBLIC KEY-----...",
"authz_id":"eca5fdd45a8b4bacc04bbc6e37a340be",
"org_member":false
}]}`,
})
c := newTestClient(t, srv.Server)
ps, _, err := c.Principals.Get(context.Background(), "normal_user")
if err != nil {
t.Fatalf("Get: %v", err)
}
if len(ps) != 1 {
t.Fatalf("Get returned %d principals", len(ps))
}
p := ps[0]
if p.Name != "normal_user" || p.Type != "user" || p.OrgMember {
t.Fatalf("principal = %+v", p)
}
if p.PublicKey == "" || p.AuthzID == "" {
t.Fatalf("principal = %+v", p)
}
}
func TestPrincipals_GetNotFound(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /organizations/o/principals/ghost",
cinctest.Route{Status: 404, Body: `{"error":["not found"]}`})
c := newTestClient(t, srv.Server)
if _, _, err := c.Principals.Get(context.Background(), "ghost"); err == nil {
t.Fatal("expected 404")
}
}