-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrap_test.go
89 lines (70 loc) · 1.99 KB
/
wrap_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
package postgres
import (
"testing"
"github.com/stretchr/testify/suite"
)
type WrapTestSuite struct {
suite.Suite
wrap *Wrap
}
func TestWrapSuite(t *testing.T) {
suite.Run(t, new(WrapTestSuite))
}
func (s *WrapTestSuite) SetupTest() {
s.wrap = NewWrap("prefix_")
}
func (s *WrapTestSuite) TestColumn() {
// With alias
result := s.wrap.Column("column as alias")
s.Equal(`"column" as "prefix_alias"`, result)
// Without alias
result = s.wrap.Column("column")
s.Equal(`"column"`, result)
}
func (s *WrapTestSuite) TestColumnize() {
result := s.wrap.Columnize([]string{"column1", "column2 as alias2"})
s.Equal(`"column1", "column2" as "prefix_alias2"`, result)
}
func (s *WrapTestSuite) TestQuote() {
// With non empty value
result := s.wrap.Quote("value")
s.Equal("'value'", result)
// With empty value
result = s.wrap.Quote("")
s.Equal("", result)
}
func (s *WrapTestSuite) TestQuotes() {
result := s.wrap.Quotes([]string{"value1", "value2"})
s.Equal([]string{"'value1'", "'value2'"}, result)
}
func (s *WrapTestSuite) TestSegmentsWithMultipleSegments() {
result := s.wrap.Segments([]string{"table", "column"})
s.Equal(`"prefix_table"."column"`, result)
}
func (s *WrapTestSuite) TestTable() {
// With alias
result := s.wrap.Table("table as alias")
s.Equal(`"prefix_table" as "prefix_alias"`, result)
// With schema
result = s.wrap.Table("goravel.table")
s.Equal(`"goravel"."prefix_table"`, result)
// Without alias
result = s.wrap.Table("table")
s.Equal(`"prefix_table"`, result)
}
func (s *WrapTestSuite) TestValue() {
// With asterisk
result := s.wrap.Value("*")
s.Equal("*", result)
// Without asterisk
result = s.wrap.Value("value")
s.Equal(`"value"`, result)
}
func (s *WrapTestSuite) TestAliasedTable() {
result := s.wrap.aliasedTable("users as u")
s.Equal(`"prefix_users" as "prefix_u"`, result)
}
func (s *WrapTestSuite) TestAliasedValue() {
result := s.wrap.aliasedValue("users.name as user_name")
s.Equal(`"prefix_users"."name" as "prefix_user_name"`, result)
}