Skip to content

Commit

Permalink
feat: #31 Adding the --filteredOperations flag and preparing release …
Browse files Browse the repository at this point in the history
…0.5.3

Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>
  • Loading branch information
lbroudoux committed Jul 27, 2023
1 parent 74a58ed commit 75e440c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Ouput of the build-binaries script
build/_output
4 changes: 3 additions & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (c *testComamnd) Execute() {
var keycloakClientSecret string
var waitFor string
var secretName string
var filteredOperations string
var operationsHeaders string
var insecureTLS bool
var caCertPaths string
Expand All @@ -75,6 +76,7 @@ func (c *testComamnd) Execute() {
testCmd.StringVar(&keycloakClientSecret, "keycloakClientSecret", "", "Keycloak Realm Service Account ClientSecret")
testCmd.StringVar(&waitFor, "waitFor", "5sec", "Time to wait for test to finish")
testCmd.StringVar(&secretName, "secretName", "", "Secret to use for connecting test endpoint")
testCmd.StringVar(&filteredOperations, "filteredOperations", "", "List of operations to launch a test for")
testCmd.StringVar(&operationsHeaders, "operationsHeaders", "", "Override of operations headers as JSON string")
testCmd.BoolVar(&insecureTLS, "insecure", false, "Whether to accept insecure HTTPS connection")
testCmd.StringVar(&caCertPaths, "caCerts", "", "Comma separated paths of CRT files to add to Root CAs")
Expand Down Expand Up @@ -148,7 +150,7 @@ func (c *testComamnd) Execute() {
mc.SetOAuthToken(oauthToken)

var testResultID string
testResultID, err = mc.CreateTestResult(serviceRef, testEndpoint, runnerType, secretName, waitForMilliseconds, operationsHeaders)
testResultID, err = mc.CreateTestResult(serviceRef, testEndpoint, runnerType, secretName, waitForMilliseconds, filteredOperations, operationsHeaders)
if err != nil {
fmt.Printf("Got error when invoking Microcks client creating Test: %s", err)
os.Exit(1)
Expand Down
22 changes: 18 additions & 4 deletions pkg/connectors/microcks_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
type MicrocksClient interface {
GetKeycloakURL() (string, error)
SetOAuthToken(oauthToken string)
CreateTestResult(serviceID string, testEndpoint string, runnerType string, secretName string, timeout int64, operationsHeaders string) (string, error)
CreateTestResult(serviceID string, testEndpoint string, runnerType string, secretName string, timeout int64, filteredOperations string, operationsHeaders string) (string, error)
GetTestResult(testResultID string) (*TestResultSummary, error)
UploadArtifact(specificationFilePath string, mainArtifact bool) (string, error)
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func (c *microcksClient) SetOAuthToken(oauthToken string) {
c.OAuthToken = oauthToken
}

func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string, runnerType string, secretName string, timeout int64, operationsHeaders string) (string, error) {
func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string, runnerType string, secretName string, timeout int64, filteredOperations string, operationsHeaders string) (string, error) {
// Ensure we have a correct URL.
rel := &url.URL{Path: "tests"}
u := c.APIURL.ResolveReference(rel)
Expand All @@ -136,7 +136,10 @@ func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string,
if len(secretName) > 0 {
input += (", \"secretName\": \"" + secretName + "\"")
}
if len(operationsHeaders) > 0 && ensureValid(operationsHeaders) {
if len(filteredOperations) > 0 && ensureValidOperationsList(filteredOperations) {
input += (", \"filteredOperations\": " + filteredOperations)
}
if len(operationsHeaders) > 0 && ensureValidOperationsHeaders(operationsHeaders) {
input += (", \"operationsHeaders\": " + operationsHeaders)
}

Expand Down Expand Up @@ -272,7 +275,18 @@ func (c *microcksClient) UploadArtifact(specificationFilePath string, mainArtifa
return string(respBody), err
}

func ensureValid(operationsHeaders string) bool {
func ensureValidOperationsList(filteredOperations string) bool {
// Unmarshal using a generic interface
var list = []string{}
err := json.Unmarshal([]byte(filteredOperations), &list)
if err != nil {
fmt.Println("Error parsing JSON in filteredOperations: ", err)
return false
}
return true
}

func ensureValidOperationsHeaders(operationsHeaders string) bool {
// Unmarshal using a generic interface
var headers = map[string][]HeaderDTO{}
err := json.Unmarshal([]byte(operationsHeaders), &headers)
Expand Down
8 changes: 6 additions & 2 deletions tekton/microcks-test-customcerts-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ spec:
type: string
description: "Time to wait for test to finish (int + one of: milli, sec, min)"
default: 5sec
- name: filteredOperations
type: string
description: "JSON array of the operations' names to consider during the tests"
default: ""
- name: operationsHeaders
type: string
description: "JSON that override some operations headers for the tests to launch"
Expand All @@ -39,7 +43,7 @@ spec:
description: "Paths to additional certificates CRT files to add to trusted roots ones"
steps:
- name: microcks-test
image: quay.io/microcks/microcks-cli:0.5.1
image: quay.io/microcks/microcks-cli:0.5.3
volumeMounts:
- name: microcks-test-customcerts
mountPath: /var/run/secrets/customcerts
Expand All @@ -51,7 +55,7 @@ spec:
microcks-cli test '$(params.apiNameAndVersion)' $(params.testEndpoint) $(params.runner) \
--microcksURL=$(params.microcksURL) --waitFor=$(params.waitFor) \
--keycloakClientId=$(params.keycloakClientId) --keycloakClientSecret=$(params.keycloakClientSecret) \
--caCerts=/var/run/secrets/customcerts/ca.crt --operationsHeaders='$(params.operationsHeaders)'
--caCerts=/var/run/secrets/customcerts/ca.crt --filteredOperations='$(params.filteredOperations)' --operationsHeaders='$(params.operationsHeaders)'
volumes:
- name: microcks-test-customcerts
secret:
Expand Down
8 changes: 6 additions & 2 deletions tekton/microcks-test-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ spec:
type: string
description: "Time to wait for test to finish (int + one of: milli, sec, min)"
default: 5sec
- name: filteredOperations
type: string
description: "JSON array of the operations' names to consider during the tests"
default: ""
- name: operationsHeaders
type: string
description: "JSON that override some operations headers for the tests to launch"
default: ""
steps:
- name: microcks-test
image: quay.io/microcks/microcks-cli:0.5.1
image: quay.io/microcks/microcks-cli:0.5.3
command:
- /usr/bin/bash
args:
Expand All @@ -45,4 +49,4 @@ spec:
microcks-cli test '$(params.apiNameAndVersion)' $(params.testEndpoint) $(params.runner) \
--microcksURL=$(params.microcksURL) --waitFor=$(params.waitFor) \
--keycloakClientId=$(params.keycloakClientId) --keycloakClientSecret=$(params.keycloakClientSecret) \
--insecure --operationsHeaders='$(params.operationsHeaders)'
--insecure --filteredOperations='$(params.filteredOperations)' --operationsHeaders='$(params.operationsHeaders)'
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package version

var (
Version = "0.5.2"
Version = "0.5.3"
)

0 comments on commit 75e440c

Please sign in to comment.