@@ -5,12 +5,13 @@ import (
55 "io"
66 "strings"
77 "text/tabwriter"
8+ "time"
89
910 "github.com/signadot/cli/internal/config"
1011 "github.com/signadot/cli/internal/print"
1112 "github.com/signadot/cli/internal/sdtab"
12- "github.com/signadot/cli/internal/utils"
1313 "github.com/signadot/go-sdk/models"
14+ "github.com/xeonx/timeago"
1415)
1516
1617func PrintTestExecution (oFmt config.OutputFormat , w io.Writer , tx * models.TestExecution ) error {
@@ -62,16 +63,14 @@ func printTestExecutionDetails(w io.Writer, tx *models.TestExecution) error {
6263 if tx .Spec .ExecutionContext != nil {
6364 ec := tx .Spec .ExecutionContext
6465 fmt .Fprintf (tw , "Cluster:\t %s\n " , ec .Cluster )
65- if ec .Routing != nil {
66- if ec .Routing .Sandbox != "" {
67- fmt .Fprintf (tw , "Sandbox:\t %s\n " , ec .Routing .Sandbox )
68- } else if ec .Routing .Routegroup != "" {
69- fmt .Fprintf (tw , "Routegroup:\t %s\n " , ec .Routing .Routegroup )
70- }
71- }
66+ fmt .Fprintf (tw , "Environment:\t %s\n " , getTXEnvironment (tx ))
7267 }
7368
74- fmt .Fprintf (tw , "Created:\t %s\n " , utils .FormatTimestamp (tx .CreatedAt ))
69+ createdAt , duration := getTXCreatedAtAndDuration (tx )
70+ fmt .Fprintf (tw , "Created:\t %s\n " , createdAt )
71+ if len (duration ) != 0 {
72+ fmt .Fprintf (tw , "Duration:\t %s\n " , duration )
73+ }
7574 fmt .Fprintf (tw , "Phase:\t %s" , tx .Status .Phase )
7675 if tx .Status .FinalState != nil {
7776 if tx .Status .FinalState .Failed != nil {
@@ -117,11 +116,13 @@ func getResults(tx *models.TestExecution) string {
117116}
118117
119118type testExecRow struct {
120- ID string `sdtab:"ID"`
121- Source string `sdtab:"SOURCE"`
122- TestName string `sdtab:"TESTNAME"`
123- Phase string `sdtab:"PHASE"`
124- CreatedAt string `sdtab:"CREATED"`
119+ ID string `sdtab:"ID"`
120+ Source string `sdtab:"SOURCE"`
121+ TestName string `sdtab:"TESTNAME"`
122+ Environment string `sdtab:"ENVIRONMENT"`
123+ CreatedAt string `sdtab:"CREATED AT"`
124+ Duration string `sdtab:"DURATION"`
125+ Status string `sdtab:"STATUS"`
125126}
126127
127128func printTestExecutionsTable (w io.Writer , txs []* models.TestexecutionsQueryResult ) error {
@@ -141,12 +142,18 @@ func printTestExecutionsTable(w io.Writer, txs []*models.TestexecutionsQueryResu
141142 testName = tx .Spec .Hosted .TestName
142143 }
143144 }
145+
146+ createdAt , duration := getTXCreatedAtAndDuration (tx )
147+ environment := getTXEnvironment (tx )
148+
144149 tab .AddRow (testExecRow {
145- ID : tx .ID ,
146- Source : source ,
147- TestName : truncateTestName (testName ),
148- CreatedAt : tx .CreatedAt ,
149- Phase : tx .Status .Phase ,
150+ ID : tx .ID ,
151+ Source : source ,
152+ TestName : truncateTestName (testName ),
153+ Environment : environment ,
154+ CreatedAt : createdAt ,
155+ Duration : duration ,
156+ Status : tx .Status .Phase ,
150157 })
151158 }
152159 return tab .Flush ()
@@ -159,3 +166,44 @@ func truncateTestName(tn string) string {
159166 }
160167 return tn
161168}
169+
170+ func getTXCreatedAtAndDuration (tx * models.TestExecution ) (createdAtStr string , durationStr string ) {
171+ var createdAt * time.Time
172+
173+ createdAtRaw := tx .CreatedAt
174+ if len (createdAtRaw ) != 0 {
175+ t , err := time .Parse (time .RFC3339 , createdAtRaw )
176+ if err != nil {
177+ return "" , ""
178+ }
179+
180+ createdAt = & t
181+ createdAtStr = timeago .NoMax (timeago .English ).Format (t )
182+ }
183+
184+ finishedAtRaw := tx .Status .FinishedAt
185+ if createdAt != nil && len (finishedAtRaw ) != 0 {
186+ finishedAt , err := time .Parse (time .RFC3339 , finishedAtRaw )
187+ if err != nil {
188+ return "" , ""
189+ }
190+
191+ durationTime := finishedAt .Sub (* createdAt )
192+ durationStr = durationTime .String ()
193+ }
194+
195+ return createdAtStr , durationStr
196+ }
197+
198+ func getTXEnvironment (tx * models.TestExecution ) string {
199+ routingContext := tx .Spec .ExecutionContext .Routing
200+
201+ switch {
202+ case routingContext == nil :
203+ case len (routingContext .Sandbox ) > 0 :
204+ return fmt .Sprintf ("sandbox=%s" , routingContext .Sandbox )
205+ case len (routingContext .Routegroup ) > 0 :
206+ return fmt .Sprintf ("routegroup=%s" , routingContext .Routegroup )
207+ }
208+ return "baseline"
209+ }
0 commit comments