...
Code Block | ||||
---|---|---|---|---|
| ||||
package app import ( "fmt" "os/user" "testing" "github.com/stretchr/testify/mock" ) type mockImports struct { mock.Mock } func (m *mockImports) GetCurrentUser() (*user.User, error) { fmt.Println("Mocked Get User") args := m.Called() return args.Get(0).(*user.User), args.Error(1) } func TestService(t *testing.T) { fakeUser := &user.User{} myImports := new(mockImports) myImports.On("GetCurrentUser").Return(&fakeUser, nil) imageClient := ImageClient{myImports, "test_image", "test_meta"} _, dir, err := imageClient.GetDirPath("test") if err != nil { t.Errorf("Path was incorrect, got: %q, want: %q.", dir, "some_path") } } |
...