Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Testify documentation can be found on Github, https://github.com/stretchr/testify


The first question I ask myself before I write a unit test is, "what do I want to test?" In this case, I'll test a method called GetDirPath in my Go pkg called image.go.

GetDirPath uses the Go core packages user and path to return a file path.

...


Code Block
languagetext
themeFadeToGrey
func (v *ImageClient) GetDirPath(imageName string) (string, string, error) {

	home, err := 

...

v.GetHomeDir()

...


	dirPath := path.Join(home, "images", v.storeName)

...


	filePath := path.Join(dirPath, imageName)

...



	return filePath, dirPath, err

...


}



To Do - Explain

To test, I'

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:

...

  myImports.On("GetHomeDir").Return("home", nil)

...



To Do - Explain



References:

...