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
/
active_test.go
63 lines (50 loc) · 2 KB
/
active_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
// 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 testOwner = "shuheiktgw"
const testGitHubId = 83472489
func TestActiveService_FindByOwner(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/owner/%s/active", testOwner), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"include": "active.builds"})
fmt.Fprint(w, `{"builds": [{"id":1,"number":"1","state":"created","duration":10}]}`)
})
opt := ActiveOption{Include: []string{"active.builds"}}
builds, _, err := client.Active.FindByOwner(context.Background(), testOwner, &opt)
if err != nil {
t.Errorf("Active.FindByOwner returned error: %v", err)
}
want := []*Build{{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Int64(10)}}
if !reflect.DeepEqual(builds, want) {
t.Errorf("Active.FindByOwner returned %+v, want %+v", builds, want)
}
}
func TestActiveService_FindByGitHubId(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/owner/github_id/%d/active", testGitHubId), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"include": "active.builds"})
fmt.Fprint(w, `{"builds": [{"id":1,"number":"1","state":"created","duration":10}]}`)
})
opt := ActiveOption{Include: []string{"active.builds"}}
builds, _, err := client.Active.FindByGitHubId(context.Background(), testGitHubId, &opt)
if err != nil {
t.Errorf("Active.FindByGitHubId returned error: %v", err)
}
want := []*Build{{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Int64(10)}}
if !reflect.DeepEqual(builds, want) {
t.Errorf("Active.FindByGitHubId returned %+v, want %+v", builds, want)
}
}