forked from shuheiktgw/go-travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preferences_test.go
80 lines (62 loc) · 2.31 KB
/
preferences_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
// 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 testPreferenceName = "builds_email"
func TestPreferencesService_Find(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/preference/%s", testPreferenceName), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"name":"builds_email","value":true}`)
})
preference, _, err := client.Preferences.Find(context.Background(), testPreferenceName)
if err != nil {
t.Errorf("Preference.Find returned error: %v", err)
}
want := &Preference{Name: String("builds_email"), Value: true}
if !reflect.DeepEqual(preference, want) {
t.Errorf("Preference.Find returned %+v, want %+v", preference, want)
}
}
func TestPreferencesService_List(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/preferences", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"preferences": [{"name":"builds_email","value":true}]}`)
})
preferences, _, err := client.Preferences.List(context.Background())
if err != nil {
t.Errorf("Preferences.Find returned error: %v", err)
}
want := []*Preference{{Name: String("builds_email"), Value: true}}
if !reflect.DeepEqual(preferences, want) {
t.Errorf("Preferences.Find returned %+v, want %+v", preferences, want)
}
}
func TestPreferencesService_Update(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/preference/%s", testPreferenceName), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
testBody(t, r, `{"name":"builds_email","value":false}`+"\n")
fmt.Fprint(w, `{"name":"builds_email","value":false}`)
})
preference, _, err := client.Preferences.Update(context.Background(), &PreferenceBody{Name: "builds_email", Value: false})
if err != nil {
t.Errorf("Preference.Update returned error: %v", err)
}
want := &Preference{Name: String("builds_email"), Value: false}
if !reflect.DeepEqual(preference, want) {
t.Errorf("Preference.Update returned %+v, want %+v", preference, want)
}
}