Created
April 29, 2022 08:51
-
-
Save mehmetcemyucel/5823cf6fbab660a9a1af81dd973bf7c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package service | |
import ( | |
"helloWorld/pkg/model/example/dto/request" | |
"helloWorld/pkg/model/example/entity" | |
"helloWorld/pkg/repository" | |
"testing" | |
) | |
var service IExampleService | |
var repoActiveExamplesMock func(name string) ([]entity.Example, error) | |
type exampleRepositoryMock struct{} | |
func (u exampleRepositoryMock) ActiveExamples(name string) ([]entity.Example, error) { | |
return repoActiveExamplesMock(name) | |
} | |
func init() { | |
var repo repository.IExampleRepository | |
repo = exampleRepositoryMock{} | |
service = &ExampleService{repo, nil} | |
} | |
func TestCheck_whenGetRecordsWithoutError_thenReturnSlice(t *testing.T) { | |
repoActiveExamplesMock = func(name string) ([]entity.Example, error) { | |
return make([]entity.Example, 1), nil | |
} | |
resp, _ := service.Check(request.ExampleReq{}) | |
if resp == nil { | |
t.Errorf("response should not be nil") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment