-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7de37d5
commit d8db8e6
Showing
48 changed files
with
13,456 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package interfaces | ||
|
||
import "gorm.io/gorm" | ||
|
||
type Database interface { | ||
Find(dest interface{}, conds ...interface{}) *gorm.DB | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package mocks | ||
|
||
import ( | ||
"github.com/stretchr/testify/mock" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type MockDB struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockDB) Find(out interface{}, where ...interface{}) *gorm.DB { | ||
args := m.Called(out, where) | ||
return args.Get(0).(*gorm.DB) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package repositories | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/VikashChauhan51/go-sample-api/internal/core/entities" | ||
repo "github.com/VikashChauhan51/go-sample-api/internal/infra/repositories" | ||
"github.com/VikashChauhan51/go-sample-api/test/mocks" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func TestFetchBooksAsync(t *testing.T) { | ||
mockDB := new(mocks.MockDB) | ||
repo := repo.NewBookRepository(mockDB) | ||
|
||
expectedBooks := []entities.Book{ | ||
{ID: 1, Title: "Title1", Author: "Author1"}, | ||
{ID: 2, Title: "Title2", Author: "Author2"}, | ||
} | ||
|
||
mockDB.On("Find", mock.Anything, mock.Anything).Run(func(args mock.Arguments) { | ||
arg := args.Get(0).(*[]entities.Book) | ||
*arg = expectedBooks | ||
}).Return(&gorm.DB{Error: nil}).Once() | ||
|
||
result, err := repo.FetchBooksAsync() | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, result) | ||
assert.Equal(t, len(expectedBooks), len(*result)) | ||
|
||
mockDB.AssertExpectations(t) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.