...
GetDirPath uses the Go core packages user and path to return a file path.
type Imports interface {
func (v *ImageClient) GetDirPath(imageName string) (string, string, error) { home, err := v.GetHomeDir() return filePath, dirPath, err }func (v *ImageClient) GetHomeDir() (string, error) { return home, nil } |
---|
To Do - Explain
To test, I'll create the test file image_test.go. A test for the GetDirPath could look like this:
import ( type mockImports struct { func (m *mockImports) GetHomeDir() (string, error) { return args.String(0), args.Error(1) func TestService(t *testing.T) { myImports.On("GetHomeDir").Return("home", nil) imageClient := ImageClient{myImports, "test_image", "test_meta"} |
---|
_, dir, err := imageClient.GetDirPath("test") |
---|
To Do - Explain
References:
...