-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.go
63 lines (53 loc) · 1.5 KB
/
module.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package aws
import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"go.k6.io/k6/js/modules"
)
func init() {
modules.Register("k6/x/aws", New())
}
type (
// RootModule is the global module instance that will create module
// instances for each VU.
RootModule struct{}
// ModuleInstance represents an instance of the JS module.
ModuleInstance struct {
// vu provides methods for accessing internal k6 objects for a VU
vu modules.VU
// aws is the exported type
aws *AWS
}
)
// Ensure the interfaces are implemented correctly.
var (
_ modules.Instance = &ModuleInstance{}
_ modules.Module = &RootModule{}
)
// New returns a pointer to a new RootModule instance.
func New() *RootModule {
return &RootModule{}
}
// NewModuleInstance implements the modules.Module interface returning a new instance for each VU.
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
return &ModuleInstance{
vu: vu,
aws: &AWS{vu: vu},
}
}
// AWS is the type for our custom API.
type AWS struct {
vu modules.VU // provides methods for accessing internal k6 objects
s3 s3.Client
}
// Exports implements the modules.Instance interface and returns the exported types for the JS module.
func (mi *ModuleInstance) Exports() modules.Exports {
return modules.Exports{
Default: mi.aws,
Named: map[string]interface{}{
"AWSConfig": mi.aws.newConfig,
"S3Client": mi.aws.newS3Client,
"KinesisClient": mi.aws.newKinesisClient,
"EventBridgeClient": mi.aws.newEventBridgeClient,
},
}
}