Skip to content

Commit 2969a4c

Browse files
committed
feat(connectors): add GetFullTestResult with per-operation test detail
Signed-off-by: caesarsage <destinyerhabor6@gmail.com>
1 parent 7f9da4d commit 2969a4c

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

pkg/connectors/microcks_client.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type MicrocksClient interface {
5050
SetOAuthToken(oauthToken string)
5151
CreateTestResult(serviceID string, testEndpoint string, runnerType string, secretName string, timeout int64, filteredOperations string, operationsHeaders string, oAuth2Context string) (string, error)
5252
GetTestResult(testResultID string) (*TestResultSummary, error)
53+
GetFullTestResult(testResultID string) (*TestResult, error)
5354
UploadArtifact(specificationFilePath string, mainArtifact bool) (string, error)
5455
DownloadArtifact(artifactURL string, mainArtifact bool, secret string) (string, error)
5556
}
@@ -67,6 +68,37 @@ type TestResultSummary struct {
6768
InProgress bool `json:"inProgress"`
6869
}
6970

71+
// TestResult represents a full Microcks TestResult including per-operation detail.
72+
type TestResult struct {
73+
ID string `json:"id"`
74+
Version int32 `json:"version"`
75+
TestNumber int32 `json:"testNumber"`
76+
TestDate int64 `json:"testDate"`
77+
TestedEndpoint string `json:"testedEndpoint"`
78+
ServiceID string `json:"serviceId"`
79+
ElapsedTime int32 `json:"elapsedTime"`
80+
Success bool `json:"success"`
81+
InProgress bool `json:"inProgress"`
82+
TestCaseResults []TestCaseResult `json:"testCaseResults"`
83+
}
84+
85+
// TestCaseResult is the result for a single operation within a TestResult.
86+
type TestCaseResult struct {
87+
Success bool `json:"success"`
88+
ElapsedTime int32 `json:"elapsedTime"`
89+
OperationName string `json:"operationName"`
90+
TestStepResults []TestStepResult `json:"testStepResults"`
91+
}
92+
93+
// TestStepResult is the result for a single request/message within a TestCaseResult.
94+
type TestStepResult struct {
95+
Success bool `json:"success"`
96+
ElapsedTime int32 `json:"elapsedTime"`
97+
RequestName string `json:"requestName"`
98+
EventMessageName string `json:"eventMessageName"`
99+
Message string `json:"message"`
100+
}
101+
70102
// HeaderDTO represents an operation header passed for Test
71103
type HeaderDTO struct {
72104
Name string `json:"name"`
@@ -436,6 +468,43 @@ func (c *microcksClient) GetTestResult(testResultID string) (*TestResultSummary,
436468
return &result, nil
437469
}
438470

471+
// GetFullTestResult fetches the complete TestResult including per-operation
472+
// (testCaseResults) detail, used by the richer --output formatters.
473+
func (c *microcksClient) GetFullTestResult(testResultID string) (*TestResult, error) {
474+
rel := &url.URL{Path: "tests/" + testResultID}
475+
u := c.APIURL.ResolveReference(rel)
476+
477+
req, err := http.NewRequest("GET", u.String(), nil)
478+
if err != nil {
479+
return nil, err
480+
}
481+
482+
req.Header.Set("Accept", "application/json")
483+
req.Header.Set("Authorization", "Bearer "+c.AuthToken)
484+
485+
config.DumpRequestIfRequired("Microcks for getting full test result", req, false)
486+
487+
resp, err := c.httpClient.Do(req)
488+
if err != nil {
489+
return nil, err
490+
}
491+
defer resp.Body.Close()
492+
493+
config.DumpResponseIfRequired("Microcks for getting full test result", resp, true)
494+
495+
body, err := io.ReadAll(resp.Body)
496+
if err != nil {
497+
return nil, err
498+
}
499+
500+
result := TestResult{}
501+
if err := json.Unmarshal(body, &result); err != nil {
502+
return nil, fmt.Errorf("failed to parse full test result response: %w", err)
503+
}
504+
505+
return &result, nil
506+
}
507+
439508
func (c *microcksClient) UploadArtifact(specificationFilePath string, mainArtifact bool) (string, error) {
440509
// Ensure file exists on fs.
441510
file, err := os.Open(specificationFilePath)

0 commit comments

Comments
 (0)