如何使用Go接口测试Google API Golang库?

I'm trying to use interfaces to test code that uses google's drive api lib.

type MyFile struct {
  DownloadUrl string `json:"downloadUrl,omitempty"`
}

type MyFilesGetCall interface {
  Do() (*MyFile, error)
  // Do() (*drive.File, error) // this DOES work
}

type MyFilesService interface {
  Get(string) *MyFilesGetCall
  // Get(string) *drive.FilesGetCall // this DOES work
}

func GetInfo(id string, myService MyFilesService) {
  myService.Get(id).Do()
}

func main() {
  drive, _ := drive.New(new(http.Client))
  GetInfo("id", drive.Files)
}

When I try to run this I get the following error:

$ go run so.go
./so.go:24: cannot use drive.Files (type *drive.FilesService) as type MyFilesService in argument to GetInfo:
        *drive.FilesService does not implement MyFilesService (wrong type for Get method)
                have Get(string) *drive.FilesGetCall
                want Get(string) *MyFilesGetCall
./so.go:28: fService.Get(id).Do undefined (type *MyFilesGetCall has no field or method Do)

It seems that interfaces only work 1 level deep.

Can anyone recommend an alternative approach for mocking this dependency?

It seems that interfaces only work 1 level deep.

Go has no notion of co/ntravariance. The signature for Get is incompatible with the MyFilesService interface. As your error message told you:

*drive.FilesService does not implement MyFilesService (wrong type for Get method)
    have Get(string) *drive.FilesGetCall
    want Get(string) *MyFilesGetCall

Can anyone recommend an alternative approach for mocking this dependency?

Change MyFilesService to something that *drive.FilesService actually implements.