Path: blob/main/components/gitpod-db/go/varchar_test.go
2498 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package db_test56import (7"testing"89db "github.com/gitpod-io/gitpod/components/gitpod-db/go"10"github.com/gitpod-io/gitpod/components/gitpod-db/go/dbtest"11"github.com/stretchr/testify/require"12"gorm.io/gorm"13)1415func TestVarcharTime_SerializeAndDeserialize(t *testing.T) {16// Custom table to be able to exercise serialization easily, independent of other models17type VarcharModel struct {18ID int `gorm:"primaryKey"`19Time db.VarcharTime `gorm:"column:time;type:varchar(255);"`20}2122conn := dbtest.ConnectForTests(t)23require.NoError(t, conn.AutoMigrate(&VarcharModel{}))2425conn.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(&VarcharModel{})2627for _, scenario := range []struct {28Description string29Input VarcharModel30Expected VarcharModel31}{32{33Description: "empty value for VarcharTime",34Input: VarcharModel{35ID: 1,36Time: db.VarcharTime{},37},38Expected: VarcharModel{39ID: 1,40Time: db.VarcharTime{},41},42},43} {44tx := conn.Create(scenario.Input)45require.NoError(t, tx.Error)4647var read VarcharModel48tx = conn.First(&read, scenario.Input.ID)49require.NoError(t, tx.Error)5051require.Equal(t, scenario.Expected, read)52}53}545556