From ed1a37b1c59b528c254b90c180348877a81c4f23 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Jul 2023 10:44:41 +0000 Subject: [PATCH] Move integrations -> tests (#2314) Reviewed-on: https://gitea.com/xorm/xorm/pulls/2314 --- Makefile | 2 +- {integrations => tests}/cache_test.go | 8 ++-- tests/dameng-table.sql | 19 ++++++++ tests/dameng.sql | 15 ++++++ tests/dump2-dameng-table.sql | 10 ++++ tests/dump2-sqlite3-table.sql | 3 ++ tests/dump_mssql-table.sql | 19 ++++++++ tests/dump_mssql.sql | 13 ++++++ tests/dump_mysql-table.sql | 13 ++++++ tests/dump_mysql.sql | 9 ++++ tests/dump_postgres-table.sql | 13 ++++++ tests/dump_postgres.sql | 9 ++++ tests/dump_sqlite3-table.sql | 12 +++++ tests/dump_sqlite3.sql | 8 ++++ {integrations => tests}/engine_dm_test.go | 2 +- {integrations => tests}/engine_group_test.go | 2 +- {integrations => tests}/engine_test.go | 2 +- {integrations => tests}/main_test.go | 2 +- {integrations => tests}/performance_test.go | 10 ++-- {integrations => tests}/processors_test.go | 8 ++-- {integrations => tests}/rows_test.go | 2 +- {integrations => tests}/schema_test.go | 2 +- {integrations => tests}/session_cols_test.go | 8 ++-- {integrations => tests}/session_cond_test.go | 6 +-- {integrations => tests}/session_count_test.go | 2 +- .../session_delete_test.go | 2 +- {integrations => tests}/session_exist_test.go | 6 +-- {integrations => tests}/session_find_test.go | 2 +- {integrations => tests}/session_get_test.go | 2 +- .../session_insert_test.go | 31 ++++++++----- .../session_iterate_test.go | 6 +-- {integrations => tests}/session_pk_test.go | 46 +++++++++++-------- {integrations => tests}/session_query_test.go | 2 +- {integrations => tests}/session_raw_test.go | 2 +- {integrations => tests}/session_sum_test.go | 38 +++++++-------- {integrations => tests}/session_test.go | 2 +- {integrations => tests}/session_tx_test.go | 7 ++- .../session_update_test.go | 2 +- tests/sqlite3-table.sql | 12 +++++ tests/sqlite3.sql | 8 ++++ {integrations => tests}/tags_test.go | 2 +- {integrations => tests}/testdata/import1.sql | 0 {integrations => tests}/testdata/import2.sql | 0 {integrations => tests}/tests.go | 4 +- {integrations => tests}/time_test.go | 41 +++++++++-------- {integrations => tests}/types_null_test.go | 2 +- {integrations => tests}/types_test.go | 2 +- 47 files changed, 294 insertions(+), 124 deletions(-) rename {integrations => tests}/cache_test.go (97%) create mode 100644 tests/dameng-table.sql create mode 100644 tests/dameng.sql create mode 100644 tests/dump2-dameng-table.sql create mode 100644 tests/dump2-sqlite3-table.sql create mode 100644 tests/dump_mssql-table.sql create mode 100644 tests/dump_mssql.sql create mode 100644 tests/dump_mysql-table.sql create mode 100644 tests/dump_mysql.sql create mode 100644 tests/dump_postgres-table.sql create mode 100644 tests/dump_postgres.sql create mode 100644 tests/dump_sqlite3-table.sql create mode 100644 tests/dump_sqlite3.sql rename {integrations => tests}/engine_dm_test.go (93%) rename {integrations => tests}/engine_group_test.go (97%) rename {integrations => tests}/engine_test.go (99%) rename {integrations => tests}/main_test.go (91%) rename {integrations => tests}/performance_test.go (92%) rename {integrations => tests}/processors_test.go (99%) rename {integrations => tests}/rows_test.go (99%) rename {integrations => tests}/schema_test.go (99%) rename {integrations => tests}/session_cols_test.go (97%) rename {integrations => tests}/session_cond_test.go (98%) rename {integrations => tests}/session_count_test.go (99%) rename {integrations => tests}/session_delete_test.go (99%) rename {integrations => tests}/session_exist_test.go (98%) rename {integrations => tests}/session_find_test.go (99%) rename {integrations => tests}/session_get_test.go (99%) rename {integrations => tests}/session_insert_test.go (98%) rename {integrations => tests}/session_iterate_test.go (98%) rename {integrations => tests}/session_pk_test.go (97%) rename {integrations => tests}/session_query_test.go (99%) rename {integrations => tests}/session_raw_test.go (99%) rename {integrations => tests}/session_sum_test.go (92%) rename {integrations => tests}/session_test.go (98%) rename {integrations => tests}/session_tx_test.go (98%) rename {integrations => tests}/session_update_test.go (99%) create mode 100644 tests/sqlite3-table.sql create mode 100644 tests/sqlite3.sql rename {integrations => tests}/tags_test.go (99%) rename {integrations => tests}/testdata/import1.sql (100%) rename {integrations => tests}/testdata/import2.sql (100%) rename {integrations => tests}/tests.go (98%) rename {integrations => tests}/time_test.go (96%) rename {integrations => tests}/types_null_test.go (99%) rename {integrations => tests}/types_test.go (99%) diff --git a/Makefile b/Makefile index ade90e6d..55183557 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ SED_INPLACE := sed -i GO_DIRS := caches contexts integrations core dialects internal log migrate names schemas tags GOFILES := $(wildcard *.go) GOFILES += $(shell find $(GO_DIRS) -name "*.go" -type f) -INTEGRATION_PACKAGES := xorm.io/xorm/integrations +INTEGRATION_PACKAGES := xorm.io/xorm/tests PACKAGES ?= $(filter-out $(INTEGRATION_PACKAGES),$(shell $(GO) list ./...)) TEST_COCKROACH_HOST ?= cockroach:26257 diff --git a/integrations/cache_test.go b/tests/cache_test.go similarity index 97% rename from integrations/cache_test.go rename to tests/cache_test.go index 2caeaa34..c3f84c77 100644 --- a/integrations/cache_test.go +++ b/tests/cache_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" @@ -28,7 +28,7 @@ func TestCacheFind(t *testing.T) { assert.NoError(t, testEngine.Sync(new(MailBox))) - var inserts = []*MailBox{ + inserts := []*MailBox{ { Id: 0, Username: "user1", @@ -105,7 +105,7 @@ func TestCacheFind2(t *testing.T) { assert.NoError(t, testEngine.Sync(new(MailBox2))) - var inserts = []*MailBox2{ + inserts := []*MailBox2{ { Id: 0, Username: "user1", @@ -156,7 +156,7 @@ func TestCacheGet(t *testing.T) { assert.NoError(t, testEngine.Sync(new(MailBox3))) - var inserts = []*MailBox3{ + inserts := []*MailBox3{ { Username: "user1", Password: "pass1", diff --git a/tests/dameng-table.sql b/tests/dameng-table.sql new file mode 100644 index 00000000..d8e0e077 --- /dev/null +++ b/tests/dameng-table.sql @@ -0,0 +1,19 @@ +/*Generated by xorm 2023-07-12 16:59:56, from dameng to dameng*/ + +CREATE SEQUENCE SEQ_TEST_DUMP_TABLE_STRUCT + minvalue 1 + nomaxvalue + start with 1 + increment by 1 + nocycle + nocache; +CREATE TABLE "test_dump_table_struct" ("id" BIGINT NOT NULL, "data" VARBINARY NULL, "name" VARCHAR2(255) NULL, "is_man" BIT NULL, "created" TIMESTAMP NULL, CONSTRAINT PK_test_dump_table_struct PRIMARY KEY ("id")); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (1,'',CONCAT('1'),1,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (2,HEXTORAW('000102'),CONCAT('2', CHAR(10)),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (3,HEXTORAW('3078303030313032'),CONCAT('3;'),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (4,HEXTORAW('48656c70'),CONCAT('4', CHAR(10), ';', CHAR(10), ''''''),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (5,HEXTORAW('30783438363536633730'),CONCAT('5''', CHAR(10)),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (6,HEXTORAW('3438363536633730'),CONCAT('6\n''', CHAR(10)),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (7,HEXTORAW('375c6e270d0a'),CONCAT('7\n''', CHAR(13), CHAR(10)),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (8,'',CONCAT('x0809ee'),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (9,'',CONCAT('090a10'),0,CONCAT('2023-07-12 16:59:56')); diff --git a/tests/dameng.sql b/tests/dameng.sql new file mode 100644 index 00000000..713aa964 --- /dev/null +++ b/tests/dameng.sql @@ -0,0 +1,15 @@ +/*Generated by xorm 2023-07-12 16:59:56, from dameng to dameng*/ + +CREATE SEQUENCE SEQ_TEST_DUMP_STRUCT + minvalue 1 + nomaxvalue + start with 1 + increment by 1 + nocycle + nocache; +CREATE TABLE "test_dump_struct" ("id" BIGINT NOT NULL, "name" VARCHAR2(255) NULL, "is_man" BIT NULL, "created" TIMESTAMP(6) NULL, CONSTRAINT PK_test_dump_struct PRIMARY KEY ("id")); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (1,CONCAT('1'),1,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (2,CONCAT('2', CHAR(10)),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (3,CONCAT('3;'),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (4,CONCAT('4', CHAR(10), ';', CHAR(10), ''''''),0,CONCAT('2023-07-12 16:59:56')); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (5,CONCAT('5''', CHAR(10)),0,CONCAT('2023-07-12 16:59:56')); diff --git a/tests/dump2-dameng-table.sql b/tests/dump2-dameng-table.sql new file mode 100644 index 00000000..73961064 --- /dev/null +++ b/tests/dump2-dameng-table.sql @@ -0,0 +1,10 @@ +/*Generated by xorm 2023-07-12 16:59:56, from dameng to dameng*/ + +CREATE SEQUENCE SEQ_TEST_DUMP_TABLE_STRUCT2 + minvalue 1 + nomaxvalue + start with 1 + increment by 1 + nocycle + nocache; +CREATE TABLE "test_dump_table_struct2" ("id" BIGINT NOT NULL, "created" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL, CONSTRAINT PK_test_dump_table_struct2 PRIMARY KEY ("id")); diff --git a/tests/dump2-sqlite3-table.sql b/tests/dump2-sqlite3-table.sql new file mode 100644 index 00000000..a35a1e97 --- /dev/null +++ b/tests/dump2-sqlite3-table.sql @@ -0,0 +1,3 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to sqlite3*/ + +CREATE TABLE IF NOT EXISTS `test_dump_table_struct2` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `created` DATETIME DEFAULT CURRENT_TIMESTAMP NULL); diff --git a/tests/dump_mssql-table.sql b/tests/dump_mssql-table.sql new file mode 100644 index 00000000..b0152bcc --- /dev/null +++ b/tests/dump_mssql-table.sql @@ -0,0 +1,19 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to mssql*/ + +IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = '[test_dump_table_struct]' ) CREATE TABLE [test_dump_table_struct] ([id] BIGINT PRIMARY KEY IDENTITY NOT NULL, [data] VARBINARY(MAX) NULL, [name] VARCHAR(255) NULL, [is_man] BIT NULL, [created] DATETIME NULL); +SET IDENTITY_INSERT [test_dump_table_struct] ON; +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (1,NULL,N'1',1,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (2,CONVERT(VARBINARY(MAX), '0x000102', 1),N'2 +',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (3,CONVERT(VARBINARY(MAX), '0x3078303030313032', 1),N'3;',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (4,CONVERT(VARBINARY(MAX), '0x48656c70', 1),N'4 +; +''''',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (5,CONVERT(VARBINARY(MAX), '0x30783438363536633730', 1),N'5'' +',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (6,CONVERT(VARBINARY(MAX), '0x3438363536633730', 1),N'6\n'' +',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (7,CONVERT(VARBINARY(MAX), '0x375c6e270d0a', 1),N'7\n'' +',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (8,NULL,N'x0809ee',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_table_struct] ([id], [data], [name], [is_man], [created]) VALUES (9,NULL,N'090a10',0,N'2023-07-26T08:06:45Z'); diff --git a/tests/dump_mssql.sql b/tests/dump_mssql.sql new file mode 100644 index 00000000..803d1aec --- /dev/null +++ b/tests/dump_mssql.sql @@ -0,0 +1,13 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to mssql*/ + +IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = '[test_dump_struct]' ) CREATE TABLE [test_dump_struct] ([id] INTEGER PRIMARY KEY IDENTITY NOT NULL, [name] VARCHAR(MAX) NULL, [is_man] INTEGER NULL, [created] DATETIME NULL); +SET IDENTITY_INSERT [test_dump_struct] ON; +INSERT INTO [test_dump_struct] ([id], [name], [is_man], [created]) VALUES (1,N'1',1,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_struct] ([id], [name], [is_man], [created]) VALUES (2,N'2 +',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_struct] ([id], [name], [is_man], [created]) VALUES (3,N'3;',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_struct] ([id], [name], [is_man], [created]) VALUES (4,N'4 +; +''''',0,N'2023-07-26T08:06:45Z'); +INSERT INTO [test_dump_struct] ([id], [name], [is_man], [created]) VALUES (5,N'5'' +',0,N'2023-07-26T08:06:45Z'); diff --git a/tests/dump_mysql-table.sql b/tests/dump_mysql-table.sql new file mode 100644 index 00000000..096ea742 --- /dev/null +++ b/tests/dump_mysql-table.sql @@ -0,0 +1,13 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to mysql*/ + +SET sql_mode='NO_BACKSLASH_ESCAPES'; +CREATE TABLE IF NOT EXISTS `test_dump_table_struct` (`id` BIGINT(20) PRIMARY KEY AUTO_INCREMENT NOT NULL, `data` BLOB NULL, `name` VARCHAR(255) NULL, `is_man` TINYINT(1) NULL, `created` DATETIME NULL); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (1,NULL,'1',1,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (2,CONCAT(CHAR(0), CHAR(1), CHAR(2)),CONCAT('2', CHAR(10)),0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (3,'0x000102','3;',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (4,'Help',CONCAT('4', CHAR(10), ';', CHAR(10), ''''''),0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (5,'0x48656c70',CONCAT('5''', CHAR(10)),0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (6,'48656c70',CONCAT('6\n''', CHAR(10)),0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (7,CONCAT('7\n''', CHAR(13), CHAR(10)),CONCAT('7\n''', CHAR(13), CHAR(10)),0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (8,NULL,'x0809ee',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (9,NULL,'090a10',0,'2023-07-26T08:06:45Z'); diff --git a/tests/dump_mysql.sql b/tests/dump_mysql.sql new file mode 100644 index 00000000..a2acff19 --- /dev/null +++ b/tests/dump_mysql.sql @@ -0,0 +1,9 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to mysql*/ + +SET sql_mode='NO_BACKSLASH_ESCAPES'; +CREATE TABLE IF NOT EXISTS `test_dump_struct` (`id` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, `name` TEXT NULL, `is_man` INTEGER NULL, `created` DATETIME NULL); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (1,'1',1,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (2,CONCAT('2', CHAR(10)),0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (3,'3;',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (4,CONCAT('4', CHAR(10), ';', CHAR(10), ''''''),0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (5,CONCAT('5''', CHAR(10)),0,'2023-07-26T08:06:45Z'); diff --git a/tests/dump_postgres-table.sql b/tests/dump_postgres-table.sql new file mode 100644 index 00000000..28a4e4d6 --- /dev/null +++ b/tests/dump_postgres-table.sql @@ -0,0 +1,13 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to postgres*/ + +CREATE TABLE IF NOT EXISTS "public"."test_dump_table_struct" ("id" BIGSERIAL PRIMARY KEY NOT NULL, "data" BYTEA NULL, "name" VARCHAR(255) NULL, "is_man" BOOL NULL, "created" TIMESTAMP NULL); ; +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (1,NULL,'1',true,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (2,'\x000102','2' || e'\x0a',false,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (3,'\x3078303030313032','3;',false,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (4,'\x48656c70','4' || e'\x0a' || ';' || e'\x0a' || '''''',false,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (5,'\x30783438363536633730','5''' || e'\x0a',false,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (6,'\x3438363536633730','6\n''' || e'\x0a',false,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (7,'\x375c6e270d0a','7\n''' || e'\x0d\x0a',false,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (8,NULL,'x0809ee',false,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_table_struct" ("id", "data", "name", "is_man", "created") VALUES (9,NULL,'090a10',false,'2023-07-26T08:06:45Z'); +SELECT setval('test_dump_table_struct_id_seq', COALESCE((SELECT MAX(id) + 1 FROM "test_dump_table_struct"), 1), false); diff --git a/tests/dump_postgres.sql b/tests/dump_postgres.sql new file mode 100644 index 00000000..5b45b550 --- /dev/null +++ b/tests/dump_postgres.sql @@ -0,0 +1,9 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to postgres*/ + +CREATE TABLE IF NOT EXISTS "public"."test_dump_struct" ("id" SERIAL PRIMARY KEY NOT NULL, "name" TEXT NULL, "is_man" INTEGER NULL, "created" TIMESTAMP NULL); ; +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (1,'1',1,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (2,'2' || e'\x0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (3,'3;',0,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (4,'4' || e'\x0a' || ';' || e'\x0a' || '''''',0,'2023-07-26T08:06:45Z'); +INSERT INTO "test_dump_struct" ("id", "name", "is_man", "created") VALUES (5,'5''' || e'\x0a',0,'2023-07-26T08:06:45Z'); +SELECT setval('test_dump_struct_id_seq', COALESCE((SELECT MAX(id) + 1 FROM "test_dump_struct"), 1), false); diff --git a/tests/dump_sqlite3-table.sql b/tests/dump_sqlite3-table.sql new file mode 100644 index 00000000..d271b658 --- /dev/null +++ b/tests/dump_sqlite3-table.sql @@ -0,0 +1,12 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to sqlite3*/ + +CREATE TABLE IF NOT EXISTS `test_dump_table_struct` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `data` BLOB NULL, `name` TEXT NULL, `is_man` INTEGER NULL, `created` DATETIME NULL); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (1,NULL,'1',1,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (2,X'000102','2' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (3,X'3078303030313032','3;',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (4,X'48656c70','4' || X'0a' || ';' || X'0a' || '''''',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (5,X'30783438363536633730','5''' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (6,X'3438363536633730','6\n''' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (7,X'375c6e270d0a','7\n''' || X'0d0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (8,NULL,'x0809ee',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (9,NULL,'090a10',0,'2023-07-26T08:06:45Z'); diff --git a/tests/dump_sqlite3.sql b/tests/dump_sqlite3.sql new file mode 100644 index 00000000..eba68553 --- /dev/null +++ b/tests/dump_sqlite3.sql @@ -0,0 +1,8 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to sqlite3*/ + +CREATE TABLE IF NOT EXISTS `test_dump_struct` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NULL, `is_man` INTEGER NULL, `created` DATETIME NULL); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (1,'1',1,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (2,'2' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (3,'3;',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (4,'4' || X'0a' || ';' || X'0a' || '''''',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (5,'5''' || X'0a',0,'2023-07-26T08:06:45Z'); diff --git a/integrations/engine_dm_test.go b/tests/engine_dm_test.go similarity index 93% rename from integrations/engine_dm_test.go rename to tests/engine_dm_test.go index 3b195ef8..5b25af29 100644 --- a/integrations/engine_dm_test.go +++ b/tests/engine_dm_test.go @@ -5,7 +5,7 @@ //go:build dm // +build dm -package integrations +package tests import "xorm.io/xorm/schemas" diff --git a/integrations/engine_group_test.go b/tests/engine_group_test.go similarity index 97% rename from integrations/engine_group_test.go rename to tests/engine_group_test.go index 635f73a6..629e0aa4 100644 --- a/integrations/engine_group_test.go +++ b/tests/engine_group_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" diff --git a/integrations/engine_test.go b/tests/engine_test.go similarity index 99% rename from integrations/engine_test.go rename to tests/engine_test.go index 86ed7344..79ca42f5 100644 --- a/integrations/engine_test.go +++ b/tests/engine_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "context" diff --git a/integrations/main_test.go b/tests/main_test.go similarity index 91% rename from integrations/main_test.go rename to tests/main_test.go index 225ae45a..ab0ee802 100644 --- a/integrations/main_test.go +++ b/tests/main_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" diff --git a/integrations/performance_test.go b/tests/performance_test.go similarity index 92% rename from integrations/performance_test.go rename to tests/performance_test.go index 49183717..d1d12161 100644 --- a/integrations/performance_test.go +++ b/tests/performance_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" @@ -23,7 +23,7 @@ func BenchmarkGetVars(b *testing.B) { assert.NoError(b, testEngine.Sync(new(BenchmarkGetVars))) - var v = BenchmarkGetVars{ + v := BenchmarkGetVars{ Name: "myname", } _, err := testEngine.Insert(&v) @@ -54,7 +54,7 @@ func BenchmarkGetStruct(b *testing.B) { assert.NoError(b, testEngine.Sync(new(BenchmarkGetStruct))) - var v = BenchmarkGetStruct{ + v := BenchmarkGetStruct{ Name: "myname", } _, err := testEngine.Insert(&v) @@ -86,13 +86,13 @@ func BenchmarkFindStruct(b *testing.B) { assert.NoError(b, testEngine.Sync(new(BenchmarkFindStruct))) - var v = BenchmarkFindStruct{ + v := BenchmarkFindStruct{ Name: "myname", } _, err := testEngine.Insert(&v) assert.NoError(b, err) - var mynames = make([]BenchmarkFindStruct, 0, 1) + mynames := make([]BenchmarkFindStruct, 0, 1) b.StartTimer() for i := 0; i < b.N; i++ { err := testEngine.Find(&mynames) diff --git a/integrations/processors_test.go b/tests/processors_test.go similarity index 99% rename from integrations/processors_test.go rename to tests/processors_test.go index 4c383437..af2866e8 100644 --- a/integrations/processors_test.go +++ b/tests/processors_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "errors" @@ -200,7 +200,7 @@ func TestProcessors(t *testing.T) { // -- // test find map processors - var p2FindMap = make(map[int64]*ProcessorsStruct) + p2FindMap := make(map[int64]*ProcessorsStruct) err = testEngine.Find(&p2FindMap) assert.NoError(t, err) @@ -848,13 +848,13 @@ func TestAfterLoadProcessor(t *testing.T) { assertSync(t, new(AfterLoadStructA), new(AfterLoadStructB)) - var a = AfterLoadStructA{ + a := AfterLoadStructA{ Content: "testa", } _, err := testEngine.Insert(&a) assert.NoError(t, err) - var b = AfterLoadStructB{ + b := AfterLoadStructB{ Content: "testb", AId: a.Id, } diff --git a/integrations/rows_test.go b/tests/rows_test.go similarity index 99% rename from integrations/rows_test.go rename to tests/rows_test.go index e354b75e..fe4f374c 100644 --- a/integrations/rows_test.go +++ b/tests/rows_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" diff --git a/integrations/schema_test.go b/tests/schema_test.go similarity index 99% rename from integrations/schema_test.go rename to tests/schema_test.go index 149c6394..c945a35c 100644 --- a/integrations/schema_test.go +++ b/tests/schema_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "errors" diff --git a/integrations/session_cols_test.go b/tests/session_cols_test.go similarity index 97% rename from integrations/session_cols_test.go rename to tests/session_cols_test.go index 462ea7c7..4a6ef39f 100644 --- a/integrations/session_cols_test.go +++ b/tests/session_cols_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" @@ -22,7 +22,7 @@ func TestSetExpr(t *testing.T) { assert.NoError(t, testEngine.Sync(new(UserExprIssue))) - var issue = UserExprIssue{ + issue := UserExprIssue{ Title: "my issue", } cnt, err := testEngine.Insert(&issue) @@ -44,7 +44,7 @@ func TestSetExpr(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, 1, cnt) - var not = "NOT" + not := "NOT" if testEngine.Dialect().URI().DBType == schemas.MSSQL || testEngine.Dialect().URI().DBType == schemas.DAMENG { not = "~" } @@ -118,7 +118,7 @@ func TestMustCol(t *testing.T) { assertSync(t, new(CustomerUpdate)) - var customer = CustomerUpdate{ + customer := CustomerUpdate{ ParentId: 1, } cnt, err := testEngine.Insert(&customer) diff --git a/integrations/session_cond_test.go b/tests/session_cond_test.go similarity index 98% rename from integrations/session_cond_test.go rename to tests/session_cond_test.go index 0597d74e..cbcd0cb5 100644 --- a/integrations/session_cond_test.go +++ b/tests/session_cond_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "errors" @@ -37,7 +37,7 @@ func TestBuilder(t *testing.T) { assert.NoError(t, err) var cond Condition - var q = testEngine.Quote + q := testEngine.Quote has, err := testEngine.Where(builder.Eq{q("col_name"): "col1"}).Get(&cond) assert.NoError(t, err) assert.Equal(t, true, has, "records should exist") @@ -90,7 +90,7 @@ func TestBuilder(t *testing.T) { assert.EqualValues(t, 0, len(conds), "records should not exist") // complex condtions - var where = builder.NewCond() + where := builder.NewCond() if true { where = where.And(builder.Eq{q("col_name"): "col1"}) where = where.Or(builder.And(builder.In(q("col_name"), "col1", "col2"), builder.Expr(q("col_name")+" = ?", "col1"))) diff --git a/integrations/session_count_test.go b/tests/session_count_test.go similarity index 99% rename from integrations/session_count_test.go rename to tests/session_count_test.go index c6e64e76..24c5d24a 100644 --- a/integrations/session_count_test.go +++ b/tests/session_count_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" diff --git a/integrations/session_delete_test.go b/tests/session_delete_test.go similarity index 99% rename from integrations/session_delete_test.go rename to tests/session_delete_test.go index 1ed3e706..44d4ad7d 100644 --- a/integrations/session_delete_test.go +++ b/tests/session_delete_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "os" diff --git a/integrations/session_exist_test.go b/tests/session_exist_test.go similarity index 98% rename from integrations/session_exist_test.go rename to tests/session_exist_test.go index ca1e66ad..a9e3a6a8 100644 --- a/integrations/session_exist_test.go +++ b/tests/session_exist_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "context" @@ -106,14 +106,14 @@ func TestExistStructForJoin(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, 1, cnt) - var orderlist = OrderList{ + orderlist := OrderList{ Eid: ply.Id, } cnt, err = testEngine.Insert(&orderlist) assert.NoError(t, err) assert.EqualValues(t, 1, cnt) - var um = Number{ + um := Number{ Lid: orderlist.Id, } cnt, err = testEngine.Insert(&um) diff --git a/integrations/session_find_test.go b/tests/session_find_test.go similarity index 99% rename from integrations/session_find_test.go rename to tests/session_find_test.go index 65df5aee..2a754e2a 100644 --- a/integrations/session_find_test.go +++ b/tests/session_find_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" diff --git a/integrations/session_get_test.go b/tests/session_get_test.go similarity index 99% rename from integrations/session_get_test.go rename to tests/session_get_test.go index d3403814..2ff2f67d 100644 --- a/integrations/session_get_test.go +++ b/tests/session_get_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "database/sql" diff --git a/integrations/session_insert_test.go b/tests/session_insert_test.go similarity index 98% rename from integrations/session_insert_test.go rename to tests/session_insert_test.go index 084deb38..e45e6e54 100644 --- a/integrations/session_insert_test.go +++ b/tests/session_insert_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "fmt" @@ -142,8 +142,13 @@ func TestInsert(t *testing.T) { assert.NoError(t, PrepareEngine()) assertSync(t, new(Userinfo)) - user := Userinfo{0, "xiaolunwen", "dev", "lunny", time.Now(), - Userdetail{Id: 1}, 1.78, []byte{1, 2, 3}, true} + user := Userinfo{ + 0, "xiaolunwen", "dev", "lunny", time.Now(), + Userdetail{Id: 1}, + 1.78, + []byte{1, 2, 3}, + true, + } cnt, err := testEngine.Insert(&user) assert.NoError(t, err) assert.EqualValues(t, 1, cnt, "insert not returned 1") @@ -161,8 +166,10 @@ func TestInsertAutoIncr(t *testing.T) { assertSync(t, new(Userinfo)) // auto increment insert - user := Userinfo{Username: "xiaolunwen2", Departname: "dev", Alias: "lunny", Created: time.Now(), - Detail: Userdetail{Id: 1}, Height: 1.78, Avatar: []byte{1, 2, 3}, IsMan: true} + user := Userinfo{ + Username: "xiaolunwen2", Departname: "dev", Alias: "lunny", Created: time.Now(), + Detail: Userdetail{Id: 1}, Height: 1.78, Avatar: []byte{1, 2, 3}, IsMan: true, + } cnt, err := testEngine.Insert(&user) assert.NoError(t, err) assert.EqualValues(t, 1, cnt) @@ -184,7 +191,7 @@ func TestInsertDefault(t *testing.T) { err := testEngine.Sync(di) assert.NoError(t, err) - var di2 = DefaultInsert{Name: "test"} + di2 := DefaultInsert{Name: "test"} _, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("Status")).Insert(&di2) assert.NoError(t, err) @@ -210,7 +217,7 @@ func TestInsertDefault2(t *testing.T) { err := testEngine.Sync(di) assert.NoError(t, err) - var di2 = DefaultInsert2{Name: "test"} + di2 := DefaultInsert2{Name: "test"} _, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("CheckTime")).Insert(&di2) assert.NoError(t, err) @@ -438,7 +445,7 @@ func TestCreatedJsonTime(t *testing.T) { assert.True(t, has) assert.EqualValues(t, time.Time(ci5.Created).Unix(), time.Time(di5.Created).Unix()) - var dis = make([]MyJSONTime, 0) + dis := make([]MyJSONTime, 0) err = testEngine.Find(&dis) assert.NoError(t, err) } @@ -762,7 +769,7 @@ func TestInsertWhere(t *testing.T) { assert.NoError(t, PrepareEngine()) assertSync(t, new(InsertWhere)) - var i = InsertWhere{ + i := InsertWhere{ RepoId: 1, Width: 10, Height: 20, @@ -872,7 +879,7 @@ func TestInsertExpr2(t *testing.T) { assertSync(t, new(InsertExprsRelease)) - var ie = InsertExprsRelease{ + ie := InsertExprsRelease{ RepoId: 1, IsTag: true, } @@ -1047,7 +1054,7 @@ func TestInsertIntSlice(t *testing.T) { assert.NoError(t, testEngine.Sync(new(InsertIntSlice))) - var v = InsertIntSlice{ + v := InsertIntSlice{ NameIDs: []int{1, 2}, } cnt, err := testEngine.Insert(&v) @@ -1064,7 +1071,7 @@ func TestInsertIntSlice(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, 1, cnt) - var v3 = InsertIntSlice{ + v3 := InsertIntSlice{ NameIDs: nil, } cnt, err = testEngine.Insert(&v3) diff --git a/integrations/session_iterate_test.go b/tests/session_iterate_test.go similarity index 98% rename from integrations/session_iterate_test.go rename to tests/session_iterate_test.go index c5ecc593..f2e36899 100644 --- a/integrations/session_iterate_test.go +++ b/tests/session_iterate_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "testing" @@ -59,7 +59,7 @@ func TestBufferIterate(t *testing.T) { assert.NoError(t, testEngine.Sync(new(UserBufferIterate))) - var size = 20 + size := 20 for i := 0; i < size; i++ { cnt, err := testEngine.Insert(&UserBufferIterate{ IsMan: true, @@ -68,7 +68,7 @@ func TestBufferIterate(t *testing.T) { assert.EqualValues(t, 1, cnt) } - var cnt = 0 + cnt := 0 err := testEngine.BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean interface{}) error { user := bean.(*UserBufferIterate) assert.EqualValues(t, cnt+1, user.Id) diff --git a/integrations/session_pk_test.go b/tests/session_pk_test.go similarity index 97% rename from integrations/session_pk_test.go rename to tests/session_pk_test.go index 0244937f..43de4eea 100644 --- a/integrations/session_pk_test.go +++ b/tests/session_pk_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "sort" @@ -53,17 +53,21 @@ type StringPK struct { Name string } -type ID int64 -type MyIntPK struct { - ID ID `xorm:"pk autoincr"` - Name string -} +type ( + ID int64 + MyIntPK struct { + ID ID `xorm:"pk autoincr"` + Name string + } +) -type StrID string -type MyStringPK struct { - ID StrID `xorm:"pk notnull"` - Name string -} +type ( + StrID string + MyStringPK struct { + ID StrID `xorm:"pk notnull"` + Name string + } +) func TestIntId(t *testing.T) { assert.NoError(t, PrepareEngine()) @@ -187,7 +191,7 @@ func TestUintId(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, 1, cnt) - var inserts = []UintId{ + inserts := []UintId{ {Name: "test1"}, {Name: "test2"}, } @@ -390,7 +394,7 @@ func TestCompositeKey(t *testing.T) { assert.True(t, has) assert.EqualValues(t, compositeKeyVal, compositeKeyVal2) - var cps = make([]CompositeKey, 0) + cps := make([]CompositeKey, 0) err = testEngine.Find(&cps) assert.NoError(t, err) assert.EqualValues(t, 1, len(cps)) @@ -460,13 +464,15 @@ func TestCompositeKey2(t *testing.T) { assert.EqualValues(t, 1, cnt) } -type MyString string -type UserPK2 struct { - UserId MyString `xorm:"varchar(19) not null pk"` - NickName string `xorm:"varchar(19) not null"` - GameId uint32 `xorm:"integer pk"` - Score int32 `xorm:"integer"` -} +type ( + MyString string + UserPK2 struct { + UserId MyString `xorm:"varchar(19) not null pk"` + NickName string `xorm:"varchar(19) not null"` + GameId uint32 `xorm:"integer pk"` + Score int32 `xorm:"integer"` + } +) func TestCompositeKey3(t *testing.T) { assert.NoError(t, PrepareEngine()) diff --git a/integrations/session_query_test.go b/tests/session_query_test.go similarity index 99% rename from integrations/session_query_test.go rename to tests/session_query_test.go index ff62f25d..5a3a3631 100644 --- a/integrations/session_query_test.go +++ b/tests/session_query_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "bytes" diff --git a/integrations/session_raw_test.go b/tests/session_raw_test.go similarity index 99% rename from integrations/session_raw_test.go rename to tests/session_raw_test.go index 5fa48d6e..e6987c41 100644 --- a/integrations/session_raw_test.go +++ b/tests/session_raw_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "strconv" diff --git a/integrations/session_sum_test.go b/tests/session_sum_test.go similarity index 92% rename from integrations/session_sum_test.go rename to tests/session_sum_test.go index e000233b..926269ee 100644 --- a/integrations/session_sum_test.go +++ b/tests/session_sum_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "fmt" @@ -25,13 +25,11 @@ func TestSum(t *testing.T) { assert.NoError(t, PrepareEngine()) assert.NoError(t, testEngine.Sync(new(SumStruct))) - var ( - cases = []SumStruct{ - {1, 6.2}, - {2, 5.3}, - {92, -0.2}, - } - ) + cases := []SumStruct{ + {1, 6.2}, + {2, 5.3}, + {92, -0.2}, + } var i int var f float32 @@ -84,13 +82,11 @@ func TestSumWithTableName(t *testing.T) { assert.NoError(t, PrepareEngine()) assert.NoError(t, testEngine.Sync(new(SumStructWithTableName))) - var ( - cases = []SumStructWithTableName{ - {1, 6.2}, - {2, 5.3}, - {92, -0.2}, - } - ) + cases := []SumStructWithTableName{ + {1, 6.2}, + {2, 5.3}, + {92, -0.2}, + } var i int var f float32 @@ -138,13 +134,11 @@ func TestSumCustomColumn(t *testing.T) { Float float32 } - var ( - cases = []SumStruct2{ - {1, 6.2}, - {2, 5.3}, - {92, -0.2}, - } - ) + cases := []SumStruct2{ + {1, 6.2}, + {2, 5.3}, + {92, -0.2}, + } assert.NoError(t, testEngine.Sync(new(SumStruct2))) diff --git a/integrations/session_test.go b/tests/session_test.go similarity index 98% rename from integrations/session_test.go rename to tests/session_test.go index a36b81bf..261f2c48 100644 --- a/integrations/session_test.go +++ b/tests/session_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "database/sql" diff --git a/integrations/session_tx_test.go b/tests/session_tx_test.go similarity index 98% rename from integrations/session_tx_test.go rename to tests/session_tx_test.go index 890e755d..c9db40ba 100644 --- a/integrations/session_tx_test.go +++ b/tests/session_tx_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "fmt" @@ -24,7 +24,7 @@ func TestTransaction(t *testing.T) { } counter(t) - //defer counter() + // defer counter() session := testEngine.NewSession() defer session.Close() @@ -58,7 +58,7 @@ func TestCombineTransaction(t *testing.T) { } counter() - //defer counter() + // defer counter() session := testEngine.NewSession() defer session.Close() @@ -187,7 +187,6 @@ func TestMultipleTransaction(t *testing.T) { } func TestInsertMulti2InterfaceTransaction(t *testing.T) { - type Multi2InterfaceTransaction struct { ID uint64 `xorm:"id pk autoincr"` Name string diff --git a/integrations/session_update_test.go b/tests/session_update_test.go similarity index 99% rename from integrations/session_update_test.go rename to tests/session_update_test.go index 2a8f8187..c13468d9 100644 --- a/integrations/session_update_test.go +++ b/tests/session_update_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "fmt" diff --git a/tests/sqlite3-table.sql b/tests/sqlite3-table.sql new file mode 100644 index 00000000..d271b658 --- /dev/null +++ b/tests/sqlite3-table.sql @@ -0,0 +1,12 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to sqlite3*/ + +CREATE TABLE IF NOT EXISTS `test_dump_table_struct` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `data` BLOB NULL, `name` TEXT NULL, `is_man` INTEGER NULL, `created` DATETIME NULL); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (1,NULL,'1',1,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (2,X'000102','2' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (3,X'3078303030313032','3;',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (4,X'48656c70','4' || X'0a' || ';' || X'0a' || '''''',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (5,X'30783438363536633730','5''' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (6,X'3438363536633730','6\n''' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (7,X'375c6e270d0a','7\n''' || X'0d0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (8,NULL,'x0809ee',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_table_struct` (`id`, `data`, `name`, `is_man`, `created`) VALUES (9,NULL,'090a10',0,'2023-07-26T08:06:45Z'); diff --git a/tests/sqlite3.sql b/tests/sqlite3.sql new file mode 100644 index 00000000..eba68553 --- /dev/null +++ b/tests/sqlite3.sql @@ -0,0 +1,8 @@ +/*Generated by xorm 2023-07-26 16:06:45, from sqlite3 to sqlite3*/ + +CREATE TABLE IF NOT EXISTS `test_dump_struct` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NULL, `is_man` INTEGER NULL, `created` DATETIME NULL); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (1,'1',1,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (2,'2' || X'0a',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (3,'3;',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (4,'4' || X'0a' || ';' || X'0a' || '''''',0,'2023-07-26T08:06:45Z'); +INSERT INTO `test_dump_struct` (`id`, `name`, `is_man`, `created`) VALUES (5,'5''' || X'0a',0,'2023-07-26T08:06:45Z'); diff --git a/integrations/tags_test.go b/tests/tags_test.go similarity index 99% rename from integrations/tags_test.go rename to tests/tags_test.go index 4c33d56c..f8448b4a 100644 --- a/integrations/tags_test.go +++ b/tests/tags_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "fmt" diff --git a/integrations/testdata/import1.sql b/tests/testdata/import1.sql similarity index 100% rename from integrations/testdata/import1.sql rename to tests/testdata/import1.sql diff --git a/integrations/testdata/import2.sql b/tests/testdata/import2.sql similarity index 100% rename from integrations/testdata/import2.sql rename to tests/testdata/import2.sql diff --git a/integrations/tests.go b/tests/tests.go similarity index 98% rename from integrations/tests.go rename to tests/tests.go index 59f4b29a..220e1c67 100644 --- a/integrations/tests.go +++ b/tests/tests.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "database/sql" @@ -162,7 +162,7 @@ func createEngine(dbType, connStr string) error { if err != nil { return err } - var tableNames = make([]interface{}, 0, len(tables)) + tableNames := make([]interface{}, 0, len(tables)) for _, table := range tables { tableNames = append(tableNames, table.Name) } diff --git a/integrations/time_test.go b/tests/time_test.go similarity index 96% rename from integrations/time_test.go rename to tests/time_test.go index 5a17417a..13b9ed15 100644 --- a/integrations/time_test.go +++ b/tests/time_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "fmt" @@ -10,6 +10,7 @@ import ( "strings" "testing" "time" + "xorm.io/xorm/convert" "xorm.io/xorm/internal/utils" @@ -18,7 +19,7 @@ import ( ) func formatTime(t time.Time, scales ...int) string { - var layout = "2006-01-02 15:04:05" + layout := "2006-01-02 15:04:05" if len(scales) > 0 && scales[0] > 0 { layout += "." + strings.Repeat("0", scales[0]) } @@ -35,7 +36,7 @@ func TestTimeUserTime(t *testing.T) { assertSync(t, new(TimeUser)) - var user = TimeUser{ + user := TimeUser{ Id: "lunny", OperTime: time.Now(), } @@ -80,7 +81,7 @@ func TestTimeUserTimeDiffLoc(t *testing.T) { assertSync(t, new(TimeUser2)) - var user = TimeUser2{ + user := TimeUser2{ Id: "lunny", OperTime: time.Now(), } @@ -110,7 +111,7 @@ func TestTimeUserCreated(t *testing.T) { assertSync(t, new(UserCreated)) - var user = UserCreated{ + user := UserCreated{ Id: "lunny", } @@ -154,7 +155,7 @@ func TestTimeUserCreatedDiffLoc(t *testing.T) { assertSync(t, new(UserCreated2)) - var user = UserCreated2{ + user := UserCreated2{ Id: "lunny", } @@ -184,7 +185,7 @@ func TestTimeUserUpdated(t *testing.T) { assertSync(t, new(UserUpdated)) - var user = UserUpdated{ + user := UserUpdated{ Id: "lunny", } @@ -204,7 +205,7 @@ func TestTimeUserUpdated(t *testing.T) { assert.EqualValues(t, formatTime(user.UpdatedAt), formatTime(user2.UpdatedAt)) fmt.Println("user2", user2.CreatedAt, user2.UpdatedAt) - var user3 = UserUpdated{ + user3 := UserUpdated{ Id: "lunny2", } @@ -250,7 +251,7 @@ func TestTimeUserUpdatedDiffLoc(t *testing.T) { assertSync(t, new(UserUpdated2)) - var user = UserUpdated2{ + user := UserUpdated2{ Id: "lunny", } @@ -270,7 +271,7 @@ func TestTimeUserUpdatedDiffLoc(t *testing.T) { assert.EqualValues(t, formatTime(user.UpdatedAt), formatTime(user2.UpdatedAt)) fmt.Println("user2", user2.CreatedAt, user2.UpdatedAt) - var user3 = UserUpdated2{ + user3 := UserUpdated2{ Id: "lunny2", } @@ -304,7 +305,7 @@ func TestTimeUserDeleted(t *testing.T) { assertSync(t, new(UserDeleted)) - var user = UserDeleted{ + user := UserDeleted{ Id: "lunny", } @@ -367,7 +368,7 @@ func TestTimeUserDeletedDiffLoc(t *testing.T) { assertSync(t, new(UserDeleted2)) - var user = UserDeleted2{ + user := UserDeleted2{ Id: "lunny", } @@ -412,7 +413,7 @@ func (j JSONDate) MarshalJSON() ([]byte, error) { } func (j *JSONDate) UnmarshalJSON(value []byte) error { - var v = strings.TrimSpace(strings.Trim(string(value), "\"")) + v := strings.TrimSpace(strings.Trim(string(value), "\"")) t, err := time.ParseInLocation("2006-01-02 15:04:05", v, time.Local) if err != nil { @@ -438,7 +439,7 @@ func TestCustomTimeUserDeleted(t *testing.T) { assertSync(t, new(UserDeleted3)) - var user = UserDeleted3{ + user := UserDeleted3{ Id: "lunny", } @@ -500,7 +501,7 @@ func TestCustomTimeUserDeletedDiffLoc(t *testing.T) { assertSync(t, new(UserDeleted4)) - var user = UserDeleted4{ + user := UserDeleted4{ Id: "lunny", } @@ -583,7 +584,7 @@ func TestTimestamp(t *testing.T) { assertSync(t, new(TimestampStruct)) - var d1 = TimestampStruct{ + d1 := TimestampStruct{ InsertTime: time.Now(), } cnt, err := testEngine.Insert(&d1) @@ -625,10 +626,10 @@ func TestTimestamp(t *testing.T) { func TestString2Time(t *testing.T) { loc, err := time.LoadLocation("Asia/Shanghai") assert.NoError(t, err) - var timeTmp1 = time.Date(2023, 7, 14, 11, 30, 0, 0, loc) - var timeTmp2 = time.Date(2023, 7, 14, 0, 0, 0, 0, loc) - var time1StampStr = strconv.FormatInt(timeTmp1.Unix(), 10) - var timeStr = "0000-00-00 00:00:00" + timeTmp1 := time.Date(2023, 7, 14, 11, 30, 0, 0, loc) + timeTmp2 := time.Date(2023, 7, 14, 0, 0, 0, 0, loc) + time1StampStr := strconv.FormatInt(timeTmp1.Unix(), 10) + timeStr := "0000-00-00 00:00:00" dt, err := convert.String2Time(timeStr, time.Local, time.Local) assert.NoError(t, err) assert.True(t, dt.Nanosecond() == 0) diff --git a/integrations/types_null_test.go b/tests/types_null_test.go similarity index 99% rename from integrations/types_null_test.go rename to tests/types_null_test.go index 8d98b456..d4fa250e 100644 --- a/integrations/types_null_test.go +++ b/tests/types_null_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "database/sql" diff --git a/integrations/types_test.go b/tests/types_test.go similarity index 99% rename from integrations/types_test.go rename to tests/types_test.go index 1c815b7a..dfdb4766 100644 --- a/integrations/types_test.go +++ b/tests/types_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package integrations +package tests import ( "errors"