diff --git a/go.mod b/go.mod index 0c990ab..1edf0ca 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/jacobbrewer1/patcher -go 1.24 +go 1.23 -toolchain go1.24.0 +toolchain go1.23.4 require ( github.com/gorilla/mux v1.8.1 github.com/stretchr/testify v1.10.0 - github.com/vektra/mockery/v2 v2.52.3 + github.com/vektra/mockery/v2 v2.52.1 ) require ( diff --git a/go.sum b/go.sum index 398e80a..394aa9b 100644 --- a/go.sum +++ b/go.sum @@ -77,8 +77,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/vektra/mockery/v2 v2.52.3 h1:lInrh+OuJu3dY/UPFvdFmJ/lsscEnUFrTmagcRJKoWU= -github.com/vektra/mockery/v2 v2.52.3/go.mod h1:zGDY/f6bip0Yh13GQ5j7xa43fuEoYBa4ICHEaihisHw= +github.com/vektra/mockery/v2 v2.52.1 h1:ejpWJSsInVNsFUvaAX4szecrpYxErN+Ny5X+0RXBP+s= +github.com/vektra/mockery/v2 v2.52.1/go.mod h1:ZJeus9igl4Uf8FGLwXZgtCnp2XUDFD9Mkipi7nsObq0= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac h1:l5+whBCLH3iH2ZNHYLbAe58bo7yrN4mVcnkHDYz5vvs= diff --git a/mock_Filter.go b/mock_Filter.go new file mode 100644 index 0000000..6152982 --- /dev/null +++ b/mock_Filter.go @@ -0,0 +1,84 @@ +// Code generated by mockery. DO NOT EDIT. + +package patcher + +import mock "github.com/stretchr/testify/mock" + +// MockFilter is an autogenerated mock type for the Filter type +type MockFilter struct { + mock.Mock +} + +// Join provides a mock function with no fields +func (_m *MockFilter) Join() (string, []interface{}) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Join") + } + + var r0 string + var r1 []interface{} + if rf, ok := ret.Get(0).(func() (string, []interface{})); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() []interface{}); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]interface{}) + } + } + + return r0, r1 +} + +// Where provides a mock function with no fields +func (_m *MockFilter) Where() (string, []interface{}) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Where") + } + + var r0 string + var r1 []interface{} + if rf, ok := ret.Get(0).(func() (string, []interface{})); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() []interface{}); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]interface{}) + } + } + + return r0, r1 +} + +// NewMockFilter creates a new instance of MockFilter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockFilter(t interface { + mock.TestingT + Cleanup(func()) +}) *MockFilter { + mock := &MockFilter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sql_test.go b/sql_test.go index 319760d..c937f80 100644 --- a/sql_test.go +++ b/sql_test.go @@ -35,6 +35,79 @@ func (s *newSQLPatchSuite) TestNewSQLPatch_Success() { s.Equal([]any{1, "test"}, patch.args) } +func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_Where() { + type testObj struct { + Id *int `db:"id_tag"` + Name *string `db:"name_tag"` + } + + obj := testObj{ + Id: ptr(1), + Name: ptr("test"), + } + + mf := NewMockFilter(s.T()) + 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() { + type testObj struct { + Id *int `db:"id_tag"` + Name *string `db:"name_tag"` + } + + obj := testObj{ + Id: ptr(1), + Name: ptr("test"), + } + + mf := NewMockFilter(s.T()) + 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() { + type testObj struct { + Id *int `db:"id_tag"` + Name *string `db:"name_tag"` + } + + obj := testObj{ + Id: ptr(1), + Name: ptr("test"), + } + + mf := NewMockFilter(s.T()) + 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() { type testObj struct { Id *int `db:"id_tag"` diff --git a/vendor/github.com/vektra/mockery/v2/CONTRIBUTING.md b/vendor/github.com/vektra/mockery/v2/CONTRIBUTING.md index 8049f59..91a4780 100644 --- a/vendor/github.com/vektra/mockery/v2/CONTRIBUTING.md +++ b/vendor/github.com/vektra/mockery/v2/CONTRIBUTING.md @@ -6,7 +6,7 @@ Read our [Code of Conduct](https://github.com/vektra/mockery/blob/master/CODE_OF ## Local development setup -All of the local development tools are go-based and are versioned in our go.mod file. Simply call `go mod download -x` to initialize and download all of our tooling. +All of the local development tools are go-based and are versioned in our go.mod file. Simply call `go download -x` to initialize and download all of our tooling. This project uses Taskfile, a better alternative to Makefile. Run `task -l` for list of valid targets. diff --git a/vendor/github.com/vektra/mockery/v2/Dockerfile b/vendor/github.com/vektra/mockery/v2/Dockerfile index 6ecd691..42f372d 100644 --- a/vendor/github.com/vektra/mockery/v2/Dockerfile +++ b/vendor/github.com/vektra/mockery/v2/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.24-alpine as builder +FROM golang:1.23-alpine as builder RUN apk --update add --no-cache gcc musl-dev git openssh diff --git a/vendor/github.com/vektra/mockery/v2/mockery-tools.env b/vendor/github.com/vektra/mockery/v2/mockery-tools.env index 671c53b..0f95022 100644 --- a/vendor/github.com/vektra/mockery/v2/mockery-tools.env +++ b/vendor/github.com/vektra/mockery/v2/mockery-tools.env @@ -1 +1 @@ -VERSION=v2.52.3 +VERSION=v2.52.1 diff --git a/vendor/modules.txt b/vendor/modules.txt index a133358..7865751 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -117,8 +117,8 @@ github.com/stretchr/testify/suite # github.com/subosito/gotenv v1.6.0 ## explicit; go 1.18 github.com/subosito/gotenv -# github.com/vektra/mockery/v2 v2.52.3 -## explicit; go 1.24 +# github.com/vektra/mockery/v2 v2.52.1 +## explicit; go 1.23 github.com/vektra/mockery/v2 github.com/vektra/mockery/v2/cmd github.com/vektra/mockery/v2/pkg