-
Notifications
You must be signed in to change notification settings - Fork 59
/
test_runs_test.go
124 lines (106 loc) · 4.72 KB
/
test_runs_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
package buildkite
import (
"context"
"fmt"
"net/http"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestTestRunsService_List(t *testing.T) {
t.Parallel()
server, client, teardown := newMockServerAndClient(t)
t.Cleanup(teardown)
server.HandleFunc("/v2/analytics/organizations/my-great-org/suites/suite-example/runs", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w,
`
[
{
"id": "3c90a8ad-8e86-4e78-87b4-acae5e808de4",
"url": "https://api.buildkite.com/v2/analytics/organizations/my-great-org/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
"web_url": "https://buildkite.com/organizations/my-great-org/analytics/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
"branch": "main",
"commit_sha": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"created_at": "2023-05-20T10:25:50.264Z"
},
{
"id": "70fe7e45-c9e4-446b-95e3-c50d61519b87",
"url": "https://api.buildkite.com/v2/analytics/organizations/my-great-org/suites/suite-example/runs/70fe7e45-c9e4-446b-95e3-c50d61519b87",
"web_url": "https://buildkite.com/organizations/my-great-org/analytics/suites/suite-example/runs/70fe7e45-c9e4-446b-95e3-c50d61519b87",
"branch": "main",
"commit_sha": "109f4b3c50d7b0df729d299bc6f8e9ef9066971f",
"created_at": "2023-05-20T10:52:22.254Z"
}
]`)
})
runs, _, err := client.TestRuns.List(context.Background(), "my-great-org", "suite-example", nil)
if err != nil {
t.Errorf("TestSuites.List returned error: %v", err)
}
// Create Time instances from strings in BuildKiteDateFormat friendly format
parsedTime1 := must(time.Parse(BuildKiteDateFormat, "2023-05-20T10:25:50.264Z"))
parsedTime2 := must(time.Parse(BuildKiteDateFormat, "2023-05-20T10:52:22.254Z"))
if err != nil {
t.Errorf("TestSuites.List time.Parse error: %v", err)
}
want := []TestRun{
{
ID: "3c90a8ad-8e86-4e78-87b4-acae5e808de4",
URL: "https://api.buildkite.com/v2/analytics/organizations/my-great-org/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
WebURL: "https://buildkite.com/organizations/my-great-org/analytics/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
Branch: "main",
CommitSHA: "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
CreatedAt: NewTimestamp(parsedTime1),
},
{
ID: "70fe7e45-c9e4-446b-95e3-c50d61519b87",
URL: "https://api.buildkite.com/v2/analytics/organizations/my-great-org/suites/suite-example/runs/70fe7e45-c9e4-446b-95e3-c50d61519b87",
WebURL: "https://buildkite.com/organizations/my-great-org/analytics/suites/suite-example/runs/70fe7e45-c9e4-446b-95e3-c50d61519b87",
Branch: "main",
CommitSHA: "109f4b3c50d7b0df729d299bc6f8e9ef9066971f",
CreatedAt: NewTimestamp(parsedTime2),
},
}
if diff := cmp.Diff(runs, want); diff != "" {
t.Errorf("TestRuns.List diff: (-got +want)\n%s", diff)
}
}
func TestTestRunsService_Get(t *testing.T) {
t.Parallel()
server, client, teardown := newMockServerAndClient(t)
t.Cleanup(teardown)
server.HandleFunc("/v2/analytics/organizations/my-great-org/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w,
`
{
"id": "3c90a8ad-8e86-4e78-87b4-acae5e808de4",
"url": "https://api.buildkite.com/v2/analytics/organizations/my-great-org/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
"web_url": "https://buildkite.com/organizations/my-great-org/analytics/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
"branch": "main",
"commit_sha": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"created_at": "2023-05-20T10:25:50.264Z"
}`)
})
run, _, err := client.TestRuns.Get(context.Background(), "my-great-org", "suite-example", "3c90a8ad-8e86-4e78-87b4-acae5e808de4")
if err != nil {
t.Errorf("TestSuites.Get returned error: %v", err)
}
// Create Time instance from string in BuildKiteDateFormat friendly format
parsedTime, err := time.Parse(BuildKiteDateFormat, "2023-05-20T10:25:50.264Z")
if err != nil {
t.Errorf("TestSuites.Get time.Parse error: %v", err)
}
want := TestRun{
ID: "3c90a8ad-8e86-4e78-87b4-acae5e808de4",
URL: "https://api.buildkite.com/v2/analytics/organizations/my-great-org/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
WebURL: "https://buildkite.com/organizations/my-great-org/analytics/suites/suite-example/runs/3c90a8ad-8e86-4e78-87b4-acae5e808de4",
Branch: "main",
CommitSHA: "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
CreatedAt: NewTimestamp(parsedTime),
}
if diff := cmp.Diff(run, want); diff != "" {
t.Errorf("TestRuns.Get diff: (-got +want)\n%s", diff)
}
}