@@ -2,6 +2,7 @@ package connectors
22
33import (
44 "encoding/json"
5+ "fmt"
56 "io/ioutil"
67 "net/http"
78 "net/url"
@@ -14,7 +15,7 @@ import (
1415type MicrocksClient interface {
1516 GetKeycloakURL () (string , error )
1617 SetOAuthToken (oauthToken string )
17- CreateTestResult (serviceID string , testEndpoint string , runnerType string ) (string , error )
18+ CreateTestResult (serviceID string , testEndpoint string , runnerType string , operationsHeaders string ) (string , error )
1819 GetTestResult (testResultID string ) (* TestResultSummary , error )
1920}
2021
@@ -31,6 +32,12 @@ type TestResultSummary struct {
3132 InProgress bool `json:"inProgress"`
3233}
3334
35+ // HeaderDTO represents an operation header passed for Test
36+ type HeaderDTO struct {
37+ Name string `json:"name"`
38+ Values string `json:"values"`
39+ }
40+
3441type microcksClient struct {
3542 APIURL * url.URL
3643 OAuthToken string
@@ -100,7 +107,7 @@ func (c *microcksClient) SetOAuthToken(oauthToken string) {
100107 c .OAuthToken = oauthToken
101108}
102109
103- func (c * microcksClient ) CreateTestResult (serviceID string , testEndpoint string , runnerType string ) (string , error ) {
110+ func (c * microcksClient ) CreateTestResult (serviceID string , testEndpoint string , runnerType string , operationsHeaders string ) (string , error ) {
104111 // Ensure we have a correct URL.
105112 rel := & url.URL {Path : "tests" }
106113 u := c .APIURL .ResolveReference (rel )
@@ -110,6 +117,10 @@ func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string,
110117 input += ("\" serviceId\" : \" " + serviceID + "\" , " )
111118 input += ("\" testEndpoint\" : \" " + testEndpoint + "\" , " )
112119 input += ("\" runnerType\" : \" " + runnerType + "\" " )
120+ if len (operationsHeaders ) > 0 && ensureValid (operationsHeaders ) {
121+ input += (", \" operationsHeaders\" : " + operationsHeaders )
122+ }
123+
113124 input += "}"
114125
115126 req , err := http .NewRequest ("POST" , u .String (), strings .NewReader (input ))
@@ -122,7 +133,7 @@ func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string,
122133 req .Header .Set ("Authorization" , "Bearer " + c .OAuthToken )
123134
124135 // Dump request if verbose required.
125- config .DumpRequestIfRequired ("Microcks for creating test" , req , false )
136+ config .DumpRequestIfRequired ("Microcks for creating test" , req , true )
126137
127138 resp , err := c .httpClient .Do (req )
128139 if err != nil {
@@ -182,3 +193,14 @@ func (c *microcksClient) GetTestResult(testResultID string) (*TestResultSummary,
182193
183194 return & result , err
184195}
196+
197+ func ensureValid (operationsHeaders string ) bool {
198+ // Unmarshal using a generic interface
199+ var headers = map [string ][]HeaderDTO {}
200+ err := json .Unmarshal ([]byte (operationsHeaders ), & headers )
201+ if err != nil {
202+ fmt .Println ("Error parsing JSON in operationsHeaders: " , err )
203+ return false
204+ }
205+ return true
206+ }
0 commit comments