-
Notifications
You must be signed in to change notification settings - Fork 1
/
testrun_abort.go
76 lines (62 loc) · 1.59 KB
/
testrun_abort.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
package cmd
import (
"fmt"
"log"
"os"
"github.com/spf13/cobra"
)
var (
// testRunAbortCmd represents the abort command
testRunAbortCmd = &cobra.Command{
Use: "abort <test-run-id>",
Short: "Abort the given running test",
Long: `Abort the given running test.`,
Run: testRunAbort,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatal("Expect exactly one argument: test run reference!")
}
},
}
testRunAbortAllCmd = &cobra.Command{
Use: "abort-all <organisation-ref>",
Short: "Abort all running tests for a given organisation",
Long: "Abort all running tests for a given organisation",
Args: cobra.ExactArgs(1),
Run: testRunAbortAll,
ValidArgsFunction: completeOrga,
}
)
func init() {
TestRunCmd.AddCommand(testRunAbortCmd)
TestRunCmd.AddCommand(testRunAbortAllCmd)
}
func testRunAbort(cmd *cobra.Command, args []string) {
client := NewClient()
testRunUID := getTestRunUID(*client, args[0])
status, response, err := client.TestRunAbort(testRunUID)
if err != nil {
log.Fatal(err)
}
if status {
fmt.Println(response)
os.Exit(0)
} else {
fmt.Fprintln(os.Stderr, "Could not abort test run!")
fmt.Println(response)
os.Exit(1)
}
}
func testRunAbortAll(cmd *cobra.Command, args []string) {
uid := lookupOrganisationUID(NewClient(), args[0])
ok, resp, err := NewClient().TestRunAbortAll(uid)
if err != nil {
log.Fatal(err)
}
if !ok {
fmt.Fprintln(os.Stderr, "Could not abort all test runs!")
fmt.Println(resp)
os.Exit(1)
}
fmt.Println(resp)
}