forked from ForceCLI/force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.go
88 lines (76 loc) · 2.11 KB
/
test.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
package main
import (
"fmt"
"strconv"
)
var cmdTest = &Command{
Usage: "test (all | classname...)",
Short: "Run apex tests",
Long: `
Run apex tests
Test Options
-namespace=<namespace> Select namespace to run test from
-v Verbose logging
Examples:
force test all
force test Test1 Test2 Test3
force test -namespace=ns Test4
force test -v Test1
`,
}
func init() {
cmdTest.Flag.BoolVar(&verboselogging, "v", false, "set verbose logging")
cmdTest.Run = runTests
}
var (
namespaceTestFlag = cmdTest.Flag.String("namespace", "", "namespace to run tests in")
verboselogging bool
)
func runTests(cmd *Command, args []string) {
if len(args) < 1 {
ErrorAndExit("must specify tests to run")
}
force, _ := ActiveForce()
output, err := force.Partner.RunTests(args, *namespaceTestFlag)
success := false
if err != nil {
ErrorAndExit(err.Error())
} else {
if verboselogging {
fmt.Println(output.Log)
fmt.Println()
}
//working on a better way to do this - catches when no class are found and ran
if output.NumberRun == 0 {
fmt.Println("Test classes specified not found")
} else {
var percent string
fmt.Println("Coverage:")
fmt.Println()
for index := range output.NumberLocations {
if output.NumberLocations[index] != 0 {
percent = strconv.Itoa(((output.NumberLocations[index]-output.NumberLocationsNotCovered[index])/output.NumberLocations[index])*100) + "%"
} else {
percent = "0%"
}
fmt.Println(" " + percent + " " + output.Name[index])
}
fmt.Println()
fmt.Println()
fmt.Println("Results:")
fmt.Println()
for index := range output.SMethodNames {
fmt.Println(" [PASS] " + output.SClassNames[index] + "::" + output.SMethodNames[index])
}
for index := range output.FMethodNames {
fmt.Println(" [FAIL] " + output.FClassNames[index] + "::" + output.FMethodNames[index] + ": " + output.FMessage[index])
fmt.Println(" " + output.FStackTrace[index])
}
fmt.Println()
fmt.Println()
success = len(output.FMethodNames) == 0
}
// Handle notifications
notifySuccess("test", success)
}
}