Skip to content

Commit d984c0f

Browse files
committed
Adding configurable time for loop
1 parent 813320a commit d984c0f

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

cmd/help.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (c *helpCommand) Execute() {
2626
fmt.Println(" test launch new test on Microcks server")
2727
fmt.Println("")
2828
fmt.Println("Use: microcks-cli test <apiName:apiVersion> <testEndpoint> <runner> \\")
29-
fmt.Println(" --microcksURL=<> --waitFor=10sec \\")
29+
fmt.Println(" --microcksURL=<> --waitFor=5sec \\")
3030
fmt.Println(" --keycloakURL=<> --keycloakUsername=<> --keycloakPassword=<>")
3131
fmt.Println("")
3232
fmt.Println("Args: ")
@@ -36,6 +36,7 @@ func (c *helpCommand) Execute() {
3636
fmt.Println("")
3737
fmt.Println("Flags: ")
3838
fmt.Println(" --microcksURL Microcks API endpoint")
39+
fmt.Println(" --waitFor Time to wait for test to finish (int + one of: milli, sec, min)")
3940
fmt.Println(" --keycloakURL Keycloak Realm API endpoint for Microcks")
4041
fmt.Println(" --keycloakUsername Keycloak Realm ServiceAccount")
4142
fmt.Println(" --keycloakPassword Keycloak Realm Account Password")

cmd/test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"strconv"
78
"strings"
89
"time"
910

@@ -61,11 +62,13 @@ func (c *testComamnd) Execute() {
6162
var keycloakURL string
6263
var keycloakUsername string
6364
var keycloakPassword string
65+
var waitFor string
6466

6567
testCmd.StringVar(&microcksURL, "microcksURL", "", "Microcks API URL")
6668
testCmd.StringVar(&keycloakURL, "keycloakURL", "", "Keycloak Realm URL")
6769
testCmd.StringVar(&keycloakUsername, "keycloakUsername", "", "Keycloak Realm ServiceAccount ")
6870
testCmd.StringVar(&keycloakPassword, "keycloakPassword", "", "Keycloak Realm Account Password")
71+
testCmd.StringVar(&waitFor, "waitFor", "5sec", "Time to wait for test to finish")
6972
testCmd.Parse(os.Args[5:])
7073

7174
// Validate presence and values of flags.
@@ -85,6 +88,22 @@ func (c *testComamnd) Execute() {
8588
fmt.Println("--keycloakPassword flag is mandatory. Check Usage.")
8689
os.Exit(1)
8790
}
91+
if &waitFor == nil || (!strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min")) {
92+
fmt.Println("--waitFor format is wrong. Applying default 5sec")
93+
waitFor = "5sec"
94+
}
95+
96+
// Compute time to wait in milliseconds.
97+
var waitForMilliseconds int64 = 5000
98+
if strings.HasSuffix(waitFor, "milli") {
99+
waitForMilliseconds, _ = strconv.ParseInt(waitFor[:len(waitFor)-5], 0, 64)
100+
} else if strings.HasSuffix(waitFor, "sec") {
101+
waitForMilliseconds, _ = strconv.ParseInt(waitFor[:len(waitFor)-3], 0, 64)
102+
waitForMilliseconds = waitForMilliseconds * 1000
103+
} else if strings.HasSuffix(waitFor, "min") {
104+
waitForMilliseconds, _ = strconv.ParseInt(waitFor[:len(waitFor)-3], 0, 64)
105+
waitForMilliseconds = waitForMilliseconds * 60 * 1000
106+
}
88107

89108
// Now we seems to be good ...
90109
// First - retrieve an OAuth token using Keycloak Client.
@@ -109,11 +128,13 @@ func (c *testComamnd) Execute() {
109128
}
110129
//fmt.Printf("Retrieve TestResult ID: %s", testResultID)
111130

131+
// Finally - wait for some time
112132
now := nowInMilliseconds()
113-
future := now + 5000
133+
future := now + waitForMilliseconds
114134

115-
var success = false
135+
fmt.Println("now: " + fmt.Sprint(now) + " - future: " + fmt.Sprint(future))
116136

137+
var success = false
117138
for nowInMilliseconds() < future {
118139
testResultSummary, err := mc.GetTestResult(testResultID)
119140
if err != nil {

0 commit comments

Comments
 (0)