From 245bae81af32bb19bfab2bb8d8f6b848658e0e5c Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 10 Jul 2020 09:13:35 -0400 Subject: [PATCH] add tests for runner, fix typo, remove unneeded todo comments --- pkg/app/test_command.go | 3 +-- pkg/output/cli.go | 2 +- pkg/output/cli_test.go | 2 +- pkg/runtime/runner_test.go | 38 ++++++++++++++++++------------------- pkg/runtime/runtime.go | 4 ++-- pkg/runtime/runtime_test.go | 10 +++++----- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/pkg/app/test_command.go b/pkg/app/test_command.go index 3e34429e..8dd8f3d8 100644 --- a/pkg/app/test_command.go +++ b/pkg/app/test_command.go @@ -60,7 +60,6 @@ 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()) @@ -68,7 +67,7 @@ func testDir(directory string) (runtime.Result, 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()) diff --git a/pkg/output/cli.go b/pkg/output/cli.go index 4a09415f..12d619e1 100644 --- a/pkg/output/cli.go +++ b/pkg/output/cli.go @@ -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) } diff --git a/pkg/output/cli_test.go b/pkg/output/cli_test.go index cd743c3f..5575bac6 100644 --- a/pkg/output/cli_test.go +++ b/pkg/output/cli_test.go @@ -29,7 +29,7 @@ func Test_EventHandlerTestFinished(t *testing.T) { testResults := createFakeTestResults() for _, tr := range testResults { - eh.TestFinsihed(tr) + eh.TestFinished(tr) } diff --git a/pkg/runtime/runner_test.go b/pkg/runtime/runner_test.go index bf574f99..9a095b72 100644 --- a/pkg/runtime/runner_test.go +++ b/pkg/runtime/runner_test.go @@ -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(), @@ -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 -} diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 357e587d..f7e5f347 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -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 @@ -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++ diff --git a/pkg/runtime/runtime_test.go b/pkg/runtime/runtime_test.go index 8e51a453..1af1b7e5 100644 --- a/pkg/runtime/runtime_test.go +++ b/pkg/runtime/runtime_test.go @@ -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) @@ -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" @@ -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" @@ -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") }, } @@ -80,7 +80,7 @@ func getRuntime() Runtime { return runtime } -func getExampleTestSuite() []TestCase { +func getExampleTestCases() []TestCase { tests := []TestCase{ { Command: CommandUnderTest{