From 0584acfcf7e0db55602aea6497fa9032e6055064 Mon Sep 17 00:00:00 2001 From: Manar Elhabbal Date: Sun, 24 May 2026 03:15:17 +0300 Subject: [PATCH 1/2] feat: Automatically open Microcks test result in the browser Signed-off-by: Manar Elhabbal --- cmd/test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/test.go b/cmd/test.go index ca14a835..b8ca3fa3 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -25,6 +25,7 @@ import ( "github.com/microcks/microcks-cli/pkg/config" "github.com/microcks/microcks-cli/pkg/connectors" "github.com/microcks/microcks-cli/pkg/errors" + "github.com/microcks/microcks-cli/pkg/util" "github.com/spf13/cobra" ) @@ -39,6 +40,7 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { filteredOperations string operationsHeaders string oAuth2Context string + launchBrowser bool ) var testCmd = &cobra.Command{ @@ -189,7 +191,9 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { time.Sleep(2 * time.Second) } - fmt.Printf("Full TestResult details are available here: %s/#/tests/%s \n", serverAddr, testResultID) + testResultURL := fmt.Sprintf("%s/#/tests/%s", serverAddr, testResultID) + fmt.Printf("Full TestResult details are available here: %s \n", testResultURL) + util.LaunchBrowser(testResultURL, launchBrowser) if !success { os.Exit(1) @@ -202,6 +206,7 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { testCmd.Flags().StringVar(&filteredOperations, "filteredOperations", "", "List of operations to launch a test for") testCmd.Flags().StringVar(&operationsHeaders, "operationsHeaders", "", "Override of operations headers as JSON string") testCmd.Flags().StringVar(&oAuth2Context, "oAuth2Context", "", "Spec of an OAuth2 client context as JSON string") + testCmd.Flags().BoolVar(&launchBrowser, "launch-browser", true, "Automatically launch the system browser to the Microcks test result") return testCmd } From 375ec588167520852ba1ec3531bf865fd58b16ef Mon Sep 17 00:00:00 2001 From: Manar Elhabbal Date: Sun, 24 May 2026 03:31:42 +0300 Subject: [PATCH 2/2] fix: Prevent panic in CreateTestResult and add proper error handling Signed-off-by: Manar Elhabbal --- pkg/connectors/microcks_client.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/connectors/microcks_client.go b/pkg/connectors/microcks_client.go index cabb85fe..56db4f29 100644 --- a/pkg/connectors/microcks_client.go +++ b/pkg/connectors/microcks_client.go @@ -367,16 +367,24 @@ func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string, body, err := io.ReadAll(resp.Body) if err != nil { - panic(err.Error()) + return "", err + } + + // Raise exception if not created. + if resp.StatusCode < 200 || resp.StatusCode > 299 { + return "", errs.New(string(body)) } var createTestResp map[string]interface{} if err := json.Unmarshal(body, &createTestResp); err != nil { - panic(err) + return "", err } - testID := createTestResp["id"].(string) - return testID, err + testID, ok := createTestResp["id"].(string) + if !ok { + return "", errs.New("Microcks response is missing 'id' field") + } + return testID, nil } func (c *microcksClient) GetTestResult(testResultID string) (*TestResultSummary, error) {