-
Notifications
You must be signed in to change notification settings - Fork 59
/
organizations_test.go
54 lines (42 loc) · 1.3 KB
/
organizations_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
package buildkite
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestOrganizationsService_List(t *testing.T) {
t.Parallel()
server, client, teardown := newMockServerAndClient(t)
t.Cleanup(teardown)
server.HandleFunc("/v2/organizations", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":"123"},{"id":"1234"}]`)
})
orgs, _, err := client.Organizations.List(context.Background(), nil)
if err != nil {
t.Errorf("Organizations.List returned error: %v", err)
}
want := []Organization{{ID: "123"}, {ID: "1234"}}
if diff := cmp.Diff(orgs, want); diff != "" {
t.Errorf("Organizations.List diff: (-got +want)\n%s", diff)
}
}
func TestOrganizationsService_Get(t *testing.T) {
t.Parallel()
server, client, teardown := newMockServerAndClient(t)
t.Cleanup(teardown)
server.HandleFunc("/v2/organizations/babelstoemp", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":"123"}`)
})
org, _, err := client.Organizations.Get(context.Background(), "babelstoemp")
if err != nil {
t.Errorf("Organizations.Get returned error: %v", err)
}
want := Organization{ID: "123"}
if diff := cmp.Diff(org, want); diff != "" {
t.Errorf("Organizations.Get diff: (-got +want)\n%s", diff)
}
}