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

Commit

Permalink
Merge branch 'development' into v0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates authored Oct 30, 2019
2 parents 719ff98 + 4ad4272 commit 672c177
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 672c177

Please sign in to comment.