Skip to content

Commit

Permalink
add tests for runner, fix typo, remove unneeded todo comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Jul 10, 2020
1 parent 435892a commit 245bae8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
3 changes: 1 addition & 2 deletions pkg/app/test_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ func TestCommand(testPath string, testFilterTitle string, ctx AddCommandContext)
func testDir(directory string) (runtime.Result, error) {
result := runtime.Result{}

// TODO: validate entire dir before running tests: issue #129
files, err := ioutil.ReadDir(directory)
if err != nil {
return result, fmt.Errorf(err.Error())
}

for _, f := range files {
if f.IsDir() {
continue // skip dirs: TODO add support for walking
continue // skip dirs
}

path := path.Join(directory, f.Name())
Expand Down
2 changes: 1 addition & 1 deletion pkg/output/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type TestResult struct {
// GetEventHandler create a new runtime.EventHandler
func (w *OutputWriter) GetEventHandler() *runtime.EventHandler {
handler := runtime.EventHandler{}
handler.TestFinsihed = func(testResult runtime.TestResult) {
handler.TestFinished = func(testResult runtime.TestResult) {
tr := convertTestResult(testResult)
w.printResult(tr)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/output/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Test_EventHandlerTestFinished(t *testing.T) {
testResults := createFakeTestResults()

for _, tr := range testResults {
eh.TestFinsihed(tr)
eh.TestFinished(tr)

}

Expand Down
38 changes: 19 additions & 19 deletions pkg/runtime/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_RunnerExexcute(t *testing.T) {
s := getExampleTestCases()
r := Runner{
Nodes: getExampleNodes(),
}

got := r.Execute(s)

assert.IsType(t, make(<-chan TestResult), got)

count := 0
for r := range got {
assert.Equal(t, "Output hello", r.TestCase.Title)
assert.True(t, r.ValidationResult.Success)
count++
}
assert.Equal(t, 1, count)
}

func Test_getExecutor(t *testing.T) {
r := Runner{
Nodes: getExampleNodes(),
Expand Down Expand Up @@ -38,22 +57,3 @@ func getExampleNodes() []Node {
}
return nodes
}

func getExampleTestCases() []TestCase {
tests := []TestCase{
{
Command: CommandUnderTest{
Cmd: "echo hello",
Timeout: "5s",
},
Expected: Expected{
Stdout: ExpectedOut{
Exactly: "hello",
},
ExitCode: 0,
},
Title: "Output hello",
},
}
return tests
}
4 changes: 2 additions & 2 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Runtime struct {

// EventHandler is a configurable event system that handles events such as test completion
type EventHandler struct {
TestFinsihed func(TestResult)
TestFinished func(TestResult)
}

// TestCase represents a test case which will be executed by the runtime
Expand Down Expand Up @@ -140,7 +140,7 @@ func (r *Runtime) Start(tests []TestCase) Result {
start := time.Now()
for tr := range testCh {

r.EventHandler.TestFinsihed(tr)
r.EventHandler.TestFinished(tr)

if !tr.ValidationResult.Success {
result.Failed++
Expand Down
10 changes: 5 additions & 5 deletions pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test_NewRuntime(t *testing.T) {
}

func Test_RuntimeStart(t *testing.T) {
s := getExampleTestSuite()
s := getExampleTestCases()
r := getRuntime()
got := r.Start(s)

Expand All @@ -30,7 +30,7 @@ func Test_RuntimeStart(t *testing.T) {
}

func TestRuntime_WithRetries(t *testing.T) {
s := getExampleTestSuite()
s := getExampleTestCases()
s[0].Command.Retries = 3
s[0].Command.Cmd = "echo fail"

Expand All @@ -48,7 +48,7 @@ func TestRuntime_WithRetries(t *testing.T) {
}

func Test_RuntimeWithRetriesAndInterval(t *testing.T) {
s := getExampleTestSuite()
s := getExampleTestCases()
s[0].Command.Retries = 3
s[0].Command.Cmd = "echo fail"
s[0].Command.Interval = "50ms"
Expand All @@ -71,7 +71,7 @@ func Test_RuntimeWithRetriesAndInterval(t *testing.T) {

func getRuntime() Runtime {
eh := EventHandler{
TestFinsihed: func(tr TestResult) {
TestFinished: func(tr TestResult) {
fmt.Println("I do nothing")
},
}
Expand All @@ -80,7 +80,7 @@ func getRuntime() Runtime {
return runtime
}

func getExampleTestSuite() []TestCase {
func getExampleTestCases() []TestCase {
tests := []TestCase{
{
Command: CommandUnderTest{
Expand Down

0 comments on commit 245bae8

Please sign in to comment.