forked from aws/aws-sdk-go-v2
/
mock.go
44 lines (37 loc) · 1.09 KB
/
mock.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
package mock
import (
"net/http"
"net/http/httptest"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/defaults"
)
func init() {
// server is the mock server that simply writes a 200 status back to the client
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
config = defaults.Config()
config.Region = "mock-region"
config.EndpointResolver = aws.ResolveWithEndpoint(aws.Endpoint{
URL: server.URL,
SigningRegion: config.Region,
})
}
// Config is a mock configuration for a localhost mock server returning 200 status.
var config aws.Config
// Config returns a copy of the mock configuration for tests.
func Config() aws.Config { return config.Copy() }
// NewMockClient creates and initializes a client that will connect to the
// mock server
func NewMockClient(cfg aws.Config) *aws.Client {
return aws.NewClient(
cfg,
aws.Metadata{
ServiceName: "Mock",
SigningRegion: cfg.Region,
APIVersion: "2015-12-08",
JSONVersion: "1.1",
TargetPrefix: "MockServer",
},
)
}