-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathresult.go
More file actions
115 lines (99 loc) · 4.33 KB
/
result.go
File metadata and controls
115 lines (99 loc) · 4.33 KB
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
/*
Package runscope implements a client library for the runscope api (https://api.blazemeter.com/api-monitoring/)
*/
package runscope
import "fmt"
type Result struct {
AssertionsDefined int `json:"assertions_defined"`
AssertionsFailed int `json:"assertions_failed"`
AssertionsPassed int `json:"assertions_passed"`
BucketKey string `json:"bucket_key"`
FinishedAt float64 `json:"finished_at"`
Region string `json:"region"`
RequestsExecuted int `json:"requests_executed"`
Result string `json:"result"`
ScriptsDefined int `json:"scripts_defined"`
ScriptsFailed int `json:"scripts_failed"`
ScriptsPassed int `json:"scripts_passed"`
StartedAt float64 `json:"started_at"`
TestRunID string `json:"test_run_id"`
TestRunURL string `json:"test_run_url"`
TestID string `json:"test_id"`
VariablesDefined int `json:"variables_defined"`
VariablesFailed int `json:"variables_failed"`
VariablesPassed int `json:"variables_passed"`
EnvironmentID string `json:"environment_id"`
EnvironmentName string `json:"environment_name"`
Requests []Request `json:"requests"`
}
// Request represents the result of a request made by a given test
type Request struct {
Result string `json:"result"`
URL string `json:"url"`
Method string `json:"method"`
AssertionsDefined int `json:"assertions_defined"`
AssertionsFailed int `json:"assertions_failed"`
AssertionsPassed int `json:"assertions_passed"`
ScriptsDefined int `json:"scripts_defined"`
ScriptsFailed int `json:"scripts_failed"`
ScriptsPassed int `json:"scripts_passed"`
VariablesDefined int `json:"variables_defined"`
VariablesFailed int `json:"variables_failed"`
VariablesPassed int `json:"variables_passed"`
Assertions []Assertion `json:"assertions"`
Scripts []Script `json:"scripts"`
Variables []Variable `json:"variables"`
}
// ListResults list all results for test. https://api.blazemeter.com/api-monitoring/#test-result-list
func (client *Client) ListResults(bucketKey string, testID string) ([]*Result, error) {
path := fmt.Sprintf("/buckets/%s/tests/%s/results", bucketKey, testID)
resource, err := client.readResource("[]result", testID, path)
if err != nil {
return nil, err
}
readResources, error := getResultsFromResponse(resource.Data)
if error != nil {
return nil, error
}
return readResources, nil
}
// ReadTestResult list details about an existing result. https://api.blazemeter.com/api-monitoring/#test-result-detail
func (client *Client) ReadTestResult(testRunID string, bucketKey string, testID string) (*Result, error) {
path := fmt.Sprintf("/buckets/%s/tests/%s/results/%s", bucketKey, testID, testRunID)
resource, error := client.readResource("result", testRunID, path)
if error != nil {
return nil, error
}
readTestResult, error := getResultFromResponse(resource.Data)
if error != nil {
return nil, error
}
return readTestResult, nil
}
// ReadTestLatestResult list details about an existing latest result. https://api.blazemeter.com/api-monitoring/#test-result-step-detail
func (client *Client) ReadTestLatestResult(testID string, bucketKey string) (*Result, error) {
return client.ReadTestResult("latest", bucketKey, testID)
}
// ReadTestStepResult list details about an existing result. https://api.blazemeter.com/api-monitoring/#test-result-step-detail
func (client *Client) ReadTestStepResult(testRunID string, bucketKey string, testID string, testStepID string) (*Result, error) {
path := fmt.Sprintf("/buckets/%s/tests/%s/results/%s/steps/%s", bucketKey, testID, testRunID, testStepID)
resource, error := client.readResource("result", testRunID, path)
if error != nil {
return nil, error
}
readTestResult, error := getResultFromResponse(resource.Data)
if error != nil {
return nil, error
}
return readTestResult, nil
}
func getResultsFromResponse(response interface{}) ([]*Result, error) {
var results []*Result
err := decode(&results, response)
return results, err
}
func getResultFromResponse(response interface{}) (*Result, error) {
testResult := new(Result)
err := decode(testResult, response)
return testResult, err
}