0

I have a wrapper interface that defines a Downloadfile function. The problem is that one of parameters has a random temporary directoriename and the output is a random temporary filename. How do I mock it using https://github.com/golang/mock so I can test the addFile function

var wrapper
func Test(t *testing.T) {
    ctrl, _ := gomock.WithContext(context.Background(), t)
    defer ctrl.Finish()
    m := mock.NewMockWrapperInterface(ctrl)
    m.EXPECT().DownloadFile("myfile", "/var/folders/ls/???").Return("/var/folders/ls/???", nil)
    wrapper = m
    path, err := addFile(myfile, key)
    ...
}

func addFile(myfile, key) (string, error) {
    tmpDirectory := helper.CreateTemporaryDirectory(objectKey)
    defer helper.CleanUpDirectory(tmpDirectory)
    return wrapper.DownloadFile(myfile, tmpDirectory)
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Gert Cuykens
  • 6,845
  • 13
  • 50
  • 84

1 Answers1

0

Found out how the matcher works. This is what I needed to do

m.EXPECT().DownloadFile("myfile", gomock.Any()).Return("/var/folders/ls/ok", nil)
Gert Cuykens
  • 6,845
  • 13
  • 50
  • 84