Skip to content

Commit

Permalink
Rename AddCommandContext to TestCommandContext
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBaeumer committed Jul 17, 2020
1 parent 107f2ac commit cb91de1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test commander.yaml --filter=filter1 --filter=filter2
},
},
Action: func(c *cli.Context) error {
return app.TestCommand(c.Args().First(), app.NewAddContextFromCli(c))
return app.TestCommand(c.Args().First(), app.NewTestContextFromCli(c))
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ const (
CommanderFile = "commander.yaml"
)

//AddCommandContext holds all flags for the add command
type AddCommandContext struct {
//TestCommandContext holds all flags for the add command
type TestCommandContext struct {
Verbose bool
NoColor bool
Dir bool
Concurrent int
Filters []string
}

//NewAddContextFromCli is a constructor which creates the context
func NewAddContextFromCli(c *cli.Context) AddCommandContext {
return AddCommandContext{
//NewTestContextFromCli is a constructor which creates the context
func NewTestContextFromCli(c *cli.Context) TestCommandContext {
return TestCommandContext{
Verbose: c.Bool("verbose"),
NoColor: c.Bool("no-color"),
Dir: c.Bool("dir"),
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
)

func TestNewAddCommandContextFromCli(t *testing.T) {
func TestNewTestCommandContextFromCli(t *testing.T) {
set := flag.NewFlagSet("verbose", 0)
set.Bool("verbose", true, "")
set.Bool("no-color", true, "")
Expand All @@ -16,7 +16,7 @@ func TestNewAddCommandContextFromCli(t *testing.T) {
context := &cli.Context{}
ctx := cli.NewContext(nil, set, context)

r := NewAddContextFromCli(ctx)
r := NewTestContextFromCli(ctx)

assert.True(t, r.Verbose)
assert.True(t, r.NoColor)
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/test_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var out output.OutputWriter
// testPath is the path to the test suite config, it can be a dir or file
// ctx holds the command flags. If directory scanning is enabled with --dir it is
// not supported to filter tests, therefore testFilterTitle is an empty string
func TestCommand(testPath string, ctx AddCommandContext) error {
func TestCommand(testPath string, ctx TestCommandContext) error {
if ctx.Verbose {
log.SetOutput(os.Stdout)
}
Expand Down Expand Up @@ -65,8 +65,8 @@ func testDir(directory string, filters runtime.Filters) (runtime.Result, error)
continue // skip dirs
}

path := path.Join(directory, f.Name())
newResult, err := testFile(path, f.Name(), filters)
p := path.Join(directory, f.Name())
newResult, err := testFile(p, f.Name(), filters)
if err != nil {
return result, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/test_command_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tests:

assert.Nil(t, err)

got := TestCommand(TestSuiteFile, AddCommandContext{})
got := TestCommand(TestSuiteFile, TestCommandContext{})
assert.Nil(t, got)
}

Expand All @@ -34,7 +34,7 @@ tests:

assert.Nil(t, err)

got := TestCommand(TestSuiteFile, AddCommandContext{})
got := TestCommand(TestSuiteFile, TestCommandContext{})
assert.Equal(t, "Test suite failed, use --verbose for more detailed output", got.Error())

}
Expand All @@ -53,7 +53,7 @@ tests:

assert.Nil(t, err)

context := AddCommandContext{}
context := TestCommandContext{}
context.Filters = runtime.Filters{"my title"}
got := TestCommand(TestSuiteFile, context)
assert.Nil(t, got)
Expand Down
12 changes: 6 additions & 6 deletions pkg/app/test_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import (

func Test_TestCommand_Verbose(t *testing.T) {
out := captureOutput(func() {
TestCommand("commander.yaml", AddCommandContext{Verbose: true})
TestCommand("commander.yaml", TestCommandContext{Verbose: true})
log.Println("test test test")
})

assert.Contains(t, out, "test test test")
}

func Test_TestCommand_DefaultFile(t *testing.T) {
err := TestCommand("", AddCommandContext{Verbose: true})
err := TestCommand("", TestCommandContext{Verbose: true})
assert.Contains(t, err.Error(), "commander.yaml")
}

func Test_TestCommand(t *testing.T) {
err := TestCommand("commander.yaml", AddCommandContext{})
err := TestCommand("commander.yaml", TestCommandContext{})

if runtime.GOOS == "windows" {
assert.Contains(t, err.Error(), "Error open commander.yaml:")
Expand All @@ -39,7 +39,7 @@ func Test_TestCommand(t *testing.T) {
}

func Test_TestCommand_ShouldUseCustomFile(t *testing.T) {
err := TestCommand("my-test.yaml", AddCommandContext{})
err := TestCommand("my-test.yaml", TestCommandContext{})

if runtime.GOOS == "windows" {
assert.Contains(t, err.Error(), "Error open my-test.yaml:")
Expand All @@ -49,7 +49,7 @@ func Test_TestCommand_ShouldUseCustomFile(t *testing.T) {
}

func Test_TestCommand_File_WithDir(t *testing.T) {
err := TestCommand("../../examples", AddCommandContext{})
err := TestCommand("../../examples", TestCommandContext{})

if runtime.GOOS == "windows" {
assert.Contains(t, err.Error(), "is a directory")
Expand All @@ -59,7 +59,7 @@ func Test_TestCommand_File_WithDir(t *testing.T) {
}

func Test_TestCommand_Dir(t *testing.T) {
err := TestCommand("../../examples", AddCommandContext{Dir: true})
err := TestCommand("../../examples", TestCommandContext{Dir: true})

if runtime.GOOS == "windows" {
assert.Contains(t, err.Error(), "Test suite failed, use --verbose for more detailed output")
Expand Down

0 comments on commit cb91de1

Please sign in to comment.