-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultifilter_test.go
63 lines (48 loc) · 1.36 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
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)
}