forked from shuheiktgw/go-travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.go
83 lines (65 loc) · 2.62 KB
/
users_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
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package travis
import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
)
const testUserId = 4321
func TestUserService_Current(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"include": "user.repositories,user.installation,user.emails"})
fmt.Fprint(w, `{"id":1,"login":"shuheiktgw","name":"shuheiktgw","github_id":1}`)
})
opt := UserOption{Include: []string{"user.repositories", "user.installation", "user.emails"}}
repo, _, err := client.User.Current(context.Background(), &opt)
if err != nil {
t.Errorf("UserService.Current returned error: %v", err)
}
want := &User{Id: Uint(1), Login: String("shuheiktgw"), Name: String("shuheiktgw"), GithubId: Uint(1)}
if !reflect.DeepEqual(repo, want) {
t.Errorf("UserService.Current returned %+v, want %+v", repo, want)
}
}
func TestUserService_Find(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/user/%d", testUserId), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"include": "user.repositories,user.installation,user.emails"})
fmt.Fprint(w, `{"id":1,"login":"shuheiktgw","name":"shuheiktgw","github_id":1}`)
})
opt := UserOption{Include: []string{"user.repositories", "user.installation", "user.emails"}}
repo, _, err := client.User.Find(context.Background(), testUserId, &opt)
if err != nil {
t.Errorf("UserService.Find returned error: %v", err)
}
want := &User{Id: Uint(1), Login: String("shuheiktgw"), Name: String("shuheiktgw"), GithubId: Uint(1)}
if !reflect.DeepEqual(repo, want) {
t.Errorf("UserService.Find returned %+v, want %+v", repo, want)
}
}
func TestUserService_Sync(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/user/%d/sync", testUserId), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"id":1,"login":"shuheiktgw","name":"shuheiktgw","github_id":1}`)
})
repo, _, err := client.User.Sync(context.Background(), testUserId)
if err != nil {
t.Errorf("UserService.Sync returned error: %v", err)
}
want := &User{Id: Uint(1), Login: String("shuheiktgw"), Name: String("shuheiktgw"), GithubId: Uint(1)}
if !reflect.DeepEqual(repo, want) {
t.Errorf("UserService.Sync returned %+v, want %+v", repo, want)
}
}