-
Notifications
You must be signed in to change notification settings - Fork 59
/
flaky_tests_test.go
82 lines (73 loc) · 2.89 KB
/
flaky_tests_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
package buildkite
import (
"context"
"fmt"
"net/http"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestFlakyTestsService_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/flaky-tests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w,
`
[
{
"id": "a915535c-a8f1-4e1a-bd6a-a5589e09f349",
"web_url": "https://buildkite.com/organizations/my_great_org/analytics/suites/suite-example/tests/a915535c-a8f1-4e1a-bd6a-a5589e09f349",
"scope": "User#email",
"name": "TestExample1_Create",
"location": "./spec/models/text_example.rb:55",
"file_name": "./spec/models/text_example.rb",
"instances": 1,
"most_recent_instance_at": "2023-05-19T20:00:02.223Z"
},
{
"id": "01867216-8478-7fde-a55a-0300f88bb49b",
"web_url": "https://buildkite.com/organizations/my_great_org/analytics/suites/suite-example/tests/01867216-8478-7fde-a55a-0300f88bb49b",
"scope": "User#email",
"name": "TestExample1_Delete",
"location": "./spec/models/text_example.rb:102",
"file_name": "./spec/models/text_example.rb",
"instances": 2,
"most_recent_instance_at": "2023-07-10T13:14:03.214Z"
}
]`)
})
flakyTests, _, err := client.FlakyTests.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-19T20:00:02.223Z"))
parsedTime2 := must(time.Parse(BuildKiteDateFormat, "2023-07-10T13:14:03.214Z"))
want := []FlakyTest{
{
ID: "a915535c-a8f1-4e1a-bd6a-a5589e09f349",
WebURL: "https://buildkite.com/organizations/my_great_org/analytics/suites/suite-example/tests/a915535c-a8f1-4e1a-bd6a-a5589e09f349",
Scope: "User#email",
Name: "TestExample1_Create",
Location: "./spec/models/text_example.rb:55",
FileName: "./spec/models/text_example.rb",
Instances: 1,
MostRecentInstanceAt: NewTimestamp(parsedTime1),
},
{
ID: "01867216-8478-7fde-a55a-0300f88bb49b",
WebURL: "https://buildkite.com/organizations/my_great_org/analytics/suites/suite-example/tests/01867216-8478-7fde-a55a-0300f88bb49b",
Scope: "User#email",
Name: "TestExample1_Delete",
Location: "./spec/models/text_example.rb:102",
FileName: "./spec/models/text_example.rb",
Instances: 2,
MostRecentInstanceAt: NewTimestamp(parsedTime2),
},
}
if diff := cmp.Diff(flakyTests, want); diff != "" {
t.Errorf("FlakyTests.List diff: (-got +want)\n%s", diff)
}
}