Skip to content

Instantly share code, notes, and snippets.

@mehmetcemyucel
Created April 29, 2022 08:51
Show Gist options
  • Save mehmetcemyucel/5823cf6fbab660a9a1af81dd973bf7c0 to your computer and use it in GitHub Desktop.
Save mehmetcemyucel/5823cf6fbab660a9a1af81dd973bf7c0 to your computer and use it in GitHub Desktop.
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