Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Fix test --force-migrations flag bug (#1812)
Browse files Browse the repository at this point in the history
* Fix test --force-migrations flag bug

* This fixes a bug that occurs when --force-migrations flag is used
while also specifying the packages to be tested. e.g. `buffalo test
./actions/ --force-migrations`

* Remove whitespaces from empty row

Suggested by fixmie

Co-Authored-By: fixmie[bot] <44270338+fixmie[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and markbates committed Oct 30, 2019
1 parent 0106086 commit 4ad4272
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions buffalo/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ var testCmd = &cobra.Command{
return err
}

// Read and remove --force-migrations flag from args:
forceMigrations = strings.Contains(strings.Join(args, ""), "--force-migrations")
args = cutArg("--force-migrations", args)
if forceMigrations {
fm, err := pop.NewFileMigrator("./migrations", test)

Expand Down Expand Up @@ -216,3 +218,13 @@ func newTestCmd(args []string) *exec.Cmd {
cmd.Stderr = os.Stderr
return cmd
}

func cutArg(arg string, args []string) []string {
for i, v := range args {
if v == arg {
return append(args[:i], args[i+1:]...)
}
}

return args
}
27 changes: 27 additions & 0 deletions buffalo/cmd/test_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"reflect"
"testing"
)

func Test_CutArg(t *testing.T) {
var tests = []struct {
arg string
args []string
expected []string
}{
{"b", []string{"a", "b", "c"}, []string{"a", "c"}},
{"--is-not-in-args", []string{"a", "b", "c"}, []string{"a", "b", "c"}},
{"--foo", []string{"--foo", "--bar", "--baz"}, []string{"--bar", "--baz"}},
{"--force-migrations", []string{"./actions/", "--force-migrations"}, []string{"./actions/"}},
{"--force-migrations", []string{"./actions/", "--force-migrations", "-m", "Test_HomeHandler"}, []string{"./actions/", "-m", "Test_HomeHandler"}},
}

for _, tt := range tests {
result := cutArg(tt.arg, tt.args)
if !reflect.DeepEqual(result, tt.expected) {
t.Errorf("got %s, want %s when cutting %s from %s", result, tt.expected, tt.arg, tt.args)
}
}
}

0 comments on commit 4ad4272

Please sign in to comment.