-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultifilter_test.go
114 lines (87 loc) · 2.52 KB
/
multifilter_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
112
113
114
package patcher
import (
"testing"
"github.com/stretchr/testify/suite"
)
type multiFilterSuite struct {
suite.Suite
}
func TestMultiFilterSuite(t *testing.T) {
suite.Run(t, new(multiFilterSuite))
}
func (s *multiFilterSuite) TestNewMultiFilter_Add_Single() {
mf := NewMultiFilter()
s.NotNil(mf)
mw := NewMockWherer(s.T())
mw.On("Where").Return("where", []any{"arg1", "arg2"})
mf.Add(mw)
sql, args := mf.Where()
s.Equal("AND where\n", sql)
s.Equal([]any{"arg1", "arg2"}, args)
}
func (s *multiFilterSuite) TestNewMultiFilter_Add_Multi() {
mf := NewMultiFilter()
s.NotNil(mf)
mw := NewMockWherer(s.T())
mw.On("Where").Return("where", []any{"arg1", "arg2"})
mf.Add(mw)
mwTwo := NewMockWherer(s.T())
mwTwo.On("Where").Return("whereTwo", []any{"arg3", "arg4"})
mf.Add(mwTwo)
sql, args := mf.Where()
s.Equal("AND where\nAND whereTwo\n", sql)
s.Equal([]any{"arg1", "arg2", "arg3", "arg4"}, args)
}
func (s *multiFilterSuite) TestNewMultiFilter_Add_WhereTyper() {
mf := NewMultiFilter()
s.NotNil(mf)
mw := NewMockWherer(s.T())
mw.On("Where").Return("where", []any{"arg1", "arg2"})
mf.Add(mw)
mwt := NewMockWhereTyper(s.T())
mwt.On("Where").Return("whereTwo", []any{"arg3", "arg4"})
mwt.On("WhereType").Return(WhereTypeOr)
mf.Add(mwt)
sql, args := mf.Where()
s.Equal("AND where\nOR whereTwo\n", sql)
s.Equal([]any{"arg1", "arg2", "arg3", "arg4"}, args)
}
func (s *multiFilterSuite) TestNewMultiFilter_Add_Joiner() {
mf := NewMultiFilter()
s.NotNil(mf)
mj := NewMockJoiner(s.T())
mj.On("Join").Return("join", []any{"arg1", "arg2"})
mf.Add(mj)
sql, args := mf.Join()
s.Equal("join\n", sql)
s.Equal([]any{"arg1", "arg2"}, args)
}
func (s *multiFilterSuite) TestNewMultiFilter_Add_MultiJoiner() {
mf := NewMultiFilter()
s.NotNil(mf)
mj := NewMockJoiner(s.T())
mj.On("Join").Return("join", []any{"arg1", "arg2"})
mf.Add(mj)
mjTwo := NewMockJoiner(s.T())
mjTwo.On("Join").Return("joinTwo", []any{"arg3", "arg4"})
mf.Add(mjTwo)
sql, args := mf.Join()
s.Equal("join\njoinTwo\n", sql)
s.Equal([]any{"arg1", "arg2", "arg3", "arg4"}, args)
}
func (s *multiFilterSuite) TestNewMultiFilter_Add_JoinerAndWherer() {
mf := NewMultiFilter()
s.NotNil(mf)
mj := NewMockJoiner(s.T())
mj.On("Join").Return("join", []any{"arg1", "arg2"})
mf.Add(mj)
mw := NewMockWherer(s.T())
mw.On("Where").Return("where", []any{"arg3", "arg4"})
mf.Add(mw)
sql, args := mf.Join()
s.Equal("join\n", sql)
s.Equal([]any{"arg1", "arg2"}, args)
sql, args = mf.Where()
s.Equal("AND where\n", sql)
s.Equal([]any{"arg3", "arg4"}, args)
}