Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/go/varchar_test.go
2498 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package db_test
6
7
import (
8
"testing"
9
10
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
11
"github.com/gitpod-io/gitpod/components/gitpod-db/go/dbtest"
12
"github.com/stretchr/testify/require"
13
"gorm.io/gorm"
14
)
15
16
func TestVarcharTime_SerializeAndDeserialize(t *testing.T) {
17
// Custom table to be able to exercise serialization easily, independent of other models
18
type VarcharModel struct {
19
ID int `gorm:"primaryKey"`
20
Time db.VarcharTime `gorm:"column:time;type:varchar(255);"`
21
}
22
23
conn := dbtest.ConnectForTests(t)
24
require.NoError(t, conn.AutoMigrate(&VarcharModel{}))
25
26
conn.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(&VarcharModel{})
27
28
for _, scenario := range []struct {
29
Description string
30
Input VarcharModel
31
Expected VarcharModel
32
}{
33
{
34
Description: "empty value for VarcharTime",
35
Input: VarcharModel{
36
ID: 1,
37
Time: db.VarcharTime{},
38
},
39
Expected: VarcharModel{
40
ID: 1,
41
Time: db.VarcharTime{},
42
},
43
},
44
} {
45
tx := conn.Create(scenario.Input)
46
require.NoError(t, tx.Error)
47
48
var read VarcharModel
49
tx = conn.First(&read, scenario.Input.ID)
50
require.NoError(t, tx.Error)
51
52
require.Equal(t, scenario.Expected, read)
53
}
54
}
55
56