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