mirror of https://github.com/pressly/goose.git
test: add C-style comments test case to sqlparser test (#555)
parent
dec87f0abd
commit
843a23d4ff
38
Makefile
38
Makefile
|
@ -1,5 +1,13 @@
|
|||
GO_TEST_FLAGS ?= -race -count=1 -v -timeout=10m
|
||||
|
||||
# These are the default values for the test database. They can be overridden
|
||||
DB_USER ?= dbuser
|
||||
DB_PASSWORD ?= password1
|
||||
DB_NAME ?= testdb
|
||||
DB_POSTGRES_PORT ?= 5433
|
||||
DB_MYSQL_PORT ?= 3307
|
||||
DB_CLICKHOUSE_PORT ?= 9001
|
||||
|
||||
.PHONY: dist
|
||||
dist:
|
||||
@mkdir -p ./bin
|
||||
|
@ -42,11 +50,31 @@ test-e2e-vertica:
|
|||
docker-cleanup:
|
||||
docker stop -t=0 $$(docker ps --filter="label=goose_test" -aq)
|
||||
|
||||
docker-start-postgres:
|
||||
docker-postgres:
|
||||
docker run --rm -d \
|
||||
-e POSTGRES_USER=${POSTGRES_DB_USER} \
|
||||
-e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
|
||||
-e POSTGRES_DB=${POSTGRES_DBNAME} \
|
||||
-p ${POSTGRES_PORT}:5432 \
|
||||
-e POSTGRES_USER=$(DB_USER) \
|
||||
-e POSTGRES_PASSWORD=$(DB_PASSWORD) \
|
||||
-e POSTGRES_DB=$(DB_NAME) \
|
||||
-p $(DB_POSTGRES_PORT):5432 \
|
||||
-l goose_test \
|
||||
postgres:14-alpine -c log_statement=all
|
||||
|
||||
docker-mysql:
|
||||
docker run --rm -d \
|
||||
-e MYSQL_ROOT_PASSWORD=rootpassword1 \
|
||||
-e MYSQL_DATABASE=$(DB_NAME) \
|
||||
-e MYSQL_USER=$(DB_USER) \
|
||||
-e MYSQL_PASSWORD=$(DB_PASSWORD) \
|
||||
-p $(DB_MYSQL_PORT):3306 \
|
||||
-l goose_test \
|
||||
mysql:8.0.31
|
||||
|
||||
docker-clickhouse:
|
||||
docker run --rm -d \
|
||||
-e CLICKHOUSE_DB=$(DB_NAME) \
|
||||
-e CLICKHOUSE_USER=$(DB_USER) \
|
||||
-e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
|
||||
-e CLICKHOUSE_PASSWORD=$(DB_PASSWORD) \
|
||||
-p $(DB_CLICKHOUSE_PORT):9000/tcp \
|
||||
-l goose_test \
|
||||
clickhouse/clickhouse-server:23-alpine
|
||||
|
|
|
@ -379,6 +379,7 @@ func TestValidUp(t *testing.T) {
|
|||
{Name: "test05", StatementsCount: 2},
|
||||
{Name: "test06", StatementsCount: 5},
|
||||
{Name: "test07", StatementsCount: 1},
|
||||
{Name: "test08", StatementsCount: 6},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
path := filepath.Join("testdata", "valid-up", tc.Name)
|
||||
|
@ -422,7 +423,7 @@ func compareStatements(t *testing.T, dir string, statements []string) {
|
|||
by, err := os.ReadFile(goldenFilePath)
|
||||
check.NoError(t, err)
|
||||
|
||||
got, want := strings.TrimSpace(statements[index]), strings.TrimSpace(string(by))
|
||||
got, want := statements[index], string(by)
|
||||
|
||||
if got != want {
|
||||
if isCIEnvironment() {
|
||||
|
@ -433,7 +434,7 @@ func compareStatements(t *testing.T, dir string, statements []string) {
|
|||
filepath.Join("internal", "sqlparser", goldenFilePath+".FAIL"),
|
||||
filepath.Join("internal", "sqlparser", goldenFilePath),
|
||||
)
|
||||
err := os.WriteFile(goldenFilePath+".FAIL", []byte(got+"\n"), 0644)
|
||||
err := os.WriteFile(goldenFilePath+".FAIL", []byte(got), 0644)
|
||||
check.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ CREATE TABLE emp (
|
|||
salary integer,
|
||||
last_date timestamp,
|
||||
last_user text
|
||||
);
|
||||
);
|
|
@ -18,4 +18,4 @@ CREATE FUNCTION emp_stamp() RETURNS trigger AS $emp_stamp$
|
|||
NEW.last_user := current_user;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$emp_stamp$ LANGUAGE plpgsql;
|
||||
$emp_stamp$ LANGUAGE plpgsql;
|
|
@ -1,2 +1,2 @@
|
|||
CREATE TRIGGER emp_stamp BEFORE INSERT OR UPDATE ON emp
|
||||
FOR EACH ROW EXECUTE FUNCTION emp_stamp();
|
||||
FOR EACH ROW EXECUTE FUNCTION emp_stamp();
|
|
@ -30,4 +30,4 @@ $emp_audit$ LANGUAGE plpgsql;
|
|||
|
||||
CREATE TRIGGER emp_audit
|
||||
AFTER INSERT OR UPDATE OR DELETE ON emp
|
||||
FOR EACH ROW EXECUTE FUNCTION process_emp_audit();
|
||||
FOR EACH ROW EXECUTE FUNCTION process_emp_audit();
|
|
@ -29,4 +29,4 @@ BEGIN
|
|||
|
||||
EXECUTE a_output;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
' LANGUAGE 'plpgsql';
|
|
@ -1,4 +1,4 @@
|
|||
CREATE TABLE ssh_keys (
|
||||
id integer NOT NULL,
|
||||
"publicKey" text
|
||||
);
|
||||
);
|
|
@ -5,4 +5,4 @@ fkuWRZjkUvy7nfPLjzM+t6SEvY4lbn3ihLPumZjwgvuCY3vDZY8V1/NMoP8MKATGR+S7D7gv
|
|||
I6KD9jkiSsTJMiotb/dRkXE3bG0nmjchhhLzMG551G8IZEpWBHDqEisCIl8yCd9YZV69BZTu
|
||||
L48zPl/CFvA+KJJ6LklxfwWeVDQ+ve2OIW0B1uLhR/MsoYbDQztbgIayg6ieMO/KlQIDAQAB
|
||||
-----END RSA PUBLIC KEY-----
|
||||
');
|
||||
');
|
|
@ -19,4 +19,4 @@ aY9/quG9l1+eM1w8LyS7og/Vkpgu4709PhFJheeTx1uIp5aBvaTFM3kJ8d5PFg3ESW3ADG
|
|||
paaAgrG9IxDyIsgRgbULtIDqCy/jfhtgpVPvxRAAAAFQCPXzpVtY5yJTN1zBo9pTGeg+f3
|
||||
EgAAAAZub25hbWUBAgME
|
||||
-----END OPENSSH PRIVATE KEY-----
|
||||
');
|
||||
');
|
|
@ -2,4 +2,4 @@ CREATE TABLE ssh_keys (
|
|||
id integer NOT NULL,
|
||||
"publicKey" text
|
||||
-- insert comment there
|
||||
);
|
||||
);
|
|
@ -3,4 +3,4 @@ CREATE TABLE ssh_keys_backup (
|
|||
-- insert comment here
|
||||
"publicKey" text
|
||||
-- insert comment there
|
||||
);
|
||||
);
|
|
@ -1,3 +1,3 @@
|
|||
CREATE TABLE article (
|
||||
id text,
|
||||
content text);
|
||||
content text);
|
|
@ -2,4 +2,4 @@ INSERT INTO article (id, content) VALUES ('id_0001', E'# My markdown doc
|
|||
|
||||
first paragraph
|
||||
|
||||
second paragraph');
|
||||
second paragraph');
|
|
@ -7,4 +7,4 @@ first paragraph
|
|||
-- with a comment
|
||||
-- with an indent comment
|
||||
|
||||
second paragraph');
|
||||
second paragraph');
|
|
@ -9,4 +9,4 @@ BEGIN
|
|||
-- technology was successful
|
||||
RETURN 1;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
$$ LANGUAGE plpgsql;
|
|
@ -5,4 +5,4 @@ this is an insert statement including empty lines.
|
|||
empty (blank) lines can be meaningful.
|
||||
|
||||
leave the lines to keep the text syntax.
|
||||
');
|
||||
');
|
|
@ -1 +1 @@
|
|||
CREATE INDEX ON public.users (user_id);
|
||||
CREATE INDEX ON public.users (user_id);
|
|
@ -0,0 +1,5 @@
|
|||
CREATE TABLE `table_a` (
|
||||
`column_1` DATETIME DEFAULT NOW(),
|
||||
`column_2` DATETIME DEFAULT NOW(),
|
||||
`column_3` DATETIME DEFAULT NOW()
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
|
@ -0,0 +1,5 @@
|
|||
CREATE TABLE `table_b` (
|
||||
`column_1` DATETIME DEFAULT NOW(),
|
||||
`column_2` DATETIME DEFAULT NOW(),
|
||||
`column_3` DATETIME DEFAULT NOW()
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
|
@ -0,0 +1,5 @@
|
|||
CREATE TABLE `table_c` (
|
||||
`column_1` DATETIME DEFAULT NOW(),
|
||||
`column_2` DATETIME DEFAULT NOW(),
|
||||
`column_3` DATETIME DEFAULT NOW()
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
|
@ -0,0 +1 @@
|
|||
/*!80031 ALTER TABLE `table_a` MODIFY `column_1` TEXT NOT NULL */;
|
|
@ -0,0 +1 @@
|
|||
/*!80031 ALTER TABLE `table_b` MODIFY `column_2` TEXT NOT NULL */;
|
|
@ -0,0 +1 @@
|
|||
/*!80033 ALTER TABLE `table_c` MODIFY `column_3` TEXT NOT NULL */;
|
|
@ -0,0 +1,23 @@
|
|||
-- +goose Up
|
||||
|
||||
CREATE TABLE `table_a` (
|
||||
`column_1` DATETIME DEFAULT NOW(),
|
||||
`column_2` DATETIME DEFAULT NOW(),
|
||||
`column_3` DATETIME DEFAULT NOW()
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
|
||||
CREATE TABLE `table_b` (
|
||||
`column_1` DATETIME DEFAULT NOW(),
|
||||
`column_2` DATETIME DEFAULT NOW(),
|
||||
`column_3` DATETIME DEFAULT NOW()
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
|
||||
CREATE TABLE `table_c` (
|
||||
`column_1` DATETIME DEFAULT NOW(),
|
||||
`column_2` DATETIME DEFAULT NOW(),
|
||||
`column_3` DATETIME DEFAULT NOW()
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
|
||||
/*!80031 ALTER TABLE `table_a` MODIFY `column_1` TEXT NOT NULL */;
|
||||
/*!80031 ALTER TABLE `table_b` MODIFY `column_2` TEXT NOT NULL */;
|
||||
/*!80033 ALTER TABLE `table_c` MODIFY `column_3` TEXT NOT NULL */;
|
Loading…
Reference in New Issue