-
Notifications
You must be signed in to change notification settings - Fork 1
/
testrun_show.go
96 lines (80 loc) · 2.28 KB
/
testrun_show.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cmd
import (
"bytes"
"fmt"
"log"
"github.com/pkg/browser"
"github.com/spf13/cobra"
"github.com/stormforger/cli/api"
"github.com/stormforger/cli/api/testrun"
)
var (
// testRunShowCmd represents the calllog command
testRunShowCmd = &cobra.Command{
Use: "show <test-run-ref>",
Short: "Show test run details",
Long: `Show test run details.`,
Run: testRunShow,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatal("Expect exactly one argument: test run reference!")
}
},
}
testRunShowOpts struct {
OpenInBrowser bool
}
)
func init() {
TestRunCmd.AddCommand(testRunShowCmd)
testRunShowCmd.Flags().BoolVar(&testRunShowOpts.OpenInBrowser, "open", false, "Open test run in browser")
}
func testRunShow(cmd *cobra.Command, args []string) {
client := NewClient()
result := fetchTestRun(*client, args[0])
if rootOpts.OutputFormat == "json" {
fmt.Println(string(result))
return
}
testRun, err := testrun.UnmarshalSingle(bytes.NewReader(result))
if err != nil {
log.Fatal(err)
}
// FIXME can we integrate this into testrun.UnmarshalSingle somehow?
meta, err := api.UnmarshalMeta(bytes.NewReader(result))
if err != nil {
log.Fatal(err)
}
if testRunShowOpts.OpenInBrowser {
fmt.Printf("Opening %s in browser...\n", meta.Links.SelfWeb)
err = browser.OpenURL(meta.Links.SelfWeb)
if err != nil {
log.Fatal(err)
}
return
}
fmt.Printf("%s (%s, %s)\n", testRun.Scope, testRun.State, testRun.ID)
fmt.Printf("Report %s\n", meta.Links.SelfWeb)
if testRun.Title != "" {
fmt.Printf("Title %s\n", testRun.Title)
}
fmt.Printf("Started %s\n", testRun.StartedAt)
fmt.Printf("Ended %s\n", testRun.EndedAt)
fmt.Print("Configuration:\n")
fmt.Printf(" Setup: %s cluster in %s\n", testRun.TestConfiguration.ClusterSizing, testRun.TestConfiguration.ClusterRegion)
if testRun.TestConfiguration.DisableGzip {
fmt.Print(" [\u2713] Disabled GZIP\n")
}
if testRun.TestConfiguration.SkipWait {
fmt.Print(" [\u2713] Skip Waits\n")
}
if testRun.TestConfiguration.DumpTrafficFull {
fmt.Print(" [\u2713] Traffic Dump\n")
}
if testRun.TestConfiguration.SessionValidationMode {
fmt.Print(" [\u2713] Session Validation Mode\n")
}
if testRun.Notes != "" {
fmt.Printf("\nNotes:\n%s\n", testRun.Notes)
}
}