-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
141 lines (125 loc) · 4.23 KB
/
types.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
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
133
134
135
136
137
138
139
140
141
package qac
import (
"fmt"
"runtime"
"strings"
)
// TestPlan represents the full set of tests on a program.
type TestPlan struct {
Preconditions Preconditions `yaml:"preconditions"`
Specs map[string]Spec `yaml:"specs"`
}
// Spec is the single test.
type Spec struct {
id string
Description string `yaml:"description"`
Preconditions Preconditions `yaml:"preconditions"`
Command Command `yaml:"command"`
Expectations Expectations `yaml:"expectations"`
}
// ID returns the dinamically created identifier for a spec.
func (s Spec) ID() string {
return s.id
}
// FileSystemAssertion is an assertion on files and directories.
type FileSystemAssertion struct {
File string `yaml:"file"`
// aggiunta a file
Extension FileExtension `yaml:"ext"`
Directory string `yaml:"directory"`
Exists *bool `yaml:"exists"`
EqualsTo string `yaml:"equals_to"`
// Only for files
TextEqualsTo string `yaml:"text_equals_to"`
ContainsAny []string `yaml:"contains_any"`
ContainsAll []string `yaml:"contains_all"`
ContainsExactly []string `yaml:"contains_exactly"`
}
// FileExtension is added as suffix to file assertions' path and command's exe values
// based on runtime.GOOS
type FileExtension struct {
Windows string `yaml:"windows"`
Unix string `yaml:"unix"`
}
func (e FileExtension) isSet() bool {
return len(e.Windows) > 0 || len(e.Unix) > 0
}
func (e FileExtension) get() string {
if runtime.GOOS == "windows" {
return e.Windows
}
return e.Unix
}
// FileAssertion is an assertion on a given file.
type FileAssertion struct {
Path string `yaml:"path"`
// aggiunta a path
Extension FileExtension `yaml:"ext"`
Exists bool `yaml:"exists"`
EqualsTo string `yaml:"equals_to"`
TextEqualsTo string `yaml:"text_equals_to"`
ContainsAny []string `yaml:"contains_any"`
ContainsAll []string `yaml:"contains_all"`
}
// DirectoryAssertion is an assertion on a given directory.
type DirectoryAssertion struct {
Path string `yaml:"path"`
Exists bool `yaml:"exists"`
EqualsTo string `yaml:"equals_to"`
ContainsAny []string `yaml:"contains_any"`
ContainsAll []string `yaml:"contains_all"`
ContainsExactly []string `yaml:"contains_exactly"`
}
// Preconditions represents the minimal requirements for a plan or a single spec to start.
type Preconditions struct {
FileSystemAssertions []FileSystemAssertion `yaml:"fs"`
}
// Command represents the command under test.
type Command struct {
WorkingDir string `yaml:"working_dir"`
Cli string `yaml:"cli"`
Exe string `yaml:"exe"`
Env map[string]string
// added to exe
Extension FileExtension `yaml:"ext"`
Args []string `yaml:"args"`
}
func (c Command) String() string {
fullCommand := c.Cli
if fullCommand == "" {
fullCommand = strings.TrimSpace(c.Exe + " " + strings.Join(c.Args, " "))
}
return fmt.Sprintf("%s# %s", c.WorkingDir, fullCommand)
}
// StatusAssertion represents an assertion on the status code returned from a command.
type StatusAssertion struct {
EqualsTo string `yaml:"equals_to"`
GreaterThan string `yaml:"greater_than"`
LesserThan string `yaml:"lesser_than"`
}
// OutputAssertion is an assertion on the output of a command: namely standard output and standard error.
type OutputAssertion struct {
// to identify as "stdout" or "stderr"
id string
EqualsTo string `yaml:"equals_to"`
EqualsToFile string `yaml:"equals_to_file"`
// output is trimmed
StartsWith string `yaml:"starts_with"`
// output is trimmed
EndsWith string `yaml:"ends_with"`
IsEmpty *bool `yaml:"is_empty"`
ContainsAny []string `yaml:"contains_any"`
ContainsAll []string `yaml:"contains_all"`
ContainsNone []string `yaml:"contains_none"`
}
// OutputAssertions is the aggregate of stdout and stderr assertions.
type OutputAssertions struct {
Stdout OutputAssertion `yaml:"stdout"`
Stderr OutputAssertion `yaml:"stderr"`
}
// Expectations is the aggregate of the final assertions on the command executed.
type Expectations struct {
StatusAssertion StatusAssertion `yaml:"status"`
OutputAssertions OutputAssertions `yaml:"output"`
FileSystemAssertions []FileSystemAssertion `yaml:"fs"`
}