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

Fix test --force-migrations flag bug #1812

Merged
merged 3 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions buffalo/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ 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)

ypjama marked this conversation as resolved.
Show resolved Hide resolved
if forceMigrations {
fm, err := pop.NewFileMigrator("./migrations", test)

Expand Down Expand Up @@ -216,3 +219,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)
}
}
}