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
/
builds_integration_test.go
157 lines (123 loc) · 3.88 KB
/
builds_integration_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// 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.
// +build integration
package travis
import (
"context"
"net/http"
"testing"
"time"
)
func TestBuildService_Integration_Find(t *testing.T) {
build, res, err := integrationClient.Builds.Find(context.TODO(), integrationBuildId, &BuildOption{Include: []string{"build.commit"}})
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("invalid http status: %s", res.Status)
}
if *build.Id != integrationBuildId {
t.Fatalf("unexpected build returned: want build id %d: got build id %d", integrationBuildId, build.Id)
}
}
func TestBuildsService_Integration_List(t *testing.T) {
cases := []*BuildsOption{
{},
{Limit: 1},
{SortBy: "id"},
{Offset: 0},
{Include: []string{"build.branch", "build.commit"}},
}
for i, opt := range cases {
builds, res, err := integrationClient.Builds.List(context.TODO(), opt)
if err != nil {
t.Fatalf("#%d unexpected error occured: %s", i, err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("#%d invalid http status: %s", i, res.Status)
}
if len(builds) == 0 {
t.Fatalf("#%d returned empty builds", i)
}
time.Sleep(5 * time.Millisecond)
}
}
func TestBuildsService_Integration_ListByRepoId(t *testing.T) {
cases := []*BuildsByRepoOption{
{},
{Limit: 1},
{SortBy: "id"},
{Offset: 0},
{State: []string{BuildStateCanceled}},
{PreviousState: []string{BuildStatePassed}},
{EventType: []string{BuildEventTypePush}},
{CreatedBy: []string{"shuheiktgwtest"}},
{BranchName: []string{"master", "test"}},
{Include: []string{"build.branch", "build.commit"}},
}
for i, opt := range cases {
builds, res, err := integrationClient.Builds.ListByRepoId(context.TODO(), integrationRepoId, opt)
if err != nil {
t.Fatalf("#%d unexpected error occured: %s", i, err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("#%d invalid http status: %s", i, res.Status)
}
if len(builds) == 0 {
t.Fatalf("#%d returned empty builds", i)
}
time.Sleep(5 * time.Millisecond)
}
}
func TestBuildsService_Integration_ListByRepoSlug(t *testing.T) {
cases := []*BuildsByRepoOption{
{},
{Limit: 1},
{SortBy: "id"},
{Offset: 0},
{State: []string{BuildStateCanceled}},
{PreviousState: []string{BuildStatePassed}},
{EventType: []string{BuildEventTypePush}},
{CreatedBy: []string{"shuheiktgwtest"}},
{Include: []string{"build.branch", "build.commit"}},
}
for i, opt := range cases {
builds, res, err := integrationClient.Builds.ListByRepoSlug(context.TODO(), integrationRepoSlug, opt)
if err != nil {
t.Fatalf("#%d unexpected error occured: %s", i, err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("#%d invalid http status: %s", i, res.Status)
}
if len(builds) == 0 {
t.Fatalf("#%d returned empty builds", i)
}
time.Sleep(5 * time.Millisecond)
}
}
func TestBuildService_Integration_RestartAndCancel(t *testing.T) {
build, res, err := integrationClient.Builds.Restart(context.TODO(), integrationBuildId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusAccepted {
t.Fatalf("#invalid http status: %s", res.Status)
}
if *build.Id != integrationBuildId {
t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationBuildId, build.Id)
}
// Wait till the build has successfully processed
time.Sleep(2 * time.Second)
build, res, err = integrationClient.Builds.Cancel(context.TODO(), integrationBuildId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusAccepted {
t.Fatalf("invalid http status: %s", res.Status)
}
if *build.Id != integrationBuildId {
t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationBuildId, build.Id)
}
}