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
/
jobs_integration_test.go
108 lines (81 loc) · 2.53 KB
/
jobs_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
// 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"
)
const buildId = 420907933
func TestJobsService_Integration_Find(t *testing.T) {
opt := JobOption{Include: []string{"job.repository", "job.config"}}
job, res, err := integrationClient.Jobs.Find(context.TODO(), integrationJobId, &opt)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("#invalid http status: %s", res.Status)
}
if *job.Id != integrationJobId {
t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationBuildId, job.Id)
}
if job.Repository.IsMinimal() {
t.Fatal("repository is minimal representation")
}
if job.Commit.IsStandard() {
t.Fatal("commit is standard representation")
}
}
func TestJobsService_Integration_ListByBuild(t *testing.T) {
jobs, res, err := integrationClient.Jobs.ListByBuild(context.TODO(), buildId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("invalid http status: %s", res.Status)
}
if len(jobs) == 0 {
t.Fatalf("returned empty jobs")
}
}
func TestJobsService_Integration_List(t *testing.T) {
opt := &JobsOption{}
jobs, res, err := integrationClient.Jobs.List(context.TODO(), opt)
// This endpoint returns 500 as of 2019/04/17
t.Skip()
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("#invalid http status: %s", res.Status)
}
if len(jobs) == 0 {
t.Fatalf("returned empty jobs")
}
}
func TestJobsService_Integration_RestartAndCancel(t *testing.T) {
// Start a job
job, res, err := integrationClient.Jobs.Restart(context.TODO(), integrationJobId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusAccepted {
t.Fatalf("#invalid http status: %s", res.Status)
}
if *job.Id != integrationJobId {
t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationJobId, job.Id)
}
// Wait till the job has successfully processed
time.Sleep(2 * time.Second)
job, res, err = integrationClient.Jobs.Cancel(context.TODO(), integrationJobId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if *job.Id != integrationJobId {
t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationJobId, job.Id)
}
}