add mocks for handlers
This commit is contained in:
parent
efee9b2718
commit
2685baa3e7
4
Makefile
4
Makefile
|
@ -10,3 +10,7 @@ run_parser:
|
||||||
go run ./cmd/parser/main.go -config ./config/local.yaml
|
go run ./cmd/parser/main.go -config ./config/local.yaml
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run
|
golangci-lint run
|
||||||
|
generate:
|
||||||
|
go generate ./...
|
||||||
|
test:
|
||||||
|
go test ./internal/...
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -15,6 +15,7 @@ require (
|
||||||
github.com/minio/minio-go/v7 v7.0.66
|
github.com/minio/minio-go/v7 v7.0.66
|
||||||
github.com/redis/go-redis/v9 v9.4.0
|
github.com/redis/go-redis/v9 v9.4.0
|
||||||
github.com/s32x/httpclient v0.0.0-20220217184346-6df4d4d51c14
|
github.com/s32x/httpclient v0.0.0-20220217184346-6df4d4d51c14
|
||||||
|
github.com/stretchr/testify v1.8.4
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -25,6 +26,7 @@ require (
|
||||||
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
|
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
github.com/charmbracelet/lipgloss v0.9.1 // indirect
|
github.com/charmbracelet/lipgloss v0.9.1 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||||
|
@ -52,10 +54,12 @@ require (
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/muesli/reflow v0.3.0 // indirect
|
github.com/muesli/reflow v0.3.0 // indirect
|
||||||
github.com/muesli/termenv v0.15.2 // indirect
|
github.com/muesli/termenv v0.15.2 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
||||||
github.com/rs/xid v1.5.0 // indirect
|
github.com/rs/xid v1.5.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
|
github.com/stretchr/objx v0.5.0 // indirect
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
golang.org/x/crypto v0.17.0 // indirect
|
golang.org/x/crypto v0.17.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||||
|
|
1
go.sum
1
go.sum
|
@ -150,6 +150,7 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
|
||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
// Code generated by mockery v2.40.1. DO NOT EDIT.
|
||||||
|
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
models "recipes/internal/domain/models"
|
||||||
|
|
||||||
|
mock "github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RecipeProvider is an autogenerated mock type for the RecipeProvider type
|
||||||
|
type RecipeProvider struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRecipe provides a mock function with given fields: ctx, r_id
|
||||||
|
func (_m *RecipeProvider) GetRecipe(ctx context.Context, r_id uint) (models.Recipe, error) {
|
||||||
|
ret := _m.Called(ctx, r_id)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for GetRecipe")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 models.Recipe
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, uint) (models.Recipe, error)); ok {
|
||||||
|
return rf(ctx, r_id)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, uint) models.Recipe); ok {
|
||||||
|
r0 = rf(ctx, r_id)
|
||||||
|
} else {
|
||||||
|
r0 = ret.Get(0).(models.Recipe)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context, uint) error); ok {
|
||||||
|
r1 = rf(ctx, r_id)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRecipeProvider creates a new instance of RecipeProvider. 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 NewRecipeProvider(t interface {
|
||||||
|
mock.TestingT
|
||||||
|
Cleanup(func())
|
||||||
|
}) *RecipeProvider {
|
||||||
|
mock := &RecipeProvider{}
|
||||||
|
mock.Mock.Test(t)
|
||||||
|
|
||||||
|
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||||
|
|
||||||
|
return mock
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ type Response struct {
|
||||||
Recipe models.Recipe `json:"recipe"`
|
Recipe models.Recipe `json:"recipe"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:generate go run github.com/vektra/mockery/v2@v2.40.1 --name=RecipeProvider
|
||||||
type RecipeProvider interface {
|
type RecipeProvider interface {
|
||||||
GetRecipe(ctx context.Context, r_id uint) (models.Recipe, error)
|
GetRecipe(ctx context.Context, r_id uint) (models.Recipe, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
// Code generated by mockery v2.40.1. DO NOT EDIT.
|
||||||
|
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
io "io"
|
||||||
|
|
||||||
|
mock "github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ImageProvider is an autogenerated mock type for the ImageProvider type
|
||||||
|
type ImageProvider struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecipeImage provides a mock function with given fields: ctx, filename
|
||||||
|
func (_m *ImageProvider) RecipeImage(ctx context.Context, filename string) (io.ReadCloser, error) {
|
||||||
|
ret := _m.Called(ctx, filename)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for RecipeImage")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 io.ReadCloser
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, string) (io.ReadCloser, error)); ok {
|
||||||
|
return rf(ctx, filename)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, string) io.ReadCloser); ok {
|
||||||
|
r0 = rf(ctx, filename)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).(io.ReadCloser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
|
||||||
|
r1 = rf(ctx, filename)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewImageProvider creates a new instance of ImageProvider. 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 NewImageProvider(t interface {
|
||||||
|
mock.TestingT
|
||||||
|
Cleanup(func())
|
||||||
|
}) *ImageProvider {
|
||||||
|
mock := &ImageProvider{}
|
||||||
|
mock.Mock.Test(t)
|
||||||
|
|
||||||
|
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||||
|
|
||||||
|
return mock
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/go-chi/render"
|
"github.com/go-chi/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:generate go run github.com/vektra/mockery/v2@v2.40.1 --name=ImageProvider
|
||||||
type ImageProvider interface {
|
type ImageProvider interface {
|
||||||
RecipeImage(ctx context.Context, filename string) (io.ReadCloser, error)
|
RecipeImage(ctx context.Context, filename string) (io.ReadCloser, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
// Code generated by mockery v2.40.1. DO NOT EDIT.
|
||||||
|
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
models "recipes/internal/domain/models"
|
||||||
|
|
||||||
|
mock "github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RecipesProvider is an autogenerated mock type for the RecipesProvider type
|
||||||
|
type RecipesProvider struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRecipes provides a mock function with given fields: ctx, offset, limit
|
||||||
|
func (_m *RecipesProvider) GetRecipes(ctx context.Context, offset int, limit int) ([]models.Recipe, error) {
|
||||||
|
ret := _m.Called(ctx, offset, limit)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for GetRecipes")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 []models.Recipe
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, int, int) ([]models.Recipe, error)); ok {
|
||||||
|
return rf(ctx, offset, limit)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, int, int) []models.Recipe); ok {
|
||||||
|
r0 = rf(ctx, offset, limit)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).([]models.Recipe)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context, int, int) error); ok {
|
||||||
|
r1 = rf(ctx, offset, limit)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRecipesProvider creates a new instance of RecipesProvider. 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 NewRecipesProvider(t interface {
|
||||||
|
mock.TestingT
|
||||||
|
Cleanup(func())
|
||||||
|
}) *RecipesProvider {
|
||||||
|
mock := &RecipesProvider{}
|
||||||
|
mock.Mock.Test(t)
|
||||||
|
|
||||||
|
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||||
|
|
||||||
|
return mock
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ type Response struct {
|
||||||
Recipes []models.Recipe `json:"recipes"`
|
Recipes []models.Recipe `json:"recipes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:generate go run github.com/vektra/mockery/v2@v2.40.1 --name=RecipesProvider
|
||||||
type RecipesProvider interface {
|
type RecipesProvider interface {
|
||||||
GetRecipes(ctx context.Context, offset, limit int) ([]models.Recipe, error)
|
GetRecipes(ctx context.Context, offset, limit int) ([]models.Recipe, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
// Code generated by mockery v2.40.1. DO NOT EDIT.
|
||||||
|
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
models "recipes/internal/domain/models"
|
||||||
|
|
||||||
|
mock "github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RecipesProvider is an autogenerated mock type for the RecipesProvider type
|
||||||
|
type RecipesProvider struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRecipesByCategory provides a mock function with given fields: ctx, offset, limit, category
|
||||||
|
func (_m *RecipesProvider) GetRecipesByCategory(ctx context.Context, offset int, limit int, category string) ([]models.Recipe, error) {
|
||||||
|
ret := _m.Called(ctx, offset, limit, category)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for GetRecipesByCategory")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 []models.Recipe
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, int, int, string) ([]models.Recipe, error)); ok {
|
||||||
|
return rf(ctx, offset, limit, category)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, int, int, string) []models.Recipe); ok {
|
||||||
|
r0 = rf(ctx, offset, limit, category)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).([]models.Recipe)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context, int, int, string) error); ok {
|
||||||
|
r1 = rf(ctx, offset, limit, category)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRecipesProvider creates a new instance of RecipesProvider. 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 NewRecipesProvider(t interface {
|
||||||
|
mock.TestingT
|
||||||
|
Cleanup(func())
|
||||||
|
}) *RecipesProvider {
|
||||||
|
mock := &RecipesProvider{}
|
||||||
|
mock.Mock.Test(t)
|
||||||
|
|
||||||
|
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||||
|
|
||||||
|
return mock
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ type Response struct {
|
||||||
Recipes []models.Recipe `json:"recipes"`
|
Recipes []models.Recipe `json:"recipes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:generate go run github.com/vektra/mockery/v2@v2.40.1 --name=RecipesProvider
|
||||||
type RecipesProvider interface {
|
type RecipesProvider interface {
|
||||||
GetRecipesByCategory(ctx context.Context, offset, limit int, category string) ([]models.Recipe, error)
|
GetRecipesByCategory(ctx context.Context, offset, limit int, category string) ([]models.Recipe, error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue