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
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra"
)

func NewCommad() *cobra.Command {
func NewCommand() *cobra.Command {

var clientOpts connectors.ClientOptions

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 27 additions & 13 deletions pkg/connectors/microcks_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down