-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_result.go
112 lines (104 loc) · 3.97 KB
/
test_result.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 wharfapi
import (
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/iver-wharf/wharf-api-client-go/v2/pkg/model/response"
)
// GetBuildAllTestResultDetailList fetches all the test result
// details for the specified build by invoking the HTTP request:
// GET /api/build/{buildId}/test-result/detail
//
// Added in wharf-api v5.0.0.
func (c *Client) GetBuildAllTestResultDetailList(buildID uint) (response.PaginatedTestResultDetails, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return response.PaginatedTestResultDetails{}, err
}
var details response.PaginatedTestResultDetails
path := fmt.Sprintf("/api/build/%d/test-result/detail", buildID)
err := c.getUnmarshal(path, nil, &details)
return details, err
}
// GetBuildAllTestResultSummaryList fetches all the test result
// summaries for the specified build by invoking the HTTP request:
// GET /api/build/{buildId}/test-result/summary
//
// Added in wharf-api v5.0.0.
func (c *Client) GetBuildAllTestResultSummaryList(buildID uint) (response.PaginatedTestResultSummaries, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return response.PaginatedTestResultSummaries{}, err
}
var summaries response.PaginatedTestResultSummaries
path := fmt.Sprintf("/api/build/%d/test-result/summary", buildID)
err := c.getUnmarshal(path, nil, &summaries)
return summaries, err
}
// GetBuildTestResultSummary fetches a test result summary by ID by
// invoking the HTTP request:
// GET /api/build/{buildId}/test-result/summary/{artifactId}
//
// Added in wharf-api v5.0.0.
func (c *Client) GetBuildTestResultSummary(buildID, artifactID uint) (response.TestResultSummary, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return response.TestResultSummary{}, err
}
var summary response.TestResultSummary
path := fmt.Sprintf("/api/build/%d/test-result/summary/%d", buildID, artifactID)
err := c.getUnmarshal(path, nil, &summary)
return summary, err
}
// GetBuildTestResultDetailList fetches all test result details for the specified
// test result summary by invoking the HTTP request:
// GET /api/build/{buildId}/test-result/summary/{artifactId}/detail
//
// Added in wharf-api v5.0.0.
func (c *Client) GetBuildTestResultDetailList(buildID, artifactID uint) (response.PaginatedTestResultDetails, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return response.PaginatedTestResultDetails{}, err
}
var details response.PaginatedTestResultDetails
path := fmt.Sprintf("/api/build/%d/test-result/summary/%d/detail", buildID, artifactID)
err := c.getUnmarshal(path, nil, &details)
return details, err
}
// GetBuildAllTestResultListSummary fetches the test result list summary of all tests for
// the specified build.
// GET /api/build/{buildId}/test-result/list-summary
//
// Added in wharf-api v5.0.0.
func (c *Client) GetBuildAllTestResultListSummary(buildID uint) (response.TestResultListSummary, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return response.TestResultListSummary{}, err
}
var listSummary response.TestResultListSummary
path := fmt.Sprintf("/api/build%d/test-result/list-summary", buildID)
err := c.getUnmarshal(path, nil, &listSummary)
return listSummary, err
}
// CreateBuildTestResult uploads a test result file (eg: "tests.trx") by
// invoking the HTTP request:
// POST /api/build/{buildId}/test-result
//
// Added in wharf-api v5.0.0.
func (c *Client) CreateBuildTestResult(buildID uint, fileName string, testResult io.Reader) ([]response.ArtifactMetadata, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return nil, err
}
path := fmt.Sprintf("/api/build/%d/test-result/", buildID)
body, err := c.uploadMultipart(http.MethodPost, path, map[string]file{
"files": {
fileName: fileName,
reader: testResult,
},
})
if err != nil {
return nil, err
}
defer body.Close()
var resp []response.ArtifactMetadata
if err := json.NewDecoder(body).Decode(&resp); err != nil {
return nil, err
}
return resp, nil
}