Skip to content

Commit

Permalink
Add 'disable' field to suite/runtime.TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Jul 28, 2020
1 parent d896521 commit 9eebe69
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
4 changes: 4 additions & 0 deletions examples/commander.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ tests:
command: invalid
stderr: "/bin/sh: 1: command invalid: not found"
exit-code: 127

it should skip:
command: echo hello
disable: true
7 changes: 7 additions & 0 deletions pkg/runtime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ func (r *Runner) Execute(tests []TestCase) <-chan TestResult {

go func(tests []TestCase) {
defer close(in)

for _, t := range tests {
if t.Disable {
tr := TestResult{TestCase: t, Skipped: true}
out <- tr
continue
}
in <- t
}

}(tests)

var wg sync.WaitGroup
Expand Down
21 changes: 9 additions & 12 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ const (
LineCount = "LineCount"
)

// Result status codes
const (
//Success status
Success ResultStatus = iota
// Failed status
Failed
// Skipped status
Skipped
)

type Filters []string

// NewRuntime creates a new runtime and inits default nodes
Expand Down Expand Up @@ -62,6 +52,7 @@ type TestCase struct {
Result CommandResult
Nodes []string
FileName string
Disable bool
}

//GlobalTestConfig represents the configuration for a test
Expand Down Expand Up @@ -125,14 +116,15 @@ type TestResult struct {
FailedProperty string
Tries int
Node string
FileName string
Skipped bool
}

// Result respresents the aggregation of all TestResults/summary of a runtime
type Result struct {
TestResults []TestResult
Duration time.Duration
Failed int
Skipped int
}

// Start starts the given test suite and executes all tests
Expand All @@ -141,9 +133,14 @@ func (r *Runtime) Start(tests []TestCase) Result {
testCh := r.Runner.Execute(tests)
start := time.Now()
for tr := range testCh {

r.EventHandler.TestFinished(tr)

if tr.Skipped {
result.Skipped++
// Do not count as failed
tr.ValidationResult.Success = true
}

if !tr.ValidationResult.Success {
result.Failed++
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ func Test_RuntimeWithRetriesAndInterval(t *testing.T) {
assert.True(t, duration.Seconds() > 0.15, "Retry interval did not work")
}

func Test_RuntimeWithSkip(t *testing.T) {
s := getExampleTestCases()
s[0].Disable = true

r := getRuntime()
got := r.Start(s)

assert.Equal(t, 1, got.Skipped)
}

func getRuntime() Runtime {
eh := EventHandler{
TestFinished: func(tr TestResult) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/suite/yaml_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type YAMLTest struct {
Stdout interface{} `yaml:"stdout,omitempty"`
Stderr interface{} `yaml:"stderr,omitempty"`
Config YAMLTestConfigConf `yaml:"config,omitempty"`
Disable bool `yaml:"disable,omitempty"`
}

// ParseYAML parses the Suite from a yaml byte slice
Expand Down Expand Up @@ -118,6 +119,7 @@ func convertYAMLSuiteConfToTestCases(conf YAMLSuiteConf, fileName string) []runt
},
Nodes: t.Config.Nodes,
FileName: fileName,
Disable: t.Disable,
})
}

Expand Down Expand Up @@ -152,6 +154,7 @@ func (y *YAMLSuiteConf) UnmarshalYAML(unmarshal func(interface{}) error) error {
Stdout: y.convertToExpectedOut(v.Stdout),
Stderr: y.convertToExpectedOut(v.Stderr),
Config: y.mergeConfigs(v.Config, params.Config),
Disable: v.Disable,
}

// Set key as command, if command property was empty
Expand Down
22 changes: 22 additions & 0 deletions pkg/suite/yaml_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ tests:
assert.Equal(t, "line4", tests[0].Expected.Stdout.Lines[3])
}

func TestYAMLConfig_UnmarshalYAML_ShouldDisable(t *testing.T) {
yaml := []byte(`
tests:
it should print hello:
command: echo hello
exit-code: 0
stdout: hello
stderr: anything
disable: true
`)
got := ParseYAML(yaml, "")
tests := got.GetTests()

assert.Len(t, tests, 1)
assert.Equal(t, "echo hello", tests[0].Command.Cmd)
assert.Equal(t, 0, tests[0].Expected.ExitCode)
assert.Equal(t, "it should print hello", tests[0].Title)
assert.Equal(t, "hello", tests[0].Expected.Stdout.Contains[0])
assert.Equal(t, "anything", tests[0].Expected.Stderr.Contains[0])
assert.True(t, tests[0].Disable)
}

func TestYAMLConfig_UnmarshalYAML_ShouldConvertStdoutToExpectedOut(t *testing.T) {
yaml := []byte(`
tests:
Expand Down

0 comments on commit 9eebe69

Please sign in to comment.