/
testing.go
45 lines (36 loc) 路 1.17 KB
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//nolint:deadcode,unused
package aws
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
type testResolver struct {
URL string
}
func (tr *testResolver) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
URL: tr.URL,
}, nil
}
type testCredentials struct {
}
func (tc *testCredentials) Retrieve(ctx context.Context) (aws.Credentials, error) {
return aws.Credentials{AccessKeyID: "AKIA0123456789", SecretAccessKey: "opensesame"}, nil
}
func WithTestEndpoint(ctx context.Context, url string) context.Context {
resolver := &testResolver{URL: url}
opts := []func(*config.LoadOptions) error{
config.WithEndpointResolverWithOptions(resolver),
config.WithCredentialsProvider(&testCredentials{}),
// config.WithClientLogMode(aws.LogRequestWithBody | aws.LogResponseWithBody),
}
ctx = context.WithValue(ctx, ctxConfigOptsKey, opts)
s3Opts := func(o *s3.Options) {
// We need this so the SDK doesn't use a subdomain for its requests
o.UsePathStyle = true
}
ctx = context.WithValue(ctx, ctxS3ConfigOptsKey, s3Opts)
return ctx
}