forked from go-gorp/gorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
column_test.go
111 lines (90 loc) · 2.5 KB
/
column_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2012 James Cooper. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gorp_test
import (
"testing"
"time"
"github.com/go-gorp/gorp/v3"
"github.com/stretchr/testify/suite"
)
type ColumnTestSuite struct {
suite.Suite
}
func TestColumnTestSuite(t *testing.T) {
suite.Run(t, new(ColumnTestSuite))
}
func (s *ColumnTestSuite) TestColumnMapBasicOperations() {
col := &gorp.ColumnMap{
ColumnName: "original_name",
}
// Test Rename
col.Rename("new_name")
s.Equal("new_name", col.ColumnName)
// Test SetTransient
s.False(col.Transient)
col.SetTransient(true)
s.True(col.Transient)
col.SetTransient(false)
s.False(col.Transient)
// Test SetUnique
s.False(col.Unique)
col.SetUnique(true)
s.True(col.Unique)
col.SetUnique(false)
s.False(col.Unique)
// Test SetNotNull
s.False(col.IsNotNull())
col.SetNotNull(true)
s.True(col.IsNotNull())
col.SetNotNull(false)
s.False(col.IsNotNull())
// Test SetMaxSize
s.Equal(0, col.MaxSize)
col.SetMaxSize(100)
s.Equal(100, col.MaxSize)
// Test SetDefaultValue
s.Equal("", col.DefaultValue)
col.SetDefaultValue("test_value")
s.Equal("test_value", col.DefaultValue)
}
func (s *ColumnTestSuite) TestTypedColumnMap() {
// Test with string type
col := &gorp.ColumnMap{ColumnName: "string_col"}
typedCol := gorp.NewTypedColumnMap[string](col)
s.Equal(col, typedCol.ColumnMap)
// Test with custom type
type UserID int64
idCol := &gorp.ColumnMap{ColumnName: "id_col"}
typedIDCol := gorp.NewTypedColumnMap[UserID](idCol)
s.Equal(idCol, typedIDCol.ColumnMap)
// Test with time.Time
timeCol := &gorp.ColumnMap{ColumnName: "time_col"}
typedTimeCol := gorp.NewTypedColumnMap[time.Time](timeCol)
s.Equal(timeCol, typedTimeCol.ColumnMap)
}
func (s *ColumnTestSuite) TestColumnMapChaining() {
// Test method chaining
col := &gorp.ColumnMap{ColumnName: "test_col"}
col.SetTransient(true).
SetUnique(true).
SetNotNull(true).
SetMaxSize(255).
SetDefaultValue("default")
s.True(col.Transient)
s.True(col.Unique)
s.True(col.IsNotNull())
s.Equal(255, col.MaxSize)
s.Equal("default", col.DefaultValue)
}
func (s *ColumnTestSuite) TestColumnMapKeyOperations() {
col := &gorp.ColumnMap{ColumnName: "id"}
// Test IsKey
s.False(col.IsKey())
// Test IsAutoIncrement
s.False(col.IsAutoIncrement())
// Test GeneratedIdQuery
s.Equal("", col.GeneratedIdQuery)
col.GeneratedIdQuery = "SELECT LAST_INSERT_ID()"
s.Equal("SELECT LAST_INSERT_ID()", col.GeneratedIdQuery)
}