-
Notifications
You must be signed in to change notification settings - Fork 59
/
test_suites.go
112 lines (92 loc) · 3.02 KB
/
test_suites.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
package buildkite
import (
"context"
"fmt"
)
// TestSuitesService handles communication with the test suite related
// methods of the Buildkite Test Analytics API.
//
// Buildkite API docs: https://buildkite.com/docs/apis/rest-api/analytics/suites
type TestSuitesService struct {
client *Client
}
type TestSuiteCreate struct {
Name string `json:"name"`
DefaultBranch string `json:"default_branch,omitempty"`
ShowAPIToken bool `json:"show_api_token"`
TeamUUIDs []string `json:"team_ids,omitempty"`
}
type TestSuite struct {
ID string `json:"id,omitempty"`
GraphQLID string `json:"graphql_id,omitempty"`
Slug string `json:"slug,omitempty"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
WebURL string `json:"web_url,omitempty"`
DefaultBranch string `json:"default_branch,omitempty"`
}
type TestSuiteListOptions struct{ ListOptions }
func (tss *TestSuitesService) List(ctx context.Context, org string, opt *TestSuiteListOptions) ([]TestSuite, *Response, error) {
u := fmt.Sprintf("v2/analytics/organizations/%s/suites", org)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := tss.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var testSuites []TestSuite
resp, err := tss.client.Do(req, &testSuites)
if err != nil {
return nil, resp, err
}
return testSuites, resp, err
}
func (tss *TestSuitesService) Get(ctx context.Context, org, slug string) (TestSuite, *Response, error) {
u := fmt.Sprintf("v2/analytics/organizations/%s/suites/%s", org, slug)
req, err := tss.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return TestSuite{}, nil, err
}
var testSuite TestSuite
resp, err := tss.client.Do(req, &testSuite)
if err != nil {
return TestSuite{}, resp, err
}
return testSuite, resp, err
}
func (tss *TestSuitesService) Create(ctx context.Context, org string, ts TestSuiteCreate) (TestSuite, *Response, error) {
u := fmt.Sprintf("v2/analytics/organizations/%s/suites", org)
req, err := tss.client.NewRequest(ctx, "POST", u, ts)
if err != nil {
return TestSuite{}, nil, err
}
var testSuite TestSuite
resp, err := tss.client.Do(req, &testSuite)
if err != nil {
return TestSuite{}, resp, err
}
return testSuite, resp, err
}
func (tss *TestSuitesService) Update(ctx context.Context, org, slug string, ts TestSuite) (TestSuite, *Response, error) {
u := fmt.Sprintf("v2/analytics/organizations/%s/suites/%s", org, slug)
req, err := tss.client.NewRequest(ctx, "PATCH", u, ts)
if err != nil {
return TestSuite{}, nil, nil
}
var out TestSuite
resp, err := tss.client.Do(req, &out)
if err != nil {
return TestSuite{}, resp, err
}
return out, resp, err
}
func (tss *TestSuitesService) Delete(ctx context.Context, org, slug string) (*Response, error) {
u := fmt.Sprintf("v2/analytics/organizations/%s/suites/%s", org, slug)
req, err := tss.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
}
return tss.client.Do(req, nil)
}