Skip to content

Commit

Permalink
filter test values
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobbrewer1 committed Feb 25, 2025
1 parent e570c65 commit 6094891
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_Where() {
}

mf := NewMockFilter(s.T())
mf.On("Where").Return("where", []any{"arg1", "arg2"})
mf.On("Where").Return("test_where = ? and arg2_val = ?", []any{"arg1", "arg2"})

patch := NewSQLPatch(obj, WithWhere(mf))

s.Equal([]string{"id_tag = ?", "name_tag = ?"}, patch.fields)
s.Equal([]any{1, "test"}, patch.args)

s.Equal("AND test_where = ? and arg2_val = ?\n", patch.whereSql.String())
s.Equal([]any{"arg1", "arg2"}, patch.whereArgs)
}

func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_Join() {
Expand All @@ -67,12 +70,15 @@ func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_Join() {
}

mf := NewMockFilter(s.T())
mf.On("Join").Return("JOIN table2 ON table1.id = table2.id", nil)
mf.On("Join").Return("JOIN table2 ON table1.id = table2.id and arg2_val = ?", []any{"arg1"})

patch := NewSQLPatch(obj, WithJoin(mf))

s.Equal([]string{"id_tag = ?", "name_tag = ?"}, patch.fields)
s.Equal([]any{1, "test"}, patch.args)

s.Equal("JOIN table2 ON table1.id = table2.id and arg2_val = ?\n", patch.joinSql.String())
s.Equal([]any{"arg1"}, patch.joinArgs)
}

func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_JoinerAndWhere() {
Expand All @@ -87,13 +93,19 @@ func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_JoinerAndWhere() {
}

mf := NewMockFilter(s.T())
mf.On("Join").Return("JOIN table2 ON table1.id = table2.id", nil)
mf.On("Join").Return("JOIN table2 ON table1.id = table2.id and arg2_val = ?", []any{"arg1"})
mf.On("Where").Return("where", []any{"arg1", "arg2"})

patch := NewSQLPatch(obj, WithFilter(mf))

s.Equal([]string{"id_tag = ?", "name_tag = ?"}, patch.fields)
s.Equal([]any{1, "test"}, patch.args)

s.Equal("JOIN table2 ON table1.id = table2.id and arg2_val = ?\n", patch.joinSql.String())
s.Equal([]any{"arg1"}, patch.joinArgs)

s.Equal("AND where\n", patch.whereSql.String())
s.Equal([]any{"arg1", "arg2"}, patch.whereArgs)
}

func (s *newSQLPatchSuite) TestNewSQLPatch_Success_MultiFilter() {
Expand Down

0 comments on commit 6094891

Please sign in to comment.