如何在golang中模拟request.Request

I'm using github.com/aws/aws-sdk-go/aws/request to get presigned URLs, which I need to upload files to s3 bucket in AWS. I'm writing the test currently, for that I need to mock func (r *Request) Presign(expire time.Duration). request.Request is a struct, not an interface, so i have no idea, how can I mock it.

This isn't directly answering your question, but it might remove the basis of the question altogether.

A neat thing in Go, is that you are able to easily isolate your dependencies using interfaces. If your code, the part that you need to test, is using Presign indirectly, it is trivial to test.

I.e. create an interface

type HigherLevelAws interface {
    Upload(file string) error
}

and use this interface in your code, along with Upload. Then you can easily mock this using e.g. https://godoc.org/github.com/stretchr/testify/mock

The actual implementation, would look something like this

type ActualAwsImpl struct {
    aws *aws.Client
}

func (a *ActualAwsImpl) Upload(file string) error {
    aws.Presign...
}

This allows you to test the business part of your code, but of course, still leaves untested code in ActualAwsImpl. This untested code, however, may be guaranteed to work by virtue of unit and integration tests in the aws sdk itself. Either way, in my organization, we test this using fake aws services run in docker (e.g. https://github.com/gliffy/fake-s3).

You can create an interface for the function directly, like this:

type presigner interface {
    Presign(expire time.Duration) (string, error)
}

If you implement your logic in a separate function that takes a presigner as a parameter like this (called dependency injection):

func Upload(p presigner, files string) error {
    // ...
    res, err := p.Presign(someduration)
    if err != nil {
        return err
    }
    // and so on
}

Then it's easy to mock in your tests - just implement the presigner interface and have the Presign function return what you expect:

type presignerMock struct {}

func (p *presignerMock) Presign(d time.Duration) (string, error) {
    return "yay", nil
}

To test different scenarios you can add fields to the presignerMock and return them in your implementation:

type presignerMock {
    res string
    err error
}

func (p *presignerMock) Presign(d time.Duration) (string, error) {
    return p.res, p.err
}