Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -39,6 +40,7 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command {
filteredOperations string
operationsHeaders string
oAuth2Context string
launchBrowser bool
)
var testCmd = &cobra.Command{

Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
16 changes: 12 additions & 4 deletions pkg/connectors/microcks_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading