From d283a4ddae119a4018c8f2d04b4e44e469c7a9a1 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Wed, 13 Apr 2022 04:00:16 +0200 Subject: [PATCH] tests: check max length is available for TEXT cols --- integrations/engine_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/integrations/engine_test.go b/integrations/engine_test.go index 997c8962..905c4f24 100644 --- a/integrations/engine_test.go +++ b/integrations/engine_test.go @@ -288,3 +288,36 @@ func TestGetColumnsComment(t *testing.T) { assert.Equal(t, comment, hasComment) assert.Zero(t, noComment) } + +func TestGetColumnsLength(t *testing.T) { + var max_length int + switch testEngine.Dialect().URI().DBType { + case + schemas.POSTGRES: + max_length = 0 + case + schemas.MYSQL: + max_length = 65535 + default: + t.Skip() + return + } + + type TestLengthStringStruct struct { + Content string `xorm:"TEXT NOT NULL"` + } + + assertSync(t, new(TestLengthStringStruct)) + + tables, err := testEngine.DBMetas() + assert.NoError(t, err) + tableLengthStringName := testEngine.GetColumnMapper().Obj2Table("TestLengthStringStruct") + for _, table := range tables { + if table.Name == tableLengthStringName { + col := table.GetColumn("content") + assert.Equal(t, col.Length, max_length) + assert.Zero(t, col.Length2) + break + } + } +}