-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
github.com/kunitsucom/util.go v0.0.60-rc.4 h1:TGqi1YeOgfh4dScSfI6C14HDhoX2qCkbWEak5ZIV1Q4= | ||
github.com/kunitsucom/util.go v0.0.60-rc.4/go.mod h1:bYFf2JvRqVF1brBtpdt3xkkTGJBxmYBxZlItrc/lf7Y= | ||
github.com/kunitsucom/util.go v0.0.60-rc.6 h1:aiyBwQzzqxzQzWz5fZCMoj1bOWPA7iAVgju85/zXmA8= | ||
github.com/kunitsucom/util.go v0.0.60-rc.6/go.mod h1:bYFf2JvRqVF1brBtpdt3xkkTGJBxmYBxZlItrc/lf7Y= | ||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= | ||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package integrationtest_test | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
cliz "github.com/kunitsucom/util.go/exp/cli" | ||
testingz "github.com/kunitsucom/util.go/testing" | ||
"github.com/kunitsucom/util.go/testing/assert" | ||
"github.com/kunitsucom/util.go/testing/require" | ||
|
||
"github.com/kunitsucom/ddlctl/internal/ddlctl/fixture" | ||
"github.com/kunitsucom/ddlctl/pkg/ddlctl" | ||
) | ||
|
||
//nolint:paralleltest | ||
func Test_ddlctl_diff(t *testing.T) { | ||
t.Run("success,go,postgres", func(t *testing.T) { | ||
cmd := fixture.Cmd() | ||
args, err := cmd.Parse([]string{ | ||
"--lang=go", | ||
"--dialect=postgres", | ||
"postgres_before.sql", | ||
"postgres_after.sql", | ||
}) | ||
require.NoError(t, err) | ||
ctx := cliz.WithContext(context.Background(), cmd) | ||
|
||
backup := os.Stdout | ||
t.Cleanup(func() { os.Stdout = backup }) | ||
|
||
w, closeFunc, err := testingz.NewFileWriter(t) | ||
require.NoError(t, err) | ||
|
||
os.Stdout = w | ||
{ | ||
err := ddlctl.Diff(ctx, args) | ||
require.NoError(t, err) | ||
} | ||
result := closeFunc() | ||
|
||
const expected = `-- - | ||
-- +description TEXT NOT NULL | ||
ALTER TABLE public.test_groups ADD COLUMN description TEXT NOT NULL; | ||
-- -name TEXT NOT NULL | ||
-- + | ||
ALTER TABLE public.test_users DROP COLUMN name; | ||
-- - | ||
-- +username TEXT NOT NULL | ||
ALTER TABLE public.test_users ADD COLUMN username TEXT NOT NULL; | ||
` | ||
|
||
actual := result.String() | ||
|
||
assert.Equal(t, expected, actual) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE public.test_groups ( | ||
group_id UUID NOT NULL, | ||
group_name TEXT NOT NULL, | ||
description TEXT NOT NULL, | ||
PRIMARY KEY (group_id) | ||
); | ||
CREATE TABLE public.test_users ( | ||
user_id UUID NOT NULL, | ||
username TEXT NOT NULL, | ||
group_id UUID NOT NULL, | ||
PRIMARY KEY (user_id) | ||
); | ||
CREATE INDEX test_users_idx_on_group_id ON public.test_users (group_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE IF NOT EXISTS public.test_groups ( | ||
group_id UUID NOT NULL, | ||
group_name TEXT NOT NULL, | ||
PRIMARY KEY (group_id) | ||
); | ||
CREATE TABLE IF NOT EXISTS public.test_users ( | ||
user_id UUID NOT NULL, | ||
name TEXT NOT NULL, | ||
group_id UUID NOT NULL, | ||
PRIMARY KEY (user_id) | ||
); | ||
CREATE INDEX IF NOT EXISTS test_users_idx_on_group_id ON public.test_users (group_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters