-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainers_test.go
More file actions
82 lines (74 loc) · 2.21 KB
/
Copy pathcontainers_test.go
File metadata and controls
82 lines (74 loc) · 2.21 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
package cinc
import (
"context"
"encoding/json"
"net/http"
"testing"
"github.com/tas50/cinc-api/internal/cinctest"
)
func TestContainers_List(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /organizations/o/containers", cinctest.Route{
Body: `{
"nodes":"http://x/containers/nodes",
"clients":"http://x/containers/clients"
}`,
})
c := newTestClient(t, srv.Server)
list, _, err := c.Containers.List(context.Background())
if err != nil {
t.Fatalf("List: %v", err)
}
if list["nodes"] == "" || list["clients"] == "" {
t.Fatalf("List = %+v", list)
}
}
func TestContainers_Get(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /organizations/o/containers/nodes", cinctest.Route{
Body: `{"containername":"nodes","containerpath":"nodes"}`,
})
c := newTestClient(t, srv.Server)
got, _, err := c.Containers.Get(context.Background(), "nodes")
if err != nil {
t.Fatalf("Get: %v", err)
}
if got.Name != "nodes" || got.Path != "nodes" {
t.Errorf("Container = %+v", got)
}
}
func TestContainers_Create(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("POST /organizations/o/containers", cinctest.Route{
Status: 201,
Body: `{"uri":"http://x/containers/widgets"}`,
Assert: func(t *testing.T, _ *http.Request, body []byte) {
var got map[string]string
json.Unmarshal(body, &got)
if got["containername"] != "widgets" || got["containerpath"] != "widgets" {
t.Errorf("POST body = %v", got)
}
},
})
c := newTestClient(t, srv.Server)
if _, err := c.Containers.Create(context.Background(), "widgets"); err != nil {
t.Fatalf("Create: %v", err)
}
}
func TestContainers_Delete(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("DELETE /organizations/o/containers/widgets", cinctest.Route{Body: `{}`})
c := newTestClient(t, srv.Server)
if _, err := c.Containers.Delete(context.Background(), "widgets"); err != nil {
t.Fatalf("Delete: %v", err)
}
}
func TestContainers_NotFound(t *testing.T) {
srv := cinctest.New(t)
srv.Handle("GET /organizations/o/containers/missing",
cinctest.Route{Status: 404, Body: `{"error":["not found"]}`})
c := newTestClient(t, srv.Server)
if _, _, err := c.Containers.Get(context.Background(), "missing"); err == nil {
t.Fatal("expected 404")
}
}