-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_case.go
More file actions
132 lines (119 loc) · 3.34 KB
/
test_case.go
File metadata and controls
132 lines (119 loc) · 3.34 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"errors"
"path/filepath"
"strings"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/file"
)
type record struct {
Enabled string `json:"enabled"`
Mode string `json:"mode"`
Speed string `json:"speed"`
Route string `json:"route"`
Path string `json:"path"`
Tool string `json:"tool"`
Filename string `json:"filename"`
Post string `json:"post"`
Options string `json:"options"`
}
type TestCase struct {
record
IsEnabled bool `json:"isEnabled,omitempty"`
HasShorthand bool `json:"hasShorthand,omitempty"`
WorkingPath string `json:"workingPath,omitempty"`
OrigOptions string `json:"origOptions,omitempty"`
SourceFile string `json:"sourceFile,omitempty"`
SdkOptions string `json:"sdkOptions,omitempty"`
CmdOptions string `json:"cmdOptions,omitempty"`
ApiOptions string `json:"apiOptions,omitempty"`
SdkOptionsArray []string `json:"sdkOptionArray,omitempty"`
OptionArray []string `json:"optionArray,omitempty"`
}
func (t *TestCase) OptionsForMode(mode string) string {
switch mode {
case "api":
return t.ApiOptions
case "cmd":
return t.CmdOptions
case "sdk":
return t.SdkOptions
}
return t.OrigOptions
}
func (t *TestCase) InnerTest(mode string) (string, error) {
switch mode {
case "api":
return t.ApiTest()
case "cmd":
return t.CmdTest()
case "sdk":
return t.SdkTest()
}
return "", errors.New("Invalid mode:" + mode)
}
func (t *TestCase) ShouldRun(mode string) bool {
if !t.IsEnabled {
return false
}
switch mode {
case "api":
if t.Mode == "cmd" || t.Mode == "sdk" || strings.Contains(t.Tool, "chifra") || t.Route == "monitors" {
return false
}
case "cmd":
if t.Mode == "api" || t.Mode == "sdk" {
return false
}
case "sdk":
if t.Mode == "cmd" || t.Mode == "api" || t.HasShorthand || strings.Contains(t.Tool, "chifra") || t.Route == "monitors" {
return false
}
}
return true
}
func (t *TestCase) GetOutputPaths(mode string) (string, string, string, string) {
working := t.WorkingPath
if mode != "cmd" {
working = filepath.Join(t.WorkingPath, mode+"_tests")
}
gold := strings.ReplaceAll(working, "working", "gold")
workFn := filepath.Join(working, t.Tool+"_"+t.Filename+".txt")
goldFn := filepath.Join(gold, t.Tool+"_"+t.Filename+".txt")
testRoot := func(s string) string {
return strings.ReplaceAll(strings.ReplaceAll(s, "sdk_tests", ""), "api_tests", "")
}
envFn := filepath.Join(testRoot(gold), t.Filename+".env")
if !file.FileExists(envFn) {
envFn = ""
}
outputFn := ""
if mode == "cmd" {
redirFn := filepath.Join(gold, t.Filename+".redir")
if file.FileExists(redirFn) {
t.OptionArray = append(t.OptionArray, "output="+t.Filename+"_out.file")
}
for _, option := range t.OptionArray {
if strings.HasPrefix(option, "output") {
parts := strings.Split(option, "=")
if len(parts) < 2 {
continue
}
outputFn = parts[1]
break
}
}
if len(outputFn) > 0 {
outputFn = filepath.Join(gold, outputFn)
}
}
return workFn, goldFn, envFn, outputFn
}
func (t *TestCase) ProcessRedirFile() {
gold := strings.ReplaceAll(t.WorkingPath, "working", "gold")
redirFn := filepath.Join(gold, t.Filename+".redir")
if file.FileExists(redirFn) {
outFn := t.Filename + "_out.file"
t.OptionArray = append(t.OptionArray, "output="+outFn)
t.CmdOptions += " --output " + outFn
}
}