From 887aa979364f45f08e6a682540db19b53f751762 Mon Sep 17 00:00:00 2001 From: Matias Ylipelto <3822534+ypjama@users.noreply.github.com> Date: Tue, 22 Oct 2019 22:17:06 +0300 Subject: [PATCH 1/2] 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` --- buffalo/cmd/test.go | 13 +++++++++++++ buffalo/cmd/test_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 buffalo/cmd/test_test.go diff --git a/buffalo/cmd/test.go b/buffalo/cmd/test.go index 4aaf7e36b..72db0214a 100644 --- a/buffalo/cmd/test.go +++ b/buffalo/cmd/test.go @@ -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) + if forceMigrations { fm, err := pop.NewFileMigrator("./migrations", test) @@ -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 +} \ No newline at end of file diff --git a/buffalo/cmd/test_test.go b/buffalo/cmd/test_test.go new file mode 100644 index 000000000..3e23b29dd --- /dev/null +++ b/buffalo/cmd/test_test.go @@ -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) + } + } +} \ No newline at end of file From 50d35623312448ab30cea49efd2d0adf4d92ca23 Mon Sep 17 00:00:00 2001 From: Matias Ylipelto <3822534+ypjama@users.noreply.github.com> Date: Tue, 22 Oct 2019 22:24:25 +0300 Subject: [PATCH 2/2] Remove whitespaces from empty row Suggested by fixmie Co-Authored-By: fixmie[bot] <44270338+fixmie[bot]@users.noreply.github.com> --- buffalo/cmd/test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buffalo/cmd/test.go b/buffalo/cmd/test.go index 72db0214a..fead3e989 100644 --- a/buffalo/cmd/test.go +++ b/buffalo/cmd/test.go @@ -49,7 +49,6 @@ var testCmd = &cobra.Command{ // 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) @@ -228,4 +227,4 @@ func cutArg(arg string, args []string) []string { } return args -} \ No newline at end of file +}