Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 如何处理随机输入和输出值_Go_Gomock - Fatal编程技术网

Go 如何处理随机输入和输出值

Go 如何处理随机输入和输出值,go,gomock,Go,Gomock,我有一个定义Downloadfile函数的包装器接口。问题是其中一个参数有一个随机的临时目录名,而输出是一个随机的临时文件名。如何使用模拟来测试addFile函数 var wrapper func Test(t *testing.T) { ctrl, _ := gomock.WithContext(context.Background(), t) defer ctrl.Finish() m := mock.NewMockWrapperInterface(ctrl)

我有一个定义Downloadfile函数的包装器接口。问题是其中一个参数有一个随机的临时目录名,而输出是一个随机的临时文件名。如何使用模拟来测试addFile函数

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)
}

了解matcher的工作原理。这就是我需要做的

m.EXPECT().DownloadFile("myfile", gomock.Any()).Return("/var/folders/ls/ok", nil)