From 429262974df4f39fe6df48d5ac13c12b28d64953 Mon Sep 17 00:00:00 2001 From: Pranjali Bhardwaj Date: Fri, 15 May 2026 18:02:52 +0530 Subject: [PATCH] testing-n-typo Signed-off-by: Pranjali Bhardwaj --- cmd/cmd.go | 2 +- main.go | 2 +- pkg/connectors/microcks_client.go | 40 +++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 16df6b9..33b6733 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -22,7 +22,7 @@ import ( "github.com/spf13/cobra" ) -func NewCommad() *cobra.Command { +func NewCommand() *cobra.Command { var clientOpts connectors.ClientOptions diff --git a/main.go b/main.go index b595a37..860c31c 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - command := cmd.NewCommad() + command := cmd.NewCommand() if err := command.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/pkg/connectors/microcks_client.go b/pkg/connectors/microcks_client.go index f06b513..8ecd420 100644 --- a/pkg/connectors/microcks_client.go +++ b/pkg/connectors/microcks_client.go @@ -110,6 +110,17 @@ type microcksClient struct { httpClient *http.Client } +type testRequest struct { + ServiceID string `json:"serviceId"` + TestEndpoint string `json:"testEndpoint"` + RunnerType string `json:"runnerType"` + Timeout int64 `json:"timeout"` + SecretName string `json:"secretName,omitempty"` + FilteredOperations json.RawMessage `json:"filteredOperations,omitempty"` + OperationsHeaders json.RawMessage `json:"operationsHeaders,omitempty"` + OAuth2Context json.RawMessage `json:"oAuth2Context,omitempty"` +} + func NewClient(opts ClientOptions) (MicrocksClient, error) { var c microcksClient localCfg, err := config.ReadLocalConfig(opts.ConfigPath) @@ -323,28 +334,31 @@ func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string, rel := &url.URL{Path: "tests"} u := c.APIURL.ResolveReference(rel) - // Prepare an input string as body. - var input = "{" - input += ("\"serviceId\": \"" + serviceID + "\", ") - input += ("\"testEndpoint\": \"" + testEndpoint + "\", ") - input += ("\"runnerType\": \"" + runnerType + "\", ") - input += ("\"timeout\": " + strconv.FormatInt(timeout, 10)) - if len(secretName) > 0 { - input += (", \"secretName\": \"" + secretName + "\"") + // Prepare an input struct as body. + testReq := testRequest{ + ServiceID: serviceID, + TestEndpoint: testEndpoint, + RunnerType: runnerType, + Timeout: timeout, + SecretName: secretName, } + if len(filteredOperations) > 0 && ensureValidOperationsList(filteredOperations) { - input += (", \"filteredOperations\": " + filteredOperations) + testReq.FilteredOperations = json.RawMessage(filteredOperations) } if len(operationsHeaders) > 0 && ensureValidOperationsHeaders(operationsHeaders) { - input += (", \"operationsHeaders\": " + operationsHeaders) + testReq.OperationsHeaders = json.RawMessage(operationsHeaders) } if len(oAuth2Context) > 0 && ensureValidOAuth2Context(oAuth2Context) { - input += (", \"oAuth2Context\": " + oAuth2Context) + testReq.OAuth2Context = json.RawMessage(oAuth2Context) } - input += "}" + input, err := json.Marshal(testReq) + if err != nil { + return "", fmt.Errorf("failed to marshal test request: %w", err) + } - req, err := http.NewRequest("POST", u.String(), strings.NewReader(input)) + req, err := http.NewRequest("POST", u.String(), bytes.NewReader(input)) if err != nil { return "", err }