Skip to content

Commit

Permalink
feat: use k6's new module API
Browse files Browse the repository at this point in the history
Migrate the extension internals to new k6's module API
  • Loading branch information
olegbespalov committed Apr 15, 2022
1 parent 81606e9 commit 62fe315
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/k6
.task
node_modules
vendor/
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
version: "3"

env:
K6_VERSION: v0.32.0
K6_VERSION: v0.37.0

silent: true

Expand Down
18 changes: 9 additions & 9 deletions faker.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package faker

import (
"context"

"github.com/brianvoe/gofakeit/v6"
"github.com/dop251/goja"
"go.k6.io/k6/js/common"
"go.k6.io/k6/js/modules"
"lukechampine.com/frand"
)

type Faker struct {
vu modules.VU

*gofakeit.Faker
}

func newFaker(seed int64) *Faker {
func newFaker(vu modules.VU, seed int64) *Faker {
src := frand.NewSource()

if seed != 0 {
src.Seed(seed)
}

return &Faker{Faker: gofakeit.NewCustom(src)}
return &Faker{vu: vu, Faker: gofakeit.NewCustom(src)}
}

func (f *Faker) Ipv4Address() string {
Expand Down Expand Up @@ -55,10 +55,10 @@ func (f *Faker) RgbColor() []int {
return f.RGBColor()
}

func (f *Faker) ImageJpeg(ctx context.Context, width int, height int) goja.ArrayBuffer {
return common.GetRuntime(ctx).NewArrayBuffer(f.Faker.ImageJpeg(width, height))
func (f *Faker) ImageJpeg(width int, height int) goja.ArrayBuffer {
return f.vu.Runtime().NewArrayBuffer(f.Faker.ImageJpeg(width, height))
}

func (f *Faker) ImagePng(ctx context.Context, width int, height int) goja.ArrayBuffer {
return common.GetRuntime(ctx).NewArrayBuffer(f.Faker.ImagePng(width, height))
func (f *Faker) ImagePng(width int, height int) goja.ArrayBuffer {
return f.vu.Runtime().NewArrayBuffer(f.Faker.ImagePng(width, height))
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.16

require (
github.com/brianvoe/gofakeit/v6 v6.4.1
github.com/dop251/goja v0.0.0-20210427212725-462d53687b0d
github.com/dop251/goja v0.0.0-20220124171016-cfb079cdc7b4
github.com/sirupsen/logrus v1.8.1
go.k6.io/k6 v0.32.0
go.k6.io/k6 v0.37.0
lukechampine.com/frand v1.4.2
)
Loading

0 comments on commit 62fe315

Please sign in to comment.