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
/
beta_features_test.go
78 lines (61 loc) · 3.1 KB
/
beta_features_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
// 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 TestBetaFeaturesService_List(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/user/%d/beta_features", testUserId), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"beta_features":[{"id":1,"name":"dashboard","description":"Try the new personal Dashboard layout","enabled":true,"feedback_url":"https://github.com/travis-ci/beta-features/issues/5"}]}`)
})
features, _, err := client.BetaFeatures.List(context.Background(), testUserId)
if err != nil {
t.Errorf("BetaFeatures.List returned error: %v", err)
}
want := []*BetaFeature{{Id: Uint(1), Name: String("dashboard"), Description: String("Try the new personal Dashboard layout"), Enabled: Bool(true), FeedbackUrl: String("https://github.com/travis-ci/beta-features/issues/5")}}
if !reflect.DeepEqual(features, want) {
t.Errorf("BetaFeatures.List returned %+v, want %+v", features, want)
}
}
func TestBetaFeaturesService_Update(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/user/%d/beta_feature/1", testUserId), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
testBody(t, r, `{"enabled":true}`+"\n")
fmt.Fprint(w, `{"id":1,"name":"dashboard","description":"Try the new personal Dashboard layout","enabled":true,"feedback_url":"https://github.com/travis-ci/beta-features/issues/5"}`)
})
features, _, err := client.BetaFeatures.Update(context.Background(), testUserId, 1, true)
if err != nil {
t.Errorf("BetaFeatures.Update returned error: %v", err)
}
want := &BetaFeature{Id: Uint(1), Name: String("dashboard"), Description: String("Try the new personal Dashboard layout"), Enabled: Bool(true), FeedbackUrl: String("https://github.com/travis-ci/beta-features/issues/5")}
if !reflect.DeepEqual(features, want) {
t.Errorf("BetaFeatures.Update returned %+v, want %+v", features, want)
}
}
func TestBetaFeaturesService_Delete(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/user/%d/beta_feature/1", testUserId), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
fmt.Fprint(w, `{"id":1,"name":"dashboard","description":"Try the new personal Dashboard layout","enabled":true,"feedback_url":"https://github.com/travis-ci/beta-features/issues/5"}`)
})
features, _, err := client.BetaFeatures.Delete(context.Background(), testUserId, 1)
if err != nil {
t.Errorf("BetaFeatures.Delete returned error: %v", err)
}
want := &BetaFeature{Id: Uint(1), Name: String("dashboard"), Description: String("Try the new personal Dashboard layout"), Enabled: Bool(true), FeedbackUrl: String("https://github.com/travis-ci/beta-features/issues/5")}
if !reflect.DeepEqual(features, want) {
t.Errorf("BetaFeatures.Delete returned %+v, want %+v", features, want)
}
}