This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
settings_test.go
102 lines (80 loc) · 3.43 KB
/
settings_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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"
)
func TestSettingsService_FindByRepoId(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%d/setting/%s", testRepoId, BuildsOnlyWithTravisYmlSetting), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"name":"builds_only_with_travis_yml","value":false}`)
})
setting, _, err := client.Settings.FindByRepoId(context.Background(), testRepoId, BuildsOnlyWithTravisYmlSetting)
if err != nil {
t.Errorf("Settings.FindByRepoId returned error: %v", err)
}
want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: false}
if !reflect.DeepEqual(setting, want) {
t.Errorf("Settings.FindByRepoId returned %+v, want %+v", setting, want)
}
}
func TestSettingsService_FindByRepoSlug(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s/setting/%s", testRepoSlug, BuildsOnlyWithTravisYmlSetting), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"name":"builds_only_with_travis_yml","value":false}`)
})
setting, _, err := client.Settings.FindByRepoSlug(context.Background(), testRepoSlug, BuildsOnlyWithTravisYmlSetting)
if err != nil {
t.Errorf("Settings.FindByRepoSlug returned error: %v", err)
}
want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: false}
if !reflect.DeepEqual(setting, want) {
t.Errorf("Settings.FindByRepoSlug returned %+v, want %+v", setting, want)
}
}
func TestSettingsService_UpdateByRepoId(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%d/setting/%s", testRepoId, BuildsOnlyWithTravisYmlSetting), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
testBody(t, r, `{"setting.value":true}`+"\n")
fmt.Fprint(w, `{"name":"builds_only_with_travis_yml","value":true}`)
})
s := SettingBody{Name: BuildsOnlyWithTravisYmlSetting, Value: true}
setting, _, err := client.Settings.UpdateByRepoId(context.Background(), testRepoId, &s)
if err != nil {
t.Errorf("Settings.UpdateByRepoId returned error: %v", err)
}
want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: true}
if !reflect.DeepEqual(setting, want) {
t.Errorf("Settings.UpdateByRepoId returned %+v, want %+v", setting, want)
}
}
func TestSettingsService_UpdateByRepoSlug(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s/setting/%s", testRepoSlug, BuildsOnlyWithTravisYmlSetting), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
testBody(t, r, `{"setting.value":true}`+"\n")
fmt.Fprint(w, `{"name":"builds_only_with_travis_yml","value":true}`)
})
s := SettingBody{Name: BuildsOnlyWithTravisYmlSetting, Value: true}
setting, _, err := client.Settings.UpdateByRepoSlug(context.Background(), testRepoSlug, &s)
if err != nil {
t.Errorf("Settings.UpdateByRepoSlug returned error: %v", err)
}
want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: true}
if !reflect.DeepEqual(setting, want) {
t.Errorf("Settings.UpdateByRepoSlug returned %+v, want %+v", setting, want)
}
}