diff --git a/.golangci.yml b/.golangci.yml index 9578f8c..b99e10b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,6 @@ linters: - gochecknoglobals - lll - wrapcheck - - gochecknoinits # deprecated - deadcode - nosnakecase diff --git a/README.md b/README.md index 7d5145a..e12fbc3 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,10 @@ In addition to the go standard library, the following third-party packages can b - https://github.com/sirupsen/logrus - https://github.com/stretchr/testify - https://github.com/PuerkitoBio/goquery + - https://github.com/tidwall/gjson + - https://github.com/PaesslerAG/jsonpath + - https://github.com/santhosh-tekuri/jsonschema/v5 + - https://github.com/brianvoe/gofakeit/v6 ### Checks @@ -281,6 +285,62 @@ func Default() error { } ``` +### JSON + +The [gjson](https://github.com/tidwall/gjson) and [jsonpath](github.com/PaesslerAG/jsonpath) packages can be used to query JSON documents. + +**gjson** +```go +package main + +import ( + "net/http" + + "github.com/go-resty/resty/v2" + "github.com/stretchr/testify/require" + "github.com/tidwall/gjson" +) + +func Default(require *require.Assertions) { + res, err := resty.New().R().Get("https://httpbin.test.k6.io/get") + + require.NoError(err, "request success") + require.Equal(http.StatusOK, res.StatusCode(), "status code 200") + + body := res.Body() + + val := gjson.GetBytes(body, "headers.Host").Str + + require.Equal("httpbin.test.k6.io", val, "headers.Host value OK") +} +``` + +**jsonpath** +```go +package main + +import ( + "net/http" + + "github.com/PaesslerAG/jsonpath" + "github.com/go-resty/resty/v2" + "github.com/stretchr/testify/require" +) + +func Default(require *require.Assertions) { + body := make(map[string]interface{}) + res, err := resty.New().R().SetResult(&body).Get("https://httpbin.test.k6.io/get") + + require.NoError(err, "request success") + require.Equal(http.StatusOK, res.StatusCode(), "status code 200") + + val, err := jsonpath.Get("$.headers.Host", body) + + require.NoError(err, "$.headers.Host no error") + require.Equal("httpbin.test.k6.io", val, "$.headers.Host value OK") +} +``` + ### Logging The https://github.com/sirupsen/logrus package can be used for logging in the test script. diff --git a/g0/assert.go b/g0/addon/assert.go similarity index 88% rename from g0/assert.go rename to g0/addon/assert.go index 8f04347..fd1ba07 100644 --- a/g0/assert.go +++ b/g0/addon/assert.go @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -package g0 +package addon import ( "errors" @@ -18,11 +18,22 @@ import ( "go.k6.io/k6/metrics" ) +type TestingT interface { + assert.TestingT + require.TestingT + + Check(string, bool) +} + type checker struct { vu modules.VU fail bool } +func NewTestingT(vu modules.VU, fail bool) TestingT { + return &checker{vu: vu, fail: fail} +} + func (c *checker) Errorf(format string, args ...interface{}) { state := c.vu.State() if state == nil { @@ -97,8 +108,7 @@ func (c *checker) FailNow() { } var ( - _ assert.TestingT = (*checker)(nil) - _ require.TestingT = (*checker)(nil) + _ TestingT = (*checker)(nil) errAssertionFailed = errors.New("assertion failed") ) diff --git a/g0/addon/transport.go b/g0/addon/transport.go new file mode 100644 index 0000000..834630e --- /dev/null +++ b/g0/addon/transport.go @@ -0,0 +1,128 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +package addon + +import ( + "bytes" + "io" + "net/http" + "strconv" + "strings" + "time" + + "go.k6.io/k6/js/modules" + khttp "go.k6.io/k6/js/modules/k6/http" + "go.k6.io/k6/lib/netext/httpext" +) + +type tripware struct { + vu modules.VU +} + +var _ http.RoundTripper = (*tripware)(nil) + +func NewTransport(vu modules.VU) http.RoundTripper { + return &tripware{vu: vu} +} + +const ( + httpTimeout = 60 * time.Second + protoFields = 2 +) + +func (t *tripware) toParsedRequest(req *http.Request) (*httpext.ParsedHTTPRequest, error) { + state := t.vu.State() + if state == nil { + return nil, khttp.ErrHTTPForbiddenInInitContext + } + + u := req.URL.String() + + url, err := httpext.NewURL(u, u) + if err != nil { + return nil, err + } + + preq := &httpext.ParsedHTTPRequest{ // nolint:exhaustruct + URL: &url, + Req: req, + Timeout: httpTimeout, + Throw: state.Options.Throw.Bool, + Redirects: state.Options.MaxRedirects, + Cookies: make(map[string]*httpext.HTTPRequestCookie), + TagsAndMeta: t.vu.State().Tags.GetCurrentValues(), + } + + if state.Options.DiscardResponseBodies.Bool { + preq.ResponseType = httpext.ResponseTypeNone + } else { + preq.ResponseType = httpext.ResponseTypeBinary + } + + if req.Body != nil { + data, err := io.ReadAll(req.Body) + if err != nil { + return nil, err + } + + preq.Body = bytes.NewBuffer(data) + + req.Body.Close() + } + + preq.Req.Header.Set("User-Agent", state.Options.UserAgent.String) + + return preq, nil +} + +func (t *tripware) toResponse(req *http.Request, eresp *httpext.Response) (*http.Response, error) { + resp := new(http.Response) + + resp.Request = req + + resp.Header = http.Header{} + + for k, v := range eresp.Headers { + resp.Header.Set(k, v) + } + + resp.Proto = eresp.Proto + fields := strings.SplitN(resp.Proto, "/", protoFields) + + if major, err := strconv.Atoi(fields[0]); err == nil { + resp.ProtoMajor = major + } + + if len(fields) > 0 { + if minor, err := strconv.Atoi(fields[1]); err == nil { + resp.ProtoMinor = minor + } + } + + if eresp.Body != nil { + if data, ok := eresp.Body.([]byte); ok { + resp.Body = io.NopCloser(bytes.NewBuffer(data)) + } + } + + resp.Status = eresp.StatusText + resp.StatusCode = eresp.Status + + return resp, nil +} + +func (t *tripware) RoundTrip(req *http.Request) (*http.Response, error) { + preq, err := t.toParsedRequest(req) + if err != nil { + return nil, err + } + + resp, err := httpext.MakeRequest(t.vu.Context(), t.vu.State(), preq) + if err != nil { + return nil, err + } + + return t.toResponse(req, resp) +} diff --git a/g0/bootstrap.go b/g0/bootstrap.go new file mode 100644 index 0000000..0031e48 --- /dev/null +++ b/g0/bootstrap.go @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +package g0 + +import ( + "github.com/szkiba/xk6-g0/internal/builtin/gjson" + "github.com/szkiba/xk6-g0/internal/builtin/gofakeit" + "github.com/szkiba/xk6-g0/internal/builtin/goquery" + "github.com/szkiba/xk6-g0/internal/builtin/jsonpath" + "github.com/szkiba/xk6-g0/internal/builtin/jsonschema" + "github.com/szkiba/xk6-g0/internal/builtin/logrus" + "github.com/szkiba/xk6-g0/internal/builtin/resty" + "github.com/szkiba/xk6-g0/internal/builtin/stdlib" + "github.com/szkiba/xk6-g0/internal/builtin/testify" + "go.k6.io/k6/js/modules" +) + +func registerBuiltins() { + registerExports(stdlib.Exports) + registerExports(logrus.Exports) + registerExports(resty.Exports) + registerExports(testify.Exports) + registerExports(goquery.Exports) + registerExports(gjson.Exports) + registerExports(jsonpath.Exports) + registerExports(jsonschema.Exports) + registerExports(gofakeit.Exports) +} + +func registerExtension() { + modules.Register("k6/x/g0", New()) +} + +func Bootstrap(addons ...ExportsFunc) { + registerBuiltins() + registerExports(addons...) + redirectStdin() + registerExtension() +} diff --git a/g0/cli.go b/g0/cli.go index 2cd7954..e5b1389 100644 --- a/g0/cli.go +++ b/g0/cli.go @@ -37,7 +37,7 @@ func isRunCommand(args []string) (bool, int) { return true, scriptIndex } -func RedirectStdin() { +func redirectStdin() { isRun, scriptIndex := isRunCommand(os.Args) if !isRun { return diff --git a/g0/context.go b/g0/context.go index c5d52b7..422f3f2 100644 --- a/g0/context.go +++ b/g0/context.go @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + package g0 import ( diff --git a/g0/exports.go b/g0/exports.go index f808c06..d810f0f 100644 --- a/g0/exports.go +++ b/g0/exports.go @@ -8,19 +8,14 @@ import ( "sync" "github.com/imdario/mergo" - "github.com/szkiba/xk6-g0/internal/builtin/goquery" - "github.com/szkiba/xk6-g0/internal/builtin/logrus" - "github.com/szkiba/xk6-g0/internal/builtin/resty" - "github.com/szkiba/xk6-g0/internal/builtin/stdlib" - "github.com/szkiba/xk6-g0/internal/builtin/testify" "github.com/traefik/yaegi/interp" "go.k6.io/k6/js/modules" ) type ExportsFunc func(modules.VU) interp.Exports -func RegisterExports(fn ExportsFunc) { - registry.register(fn) +func registerExports(fn ...ExportsFunc) { + registry.register(fn...) } type exportsRegistry struct { @@ -30,11 +25,11 @@ type exportsRegistry struct { var registry exportsRegistry -func (r *exportsRegistry) register(fn ExportsFunc) { +func (r *exportsRegistry) register(fn ...ExportsFunc) { r.mu.Lock() defer r.mu.Unlock() - r.exports = append(r.exports, fn) + r.exports = append(r.exports, fn...) } func (r *exportsRegistry) merge(vu modules.VU) (interp.Exports, error) { //nolint:varnamelen @@ -51,11 +46,3 @@ func (r *exportsRegistry) merge(vu modules.VU) (interp.Exports, error) { //nolin return symbols, nil } - -func init() { - RegisterExports(stdlib.Exports) - RegisterExports(logrus.Exports) - RegisterExports(resty.Exports) - RegisterExports(testify.Exports) - RegisterExports(goquery.Exports) -} diff --git a/g0/module.go b/g0/module.go index a70a7d1..290d4d8 100644 --- a/g0/module.go +++ b/g0/module.go @@ -7,6 +7,7 @@ package g0 import ( "os" + "github.com/szkiba/xk6-g0/g0/addon" "github.com/szkiba/xk6-g0/internal/builtin/testify/assertions" "github.com/szkiba/xk6-g0/internal/builtin/testify/requirements" "github.com/traefik/yaegi/interp" @@ -27,8 +28,8 @@ func (root *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { // n mod := &Module{ //nolint:exhaustruct vu: vu, yaegi: yaegi, - assert: assertions.New(&checker{fail: false, vu: vu}), - require: requirements.New(&checker{fail: true, vu: vu}), + assert: assertions.New(addon.NewTestingT(vu, false)), + require: requirements.New(addon.NewTestingT(vu, true)), } if err := mod.init(os.Getenv(envScript)); err != nil { diff --git a/go.mod b/go.mod index f251f65..128748a 100644 --- a/go.mod +++ b/go.mod @@ -3,16 +3,20 @@ module github.com/szkiba/xk6-g0 go 1.18 require ( + github.com/PaesslerAG/gval v1.0.0 + github.com/PaesslerAG/jsonpath v0.1.1 github.com/PuerkitoBio/goquery v1.8.1 + github.com/brianvoe/gofakeit/v6 v6.22.0 github.com/dop251/goja v0.0.0-20230402114112-623f9dda9079 github.com/go-resty/resty/v2 v2.7.0 github.com/imdario/mergo v0.3.16 + github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 github.com/sirupsen/logrus v1.9.0 - github.com/stretchr/testify v1.8.0 + github.com/stretchr/testify v1.8.1 github.com/stretchr/testify/_codegen v0.0.0-20230530093840-f97607b89807 + github.com/tidwall/gjson v1.14.3 github.com/traefik/yaegi v0.14.3 go.k6.io/k6 v0.43.1 - ) require ( @@ -39,7 +43,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect github.com/spf13/afero v1.9.5 // indirect - github.com/tidwall/gjson v1.14.3 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/go.sum b/go.sum index e0e53be..d6b5d50 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,11 @@ github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e h1:NeAW1fUYUEWhft github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/PaesslerAG/gval v1.0.0 h1:GEKnRwkWDdf9dOmKcNrar9EA1bz1z9DqPIO1+iLzhd8= +github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v24IBN1I= +github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8= +github.com/PaesslerAG/jsonpath v0.1.1 h1:c1/AToHQMVsduPAa4Vh6xp2U0evy4t8SWp8imEsylIk= +github.com/PaesslerAG/jsonpath v0.1.1/go.mod h1:lVboNxFGal/VwW6d9JzIy56bUsYAP6tH/x80vjnCseY= github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 h1:k+1+doEm31k0rRjCjLnGG3YRkuO9ljaEyS2ajZd6GK8= @@ -48,6 +53,8 @@ github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= +github.com/brianvoe/gofakeit/v6 v6.22.0 h1:BzOsDot1o3cufTfOk+fWKE9nFYojyDV+XHdCWL2+uyE= +github.com/brianvoe/gofakeit/v6 v6.22.0/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= @@ -214,6 +221,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 h1:uIkTLo0AGRc8l7h5l9r+GcYi9qfVPt6lD4/bhmzfiKo= +github.com/santhosh-tekuri/jsonschema/v5 v5.3.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e h1:zWKUYT07mGmVBH+9UgnHXd/ekCK99C8EbDSAt5qsjXE= github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= @@ -222,13 +231,15 @@ github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify/_codegen v0.0.0-20230530093840-f97607b89807 h1:G+OU3/Tx9zLCX9gVsEMFvDhWgruq+89YJ0GhjMqaF9U= github.com/stretchr/testify/_codegen v0.0.0-20230530093840-f97607b89807/go.mod h1:DdemnDXKdn7HC6syua1pqWFZAXub54YSdJ01tIbbBEI= github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= diff --git a/register.go b/init.go similarity index 59% rename from register.go rename to init.go index 2cbee6b..80f66c9 100644 --- a/register.go +++ b/init.go @@ -6,14 +6,8 @@ package g0 import ( "github.com/szkiba/xk6-g0/g0" - "go.k6.io/k6/js/modules" ) func init() { //nolint:gochecknoinits - register() - g0.RedirectStdin() -} - -func register() { - modules.Register("k6/x/g0", g0.New()) + g0.Bootstrap() } diff --git a/internal/builtin/gjson/exports.go b/internal/builtin/gjson/exports.go new file mode 100644 index 0000000..3e9c760 --- /dev/null +++ b/internal/builtin/gjson/exports.go @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +package gjson + +import ( + "github.com/traefik/yaegi/interp" + "go.k6.io/k6/js/modules" +) + +var Symbols = interp.Exports{} + +//go:generate yaegi extract -name gjson github.com/tidwall/gjson + +func Exports(vu modules.VU) interp.Exports { + return Symbols +} diff --git a/internal/builtin/gjson/github_com-tidwall-gjson.go b/internal/builtin/gjson/github_com-tidwall-gjson.go new file mode 100644 index 0000000..df10ed5 --- /dev/null +++ b/internal/builtin/gjson/github_com-tidwall-gjson.go @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +// Code generated by 'yaegi extract github.com/tidwall/gjson'. DO NOT EDIT. + +package gjson + +import ( + "github.com/tidwall/gjson" + "reflect" +) + +func init() { + Symbols["github.com/tidwall/gjson/gjson"] = map[string]reflect.Value{ + // function, constant and variable definitions + "AddModifier": reflect.ValueOf(gjson.AddModifier), + "AppendJSONString": reflect.ValueOf(gjson.AppendJSONString), + "DisableModifiers": reflect.ValueOf(&gjson.DisableModifiers).Elem(), + "False": reflect.ValueOf(gjson.False), + "ForEachLine": reflect.ValueOf(gjson.ForEachLine), + "Get": reflect.ValueOf(gjson.Get), + "GetBytes": reflect.ValueOf(gjson.GetBytes), + "GetMany": reflect.ValueOf(gjson.GetMany), + "GetManyBytes": reflect.ValueOf(gjson.GetManyBytes), + "JSON": reflect.ValueOf(gjson.JSON), + "ModifierExists": reflect.ValueOf(gjson.ModifierExists), + "Null": reflect.ValueOf(gjson.Null), + "Number": reflect.ValueOf(gjson.Number), + "Parse": reflect.ValueOf(gjson.Parse), + "ParseBytes": reflect.ValueOf(gjson.ParseBytes), + "String": reflect.ValueOf(gjson.String), + "True": reflect.ValueOf(gjson.True), + "Valid": reflect.ValueOf(gjson.Valid), + "ValidBytes": reflect.ValueOf(gjson.ValidBytes), + + // type definitions + "Result": reflect.ValueOf((*gjson.Result)(nil)), + "Type": reflect.ValueOf((*gjson.Type)(nil)), + } +} diff --git a/internal/builtin/gofakeit/exports.go b/internal/builtin/gofakeit/exports.go new file mode 100644 index 0000000..ae59d93 --- /dev/null +++ b/internal/builtin/gofakeit/exports.go @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +package gofakeit + +import ( + "github.com/traefik/yaegi/interp" + "go.k6.io/k6/js/modules" +) + +var Symbols = interp.Exports{} + +//go:generate yaegi extract -name gofakeit github.com/brianvoe/gofakeit/v6 + +func Exports(vu modules.VU) interp.Exports { + return Symbols +} diff --git a/internal/builtin/gofakeit/github_com-brianvoe-gofakeit-v6.go b/internal/builtin/gofakeit/github_com-brianvoe-gofakeit-v6.go new file mode 100644 index 0000000..6d32a03 --- /dev/null +++ b/internal/builtin/gofakeit/github_com-brianvoe-gofakeit-v6.go @@ -0,0 +1,374 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +// Code generated by 'yaegi extract github.com/brianvoe/gofakeit/v6'. DO NOT EDIT. + +package gofakeit + +import ( + "github.com/brianvoe/gofakeit/v6" + "reflect" +) + +func init() { + Symbols["github.com/brianvoe/gofakeit/v6/gofakeit"] = map[string]reflect.Value{ + // function, constant and variable definitions + "AchAccount": reflect.ValueOf(gofakeit.AchAccount), + "AchRouting": reflect.ValueOf(gofakeit.AchRouting), + "AddFuncLookup": reflect.ValueOf(gofakeit.AddFuncLookup), + "Address": reflect.ValueOf(gofakeit.Address), + "Adjective": reflect.ValueOf(gofakeit.Adjective), + "AdjectiveDemonstrative": reflect.ValueOf(gofakeit.AdjectiveDemonstrative), + "AdjectiveDescriptive": reflect.ValueOf(gofakeit.AdjectiveDescriptive), + "AdjectiveIndefinite": reflect.ValueOf(gofakeit.AdjectiveIndefinite), + "AdjectiveInterrogative": reflect.ValueOf(gofakeit.AdjectiveInterrogative), + "AdjectivePossessive": reflect.ValueOf(gofakeit.AdjectivePossessive), + "AdjectiveProper": reflect.ValueOf(gofakeit.AdjectiveProper), + "AdjectiveQuantitative": reflect.ValueOf(gofakeit.AdjectiveQuantitative), + "Adverb": reflect.ValueOf(gofakeit.Adverb), + "AdverbDegree": reflect.ValueOf(gofakeit.AdverbDegree), + "AdverbFrequencyDefinite": reflect.ValueOf(gofakeit.AdverbFrequencyDefinite), + "AdverbFrequencyIndefinite": reflect.ValueOf(gofakeit.AdverbFrequencyIndefinite), + "AdverbManner": reflect.ValueOf(gofakeit.AdverbManner), + "AdverbPlace": reflect.ValueOf(gofakeit.AdverbPlace), + "AdverbTimeDefinite": reflect.ValueOf(gofakeit.AdverbTimeDefinite), + "AdverbTimeIndefinite": reflect.ValueOf(gofakeit.AdverbTimeIndefinite), + "Animal": reflect.ValueOf(gofakeit.Animal), + "AnimalType": reflect.ValueOf(gofakeit.AnimalType), + "AppAuthor": reflect.ValueOf(gofakeit.AppAuthor), + "AppName": reflect.ValueOf(gofakeit.AppName), + "AppVersion": reflect.ValueOf(gofakeit.AppVersion), + "BS": reflect.ValueOf(gofakeit.BS), + "BeerAlcohol": reflect.ValueOf(gofakeit.BeerAlcohol), + "BeerBlg": reflect.ValueOf(gofakeit.BeerBlg), + "BeerHop": reflect.ValueOf(gofakeit.BeerHop), + "BeerIbu": reflect.ValueOf(gofakeit.BeerIbu), + "BeerMalt": reflect.ValueOf(gofakeit.BeerMalt), + "BeerName": reflect.ValueOf(gofakeit.BeerName), + "BeerStyle": reflect.ValueOf(gofakeit.BeerStyle), + "BeerYeast": reflect.ValueOf(gofakeit.BeerYeast), + "Bird": reflect.ValueOf(gofakeit.Bird), + "BitcoinAddress": reflect.ValueOf(gofakeit.BitcoinAddress), + "BitcoinPrivateKey": reflect.ValueOf(gofakeit.BitcoinPrivateKey), + "Blurb": reflect.ValueOf(gofakeit.Blurb), + "Book": reflect.ValueOf(gofakeit.Book), + "BookAuthor": reflect.ValueOf(gofakeit.BookAuthor), + "BookGenre": reflect.ValueOf(gofakeit.BookGenre), + "BookTitle": reflect.ValueOf(gofakeit.BookTitle), + "Bool": reflect.ValueOf(gofakeit.Bool), + "Breakfast": reflect.ValueOf(gofakeit.Breakfast), + "BuzzWord": reflect.ValueOf(gofakeit.BuzzWord), + "CSV": reflect.ValueOf(gofakeit.CSV), + "Car": reflect.ValueOf(gofakeit.Car), + "CarFuelType": reflect.ValueOf(gofakeit.CarFuelType), + "CarMaker": reflect.ValueOf(gofakeit.CarMaker), + "CarModel": reflect.ValueOf(gofakeit.CarModel), + "CarTransmissionType": reflect.ValueOf(gofakeit.CarTransmissionType), + "CarType": reflect.ValueOf(gofakeit.CarType), + "Cat": reflect.ValueOf(gofakeit.Cat), + "Categories": reflect.ValueOf(gofakeit.Categories), + "CelebrityActor": reflect.ValueOf(gofakeit.CelebrityActor), + "CelebrityBusiness": reflect.ValueOf(gofakeit.CelebrityBusiness), + "CelebritySport": reflect.ValueOf(gofakeit.CelebritySport), + "ChromeUserAgent": reflect.ValueOf(gofakeit.ChromeUserAgent), + "City": reflect.ValueOf(gofakeit.City), + "Color": reflect.ValueOf(gofakeit.Color), + "Company": reflect.ValueOf(gofakeit.Company), + "CompanySuffix": reflect.ValueOf(gofakeit.CompanySuffix), + "Connective": reflect.ValueOf(gofakeit.Connective), + "ConnectiveCasual": reflect.ValueOf(gofakeit.ConnectiveCasual), + "ConnectiveComparitive": reflect.ValueOf(gofakeit.ConnectiveComparitive), + "ConnectiveComplaint": reflect.ValueOf(gofakeit.ConnectiveComplaint), + "ConnectiveExamplify": reflect.ValueOf(gofakeit.ConnectiveExamplify), + "ConnectiveListing": reflect.ValueOf(gofakeit.ConnectiveListing), + "ConnectiveTime": reflect.ValueOf(gofakeit.ConnectiveTime), + "Contact": reflect.ValueOf(gofakeit.Contact), + "Country": reflect.ValueOf(gofakeit.Country), + "CountryAbr": reflect.ValueOf(gofakeit.CountryAbr), + "CreditCard": reflect.ValueOf(gofakeit.CreditCard), + "CreditCardCvv": reflect.ValueOf(gofakeit.CreditCardCvv), + "CreditCardExp": reflect.ValueOf(gofakeit.CreditCardExp), + "CreditCardNumber": reflect.ValueOf(gofakeit.CreditCardNumber), + "CreditCardType": reflect.ValueOf(gofakeit.CreditCardType), + "Currency": reflect.ValueOf(gofakeit.Currency), + "CurrencyLong": reflect.ValueOf(gofakeit.CurrencyLong), + "CurrencyShort": reflect.ValueOf(gofakeit.CurrencyShort), + "Cusip": reflect.ValueOf(gofakeit.Cusip), + "Date": reflect.ValueOf(gofakeit.Date), + "DateRange": reflect.ValueOf(gofakeit.DateRange), + "Day": reflect.ValueOf(gofakeit.Day), + "Dessert": reflect.ValueOf(gofakeit.Dessert), + "Dice": reflect.ValueOf(gofakeit.Dice), + "Digit": reflect.ValueOf(gofakeit.Digit), + "DigitN": reflect.ValueOf(gofakeit.DigitN), + "Dinner": reflect.ValueOf(gofakeit.Dinner), + "Dog": reflect.ValueOf(gofakeit.Dog), + "DomainName": reflect.ValueOf(gofakeit.DomainName), + "DomainSuffix": reflect.ValueOf(gofakeit.DomainSuffix), + "Drink": reflect.ValueOf(gofakeit.Drink), + "Email": reflect.ValueOf(gofakeit.Email), + "Emoji": reflect.ValueOf(gofakeit.Emoji), + "EmojiAlias": reflect.ValueOf(gofakeit.EmojiAlias), + "EmojiCategory": reflect.ValueOf(gofakeit.EmojiCategory), + "EmojiDescription": reflect.ValueOf(gofakeit.EmojiDescription), + "EmojiTag": reflect.ValueOf(gofakeit.EmojiTag), + "Error": reflect.ValueOf(gofakeit.Error), + "ErrorDatabase": reflect.ValueOf(gofakeit.ErrorDatabase), + "ErrorGRPC": reflect.ValueOf(gofakeit.ErrorGRPC), + "ErrorHTTP": reflect.ValueOf(gofakeit.ErrorHTTP), + "ErrorHTTPClient": reflect.ValueOf(gofakeit.ErrorHTTPClient), + "ErrorHTTPServer": reflect.ValueOf(gofakeit.ErrorHTTPServer), + "ErrorObject": reflect.ValueOf(gofakeit.ErrorObject), + "ErrorRuntime": reflect.ValueOf(gofakeit.ErrorRuntime), + "ErrorValidation": reflect.ValueOf(gofakeit.ErrorValidation), + "FarmAnimal": reflect.ValueOf(gofakeit.FarmAnimal), + "FileExtension": reflect.ValueOf(gofakeit.FileExtension), + "FileMimeType": reflect.ValueOf(gofakeit.FileMimeType), + "FirefoxUserAgent": reflect.ValueOf(gofakeit.FirefoxUserAgent), + "FirstName": reflect.ValueOf(gofakeit.FirstName), + "FlipACoin": reflect.ValueOf(gofakeit.FlipACoin), + "Float32": reflect.ValueOf(gofakeit.Float32), + "Float32Range": reflect.ValueOf(gofakeit.Float32Range), + "Float64": reflect.ValueOf(gofakeit.Float64), + "Float64Range": reflect.ValueOf(gofakeit.Float64Range), + "Fruit": reflect.ValueOf(gofakeit.Fruit), + "FuncLookups": reflect.ValueOf(&gofakeit.FuncLookups).Elem(), + "Gamertag": reflect.ValueOf(gofakeit.Gamertag), + "Gender": reflect.ValueOf(gofakeit.Gender), + "Generate": reflect.ValueOf(gofakeit.Generate), + "GetFuncLookup": reflect.ValueOf(gofakeit.GetFuncLookup), + "HTTPMethod": reflect.ValueOf(gofakeit.HTTPMethod), + "HTTPStatusCode": reflect.ValueOf(gofakeit.HTTPStatusCode), + "HTTPStatusCodeSimple": reflect.ValueOf(gofakeit.HTTPStatusCodeSimple), + "HTTPVersion": reflect.ValueOf(gofakeit.HTTPVersion), + "HackerAbbreviation": reflect.ValueOf(gofakeit.HackerAbbreviation), + "HackerAdjective": reflect.ValueOf(gofakeit.HackerAdjective), + "HackerNoun": reflect.ValueOf(gofakeit.HackerNoun), + "HackerPhrase": reflect.ValueOf(gofakeit.HackerPhrase), + "HackerVerb": reflect.ValueOf(gofakeit.HackerVerb), + "HackeringVerb": reflect.ValueOf(gofakeit.HackeringVerb), + "HexColor": reflect.ValueOf(gofakeit.HexColor), + "HexUint128": reflect.ValueOf(gofakeit.HexUint128), + "HexUint16": reflect.ValueOf(gofakeit.HexUint16), + "HexUint256": reflect.ValueOf(gofakeit.HexUint256), + "HexUint32": reflect.ValueOf(gofakeit.HexUint32), + "HexUint64": reflect.ValueOf(gofakeit.HexUint64), + "HexUint8": reflect.ValueOf(gofakeit.HexUint8), + "HipsterParagraph": reflect.ValueOf(gofakeit.HipsterParagraph), + "HipsterSentence": reflect.ValueOf(gofakeit.HipsterSentence), + "HipsterWord": reflect.ValueOf(gofakeit.HipsterWord), + "Hobby": reflect.ValueOf(gofakeit.Hobby), + "Hour": reflect.ValueOf(gofakeit.Hour), + "IPv4Address": reflect.ValueOf(gofakeit.IPv4Address), + "IPv6Address": reflect.ValueOf(gofakeit.IPv6Address), + "Image": reflect.ValueOf(gofakeit.Image), + "ImageJpeg": reflect.ValueOf(gofakeit.ImageJpeg), + "ImagePng": reflect.ValueOf(gofakeit.ImagePng), + "ImageURL": reflect.ValueOf(gofakeit.ImageURL), + "InputName": reflect.ValueOf(gofakeit.InputName), + "Int16": reflect.ValueOf(gofakeit.Int16), + "Int32": reflect.ValueOf(gofakeit.Int32), + "Int64": reflect.ValueOf(gofakeit.Int64), + "Int8": reflect.ValueOf(gofakeit.Int8), + "IntRange": reflect.ValueOf(gofakeit.IntRange), + "Isin": reflect.ValueOf(gofakeit.Isin), + "JSON": reflect.ValueOf(gofakeit.JSON), + "Job": reflect.ValueOf(gofakeit.Job), + "JobDescriptor": reflect.ValueOf(gofakeit.JobDescriptor), + "JobLevel": reflect.ValueOf(gofakeit.JobLevel), + "JobTitle": reflect.ValueOf(gofakeit.JobTitle), + "Language": reflect.ValueOf(gofakeit.Language), + "LanguageAbbreviation": reflect.ValueOf(gofakeit.LanguageAbbreviation), + "LanguageBCP": reflect.ValueOf(gofakeit.LanguageBCP), + "LastName": reflect.ValueOf(gofakeit.LastName), + "Latitude": reflect.ValueOf(gofakeit.Latitude), + "LatitudeInRange": reflect.ValueOf(gofakeit.LatitudeInRange), + "Letter": reflect.ValueOf(gofakeit.Letter), + "LetterN": reflect.ValueOf(gofakeit.LetterN), + "Lexify": reflect.ValueOf(gofakeit.Lexify), + "LogLevel": reflect.ValueOf(gofakeit.LogLevel), + "Longitude": reflect.ValueOf(gofakeit.Longitude), + "LongitudeInRange": reflect.ValueOf(gofakeit.LongitudeInRange), + "LoremIpsumParagraph": reflect.ValueOf(gofakeit.LoremIpsumParagraph), + "LoremIpsumSentence": reflect.ValueOf(gofakeit.LoremIpsumSentence), + "LoremIpsumWord": reflect.ValueOf(gofakeit.LoremIpsumWord), + "Lunch": reflect.ValueOf(gofakeit.Lunch), + "MacAddress": reflect.ValueOf(gofakeit.MacAddress), + "Map": reflect.ValueOf(gofakeit.Map), + "MiddleName": reflect.ValueOf(gofakeit.MiddleName), + "MinecraftAnimal": reflect.ValueOf(gofakeit.MinecraftAnimal), + "MinecraftArmorPart": reflect.ValueOf(gofakeit.MinecraftArmorPart), + "MinecraftArmorTier": reflect.ValueOf(gofakeit.MinecraftArmorTier), + "MinecraftBiome": reflect.ValueOf(gofakeit.MinecraftBiome), + "MinecraftDye": reflect.ValueOf(gofakeit.MinecraftDye), + "MinecraftFood": reflect.ValueOf(gofakeit.MinecraftFood), + "MinecraftMobBoss": reflect.ValueOf(gofakeit.MinecraftMobBoss), + "MinecraftMobHostile": reflect.ValueOf(gofakeit.MinecraftMobHostile), + "MinecraftMobNeutral": reflect.ValueOf(gofakeit.MinecraftMobNeutral), + "MinecraftMobPassive": reflect.ValueOf(gofakeit.MinecraftMobPassive), + "MinecraftOre": reflect.ValueOf(gofakeit.MinecraftOre), + "MinecraftTool": reflect.ValueOf(gofakeit.MinecraftTool), + "MinecraftVillagerJob": reflect.ValueOf(gofakeit.MinecraftVillagerJob), + "MinecraftVillagerLevel": reflect.ValueOf(gofakeit.MinecraftVillagerLevel), + "MinecraftVillagerStation": reflect.ValueOf(gofakeit.MinecraftVillagerStation), + "MinecraftWeapon": reflect.ValueOf(gofakeit.MinecraftWeapon), + "MinecraftWeather": reflect.ValueOf(gofakeit.MinecraftWeather), + "MinecraftWood": reflect.ValueOf(gofakeit.MinecraftWood), + "Minute": reflect.ValueOf(gofakeit.Minute), + "Month": reflect.ValueOf(gofakeit.Month), + "MonthString": reflect.ValueOf(gofakeit.MonthString), + "Movie": reflect.ValueOf(gofakeit.Movie), + "MovieGenre": reflect.ValueOf(gofakeit.MovieGenre), + "MovieName": reflect.ValueOf(gofakeit.MovieName), + "Name": reflect.ValueOf(gofakeit.Name), + "NamePrefix": reflect.ValueOf(gofakeit.NamePrefix), + "NameSuffix": reflect.ValueOf(gofakeit.NameSuffix), + "NanoSecond": reflect.ValueOf(gofakeit.NanoSecond), + "New": reflect.ValueOf(gofakeit.New), + "NewCrypto": reflect.ValueOf(gofakeit.NewCrypto), + "NewCustom": reflect.ValueOf(gofakeit.NewCustom), + "NewMapParams": reflect.ValueOf(gofakeit.NewMapParams), + "NewUnlocked": reflect.ValueOf(gofakeit.NewUnlocked), + "NiceColors": reflect.ValueOf(gofakeit.NiceColors), + "Noun": reflect.ValueOf(gofakeit.Noun), + "NounAbstract": reflect.ValueOf(gofakeit.NounAbstract), + "NounCollectiveAnimal": reflect.ValueOf(gofakeit.NounCollectiveAnimal), + "NounCollectivePeople": reflect.ValueOf(gofakeit.NounCollectivePeople), + "NounCollectiveThing": reflect.ValueOf(gofakeit.NounCollectiveThing), + "NounCommon": reflect.ValueOf(gofakeit.NounCommon), + "NounConcrete": reflect.ValueOf(gofakeit.NounConcrete), + "NounCountable": reflect.ValueOf(gofakeit.NounCountable), + "NounProper": reflect.ValueOf(gofakeit.NounProper), + "NounUncountable": reflect.ValueOf(gofakeit.NounUncountable), + "Number": reflect.ValueOf(gofakeit.Number), + "Numerify": reflect.ValueOf(gofakeit.Numerify), + "OperaUserAgent": reflect.ValueOf(gofakeit.OperaUserAgent), + "Paragraph": reflect.ValueOf(gofakeit.Paragraph), + "Password": reflect.ValueOf(gofakeit.Password), + "Person": reflect.ValueOf(gofakeit.Person), + "PetName": reflect.ValueOf(gofakeit.PetName), + "Phone": reflect.ValueOf(gofakeit.Phone), + "PhoneFormatted": reflect.ValueOf(gofakeit.PhoneFormatted), + "Phrase": reflect.ValueOf(gofakeit.Phrase), + "PhraseAdverb": reflect.ValueOf(gofakeit.PhraseAdverb), + "PhraseNoun": reflect.ValueOf(gofakeit.PhraseNoun), + "PhrasePreposition": reflect.ValueOf(gofakeit.PhrasePreposition), + "PhraseVerb": reflect.ValueOf(gofakeit.PhraseVerb), + "Preposition": reflect.ValueOf(gofakeit.Preposition), + "PrepositionCompound": reflect.ValueOf(gofakeit.PrepositionCompound), + "PrepositionDouble": reflect.ValueOf(gofakeit.PrepositionDouble), + "PrepositionSimple": reflect.ValueOf(gofakeit.PrepositionSimple), + "Price": reflect.ValueOf(gofakeit.Price), + "ProgrammingLanguage": reflect.ValueOf(gofakeit.ProgrammingLanguage), + "ProgrammingLanguageBest": reflect.ValueOf(gofakeit.ProgrammingLanguageBest), + "Pronoun": reflect.ValueOf(gofakeit.Pronoun), + "PronounDemonstrative": reflect.ValueOf(gofakeit.PronounDemonstrative), + "PronounIndefinite": reflect.ValueOf(gofakeit.PronounIndefinite), + "PronounInterrogative": reflect.ValueOf(gofakeit.PronounInterrogative), + "PronounObject": reflect.ValueOf(gofakeit.PronounObject), + "PronounPersonal": reflect.ValueOf(gofakeit.PronounPersonal), + "PronounPossessive": reflect.ValueOf(gofakeit.PronounPossessive), + "PronounReflective": reflect.ValueOf(gofakeit.PronounReflective), + "PronounRelative": reflect.ValueOf(gofakeit.PronounRelative), + "Question": reflect.ValueOf(gofakeit.Question), + "Quote": reflect.ValueOf(gofakeit.Quote), + "RGBColor": reflect.ValueOf(gofakeit.RGBColor), + "RandomInt": reflect.ValueOf(gofakeit.RandomInt), + "RandomMapKey": reflect.ValueOf(gofakeit.RandomMapKey), + "RandomString": reflect.ValueOf(gofakeit.RandomString), + "RandomUint": reflect.ValueOf(gofakeit.RandomUint), + "Regex": reflect.ValueOf(gofakeit.Regex), + "RemoveFuncLookup": reflect.ValueOf(gofakeit.RemoveFuncLookup), + "SQL": reflect.ValueOf(gofakeit.SQL), + "SSN": reflect.ValueOf(gofakeit.SSN), + "SafariUserAgent": reflect.ValueOf(gofakeit.SafariUserAgent), + "SafeColor": reflect.ValueOf(gofakeit.SafeColor), + "Second": reflect.ValueOf(gofakeit.Second), + "Seed": reflect.ValueOf(gofakeit.Seed), + "Sentence": reflect.ValueOf(gofakeit.Sentence), + "SentenceSimple": reflect.ValueOf(gofakeit.SentenceSimple), + "SetGlobalFaker": reflect.ValueOf(gofakeit.SetGlobalFaker), + "ShuffleAnySlice": reflect.ValueOf(gofakeit.ShuffleAnySlice), + "ShuffleInts": reflect.ValueOf(gofakeit.ShuffleInts), + "ShuffleStrings": reflect.ValueOf(gofakeit.ShuffleStrings), + "Slice": reflect.ValueOf(gofakeit.Slice), + "Slogan": reflect.ValueOf(gofakeit.Slogan), + "Snack": reflect.ValueOf(gofakeit.Snack), + "State": reflect.ValueOf(gofakeit.State), + "StateAbr": reflect.ValueOf(gofakeit.StateAbr), + "Street": reflect.ValueOf(gofakeit.Street), + "StreetName": reflect.ValueOf(gofakeit.StreetName), + "StreetNumber": reflect.ValueOf(gofakeit.StreetNumber), + "StreetPrefix": reflect.ValueOf(gofakeit.StreetPrefix), + "StreetSuffix": reflect.ValueOf(gofakeit.StreetSuffix), + "Struct": reflect.ValueOf(gofakeit.Struct), + "Svg": reflect.ValueOf(gofakeit.Svg), + "Teams": reflect.ValueOf(gofakeit.Teams), + "TimeZone": reflect.ValueOf(gofakeit.TimeZone), + "TimeZoneAbv": reflect.ValueOf(gofakeit.TimeZoneAbv), + "TimeZoneFull": reflect.ValueOf(gofakeit.TimeZoneFull), + "TimeZoneOffset": reflect.ValueOf(gofakeit.TimeZoneOffset), + "TimeZoneRegion": reflect.ValueOf(gofakeit.TimeZoneRegion), + "URL": reflect.ValueOf(gofakeit.URL), + "UUID": reflect.ValueOf(gofakeit.UUID), + "Uint16": reflect.ValueOf(gofakeit.Uint16), + "Uint32": reflect.ValueOf(gofakeit.Uint32), + "Uint64": reflect.ValueOf(gofakeit.Uint64), + "Uint8": reflect.ValueOf(gofakeit.Uint8), + "UintRange": reflect.ValueOf(gofakeit.UintRange), + "UserAgent": reflect.ValueOf(gofakeit.UserAgent), + "Username": reflect.ValueOf(gofakeit.Username), + "Vegetable": reflect.ValueOf(gofakeit.Vegetable), + "Verb": reflect.ValueOf(gofakeit.Verb), + "VerbAction": reflect.ValueOf(gofakeit.VerbAction), + "VerbHelping": reflect.ValueOf(gofakeit.VerbHelping), + "VerbIntransitive": reflect.ValueOf(gofakeit.VerbIntransitive), + "VerbLinking": reflect.ValueOf(gofakeit.VerbLinking), + "VerbTransitive": reflect.ValueOf(gofakeit.VerbTransitive), + "Vowel": reflect.ValueOf(gofakeit.Vowel), + "WeekDay": reflect.ValueOf(gofakeit.WeekDay), + "Weighted": reflect.ValueOf(gofakeit.Weighted), + "Word": reflect.ValueOf(gofakeit.Word), + "XML": reflect.ValueOf(gofakeit.XML), + "Year": reflect.ValueOf(gofakeit.Year), + "Zip": reflect.ValueOf(gofakeit.Zip), + + // type definitions + "AddressInfo": reflect.ValueOf((*gofakeit.AddressInfo)(nil)), + "BookInfo": reflect.ValueOf((*gofakeit.BookInfo)(nil)), + "CSVOptions": reflect.ValueOf((*gofakeit.CSVOptions)(nil)), + "CarInfo": reflect.ValueOf((*gofakeit.CarInfo)(nil)), + "ContactInfo": reflect.ValueOf((*gofakeit.ContactInfo)(nil)), + "CreditCardInfo": reflect.ValueOf((*gofakeit.CreditCardInfo)(nil)), + "CreditCardOptions": reflect.ValueOf((*gofakeit.CreditCardOptions)(nil)), + "CurrencyInfo": reflect.ValueOf((*gofakeit.CurrencyInfo)(nil)), + "Fakeable": reflect.ValueOf((*gofakeit.Fakeable)(nil)), + "Faker": reflect.ValueOf((*gofakeit.Faker)(nil)), + "Field": reflect.ValueOf((*gofakeit.Field)(nil)), + "Info": reflect.ValueOf((*gofakeit.Info)(nil)), + "JSONOptions": reflect.ValueOf((*gofakeit.JSONOptions)(nil)), + "JobInfo": reflect.ValueOf((*gofakeit.JobInfo)(nil)), + "MapParams": reflect.ValueOf((*gofakeit.MapParams)(nil)), + "MapParamsValue": reflect.ValueOf((*gofakeit.MapParamsValue)(nil)), + "MovieInfo": reflect.ValueOf((*gofakeit.MovieInfo)(nil)), + "Param": reflect.ValueOf((*gofakeit.Param)(nil)), + "PersonInfo": reflect.ValueOf((*gofakeit.PersonInfo)(nil)), + "SQLOptions": reflect.ValueOf((*gofakeit.SQLOptions)(nil)), + "SVGOptions": reflect.ValueOf((*gofakeit.SVGOptions)(nil)), + "XMLOptions": reflect.ValueOf((*gofakeit.XMLOptions)(nil)), + + // interface wrapper definitions + "_Fakeable": reflect.ValueOf((*_github_com_brianvoe_gofakeit_v6_Fakeable)(nil)), + } +} + +// _github_com_brianvoe_gofakeit_v6_Fakeable is an interface wrapper for Fakeable type +type _github_com_brianvoe_gofakeit_v6_Fakeable struct { + IValue interface{} + WFake func(faker *gofakeit.Faker) interface{} +} + +func (W _github_com_brianvoe_gofakeit_v6_Fakeable) Fake(faker *gofakeit.Faker) interface{} { + return W.WFake(faker) +} diff --git a/internal/builtin/goquery/exports.go b/internal/builtin/goquery/exports.go index 22314ac..c3c6840 100644 --- a/internal/builtin/goquery/exports.go +++ b/internal/builtin/goquery/exports.go @@ -10,7 +10,7 @@ import ( "github.com/PuerkitoBio/goquery" "github.com/imdario/mergo" - "github.com/szkiba/xk6-g0/internal/builtin/stdlib" + "github.com/szkiba/xk6-g0/g0/addon" "github.com/traefik/yaegi/interp" "go.k6.io/k6/js/modules" ) @@ -21,7 +21,7 @@ var Symbols = interp.Exports{} func Exports(vu modules.VU) interp.Exports { newDocument := func(url string) (*goquery.Document, error) { - client := &http.Client{Transport: stdlib.NewTransport(vu)} + client := &http.Client{Transport: addon.NewTransport(vu)} resp, err := client.Get(url) if err != nil { diff --git a/internal/builtin/goquery/github_com-PuerkitoBio-goquery.go b/internal/builtin/goquery/github_com-PuerkitoBio-goquery.go index d0b89ac..3219d81 100644 --- a/internal/builtin/goquery/github_com-PuerkitoBio-goquery.go +++ b/internal/builtin/goquery/github_com-PuerkitoBio-goquery.go @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + // Code generated by 'yaegi extract github.com/PuerkitoBio/goquery'. DO NOT EDIT. package goquery diff --git a/internal/builtin/jsonpath/exports.go b/internal/builtin/jsonpath/exports.go new file mode 100644 index 0000000..ef5713e --- /dev/null +++ b/internal/builtin/jsonpath/exports.go @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +package jsonpath + +import ( + "github.com/traefik/yaegi/interp" + "go.k6.io/k6/js/modules" +) + +var Symbols = interp.Exports{} + +//go:generate yaegi extract -name jsonpath github.com/PaesslerAG/jsonpath github.com/PaesslerAG/gval + +func Exports(vu modules.VU) interp.Exports { + return Symbols +} diff --git a/internal/builtin/jsonpath/github_com-PaesslerAG-gval.go b/internal/builtin/jsonpath/github_com-PaesslerAG-gval.go new file mode 100644 index 0000000..c3f1a55 --- /dev/null +++ b/internal/builtin/jsonpath/github_com-PaesslerAG-gval.go @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +// Code generated by 'yaegi extract github.com/PaesslerAG/gval'. DO NOT EDIT. + +package jsonpath + +import ( + "github.com/PaesslerAG/gval" + "reflect" +) + +func init() { + Symbols["github.com/PaesslerAG/gval/gval"] = map[string]reflect.Value{ + // function, constant and variable definitions + "Arithmetic": reflect.ValueOf(gval.Arithmetic), + "Base": reflect.ValueOf(gval.Base), + "Bitmask": reflect.ValueOf(gval.Bitmask), + "Constant": reflect.ValueOf(gval.Constant), + "Evaluate": reflect.ValueOf(gval.Evaluate), + "Full": reflect.ValueOf(gval.Full), + "Function": reflect.ValueOf(gval.Function), + "InfixBoolOperator": reflect.ValueOf(gval.InfixBoolOperator), + "InfixEvalOperator": reflect.ValueOf(gval.InfixEvalOperator), + "InfixNumberOperator": reflect.ValueOf(gval.InfixNumberOperator), + "InfixOperator": reflect.ValueOf(gval.InfixOperator), + "InfixShortCircuit": reflect.ValueOf(gval.InfixShortCircuit), + "InfixTextOperator": reflect.ValueOf(gval.InfixTextOperator), + "JSON": reflect.ValueOf(gval.JSON), + "NewLanguage": reflect.ValueOf(gval.NewLanguage), + "PostfixOperator": reflect.ValueOf(gval.PostfixOperator), + "Precedence": reflect.ValueOf(gval.Precedence), + "PrefixExtension": reflect.ValueOf(gval.PrefixExtension), + "PrefixMetaPrefix": reflect.ValueOf(gval.PrefixMetaPrefix), + "PrefixOperator": reflect.ValueOf(gval.PrefixOperator), + "PropositionalLogic": reflect.ValueOf(gval.PropositionalLogic), + "Text": reflect.ValueOf(gval.Text), + "VariableSelector": reflect.ValueOf(gval.VariableSelector), + + // type definitions + "Evaluable": reflect.ValueOf((*gval.Evaluable)(nil)), + "Evaluables": reflect.ValueOf((*gval.Evaluables)(nil)), + "Language": reflect.ValueOf((*gval.Language)(nil)), + "Parser": reflect.ValueOf((*gval.Parser)(nil)), + } +} diff --git a/internal/builtin/jsonpath/github_com-PaesslerAG-jsonpath.go b/internal/builtin/jsonpath/github_com-PaesslerAG-jsonpath.go new file mode 100644 index 0000000..8afe1ca --- /dev/null +++ b/internal/builtin/jsonpath/github_com-PaesslerAG-jsonpath.go @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +// Code generated by 'yaegi extract github.com/PaesslerAG/jsonpath'. DO NOT EDIT. + +package jsonpath + +import ( + "github.com/PaesslerAG/jsonpath" + "reflect" +) + +func init() { + Symbols["github.com/PaesslerAG/jsonpath/jsonpath"] = map[string]reflect.Value{ + // function, constant and variable definitions + "Get": reflect.ValueOf(jsonpath.Get), + "Language": reflect.ValueOf(jsonpath.Language), + "New": reflect.ValueOf(jsonpath.New), + "PlaceholderExtension": reflect.ValueOf(jsonpath.PlaceholderExtension), + } +} diff --git a/internal/builtin/jsonschema/exports.go b/internal/builtin/jsonschema/exports.go new file mode 100644 index 0000000..250a819 --- /dev/null +++ b/internal/builtin/jsonschema/exports.go @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +package jsonschema + +import ( + "github.com/traefik/yaegi/interp" + "go.k6.io/k6/js/modules" +) + +var Symbols = interp.Exports{} + +//go:generate yaegi extract -name jsonschema github.com/santhosh-tekuri/jsonschema/v5 + +func Exports(vu modules.VU) interp.Exports { + return Symbols +} diff --git a/internal/builtin/jsonschema/github_com-santhosh-tekuri-jsonschema-v5.go b/internal/builtin/jsonschema/github_com-santhosh-tekuri-jsonschema-v5.go new file mode 100644 index 0000000..a2ff534 --- /dev/null +++ b/internal/builtin/jsonschema/github_com-santhosh-tekuri-jsonschema-v5.go @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2023 Iván Szkiba +// +// SPDX-License-Identifier: MIT + +// Code generated by 'yaegi extract github.com/santhosh-tekuri/jsonschema/v5'. DO NOT EDIT. + +package jsonschema + +import ( + "github.com/santhosh-tekuri/jsonschema/v5" + "reflect" +) + +func init() { + Symbols["github.com/santhosh-tekuri/jsonschema/v5/jsonschema"] = map[string]reflect.Value{ + // function, constant and variable definitions + "Compile": reflect.ValueOf(jsonschema.Compile), + "CompileString": reflect.ValueOf(jsonschema.CompileString), + "Decoders": reflect.ValueOf(&jsonschema.Decoders).Elem(), + "Draft2019": reflect.ValueOf(&jsonschema.Draft2019).Elem(), + "Draft2020": reflect.ValueOf(&jsonschema.Draft2020).Elem(), + "Draft4": reflect.ValueOf(&jsonschema.Draft4).Elem(), + "Draft6": reflect.ValueOf(&jsonschema.Draft6).Elem(), + "Draft7": reflect.ValueOf(&jsonschema.Draft7).Elem(), + "Formats": reflect.ValueOf(&jsonschema.Formats).Elem(), + "LoadURL": reflect.ValueOf(&jsonschema.LoadURL).Elem(), + "Loaders": reflect.ValueOf(&jsonschema.Loaders).Elem(), + "MediaTypes": reflect.ValueOf(&jsonschema.MediaTypes).Elem(), + "MustCompile": reflect.ValueOf(jsonschema.MustCompile), + "MustCompileString": reflect.ValueOf(jsonschema.MustCompileString), + "NewCompiler": reflect.ValueOf(jsonschema.NewCompiler), + + // type definitions + "Basic": reflect.ValueOf((*jsonschema.Basic)(nil)), + "BasicError": reflect.ValueOf((*jsonschema.BasicError)(nil)), + "Compiler": reflect.ValueOf((*jsonschema.Compiler)(nil)), + "CompilerContext": reflect.ValueOf((*jsonschema.CompilerContext)(nil)), + "Detailed": reflect.ValueOf((*jsonschema.Detailed)(nil)), + "Draft": reflect.ValueOf((*jsonschema.Draft)(nil)), + "ExtCompiler": reflect.ValueOf((*jsonschema.ExtCompiler)(nil)), + "ExtSchema": reflect.ValueOf((*jsonschema.ExtSchema)(nil)), + "Flag": reflect.ValueOf((*jsonschema.Flag)(nil)), + "InfiniteLoopError": reflect.ValueOf((*jsonschema.InfiniteLoopError)(nil)), + "InvalidJSONTypeError": reflect.ValueOf((*jsonschema.InvalidJSONTypeError)(nil)), + "LoaderNotFoundError": reflect.ValueOf((*jsonschema.LoaderNotFoundError)(nil)), + "Schema": reflect.ValueOf((*jsonschema.Schema)(nil)), + "SchemaError": reflect.ValueOf((*jsonschema.SchemaError)(nil)), + "ValidationContext": reflect.ValueOf((*jsonschema.ValidationContext)(nil)), + "ValidationError": reflect.ValueOf((*jsonschema.ValidationError)(nil)), + + // interface wrapper definitions + "_ExtCompiler": reflect.ValueOf((*_github_com_santhosh_tekuri_jsonschema_v5_ExtCompiler)(nil)), + "_ExtSchema": reflect.ValueOf((*_github_com_santhosh_tekuri_jsonschema_v5_ExtSchema)(nil)), + } +} + +// _github_com_santhosh_tekuri_jsonschema_v5_ExtCompiler is an interface wrapper for ExtCompiler type +type _github_com_santhosh_tekuri_jsonschema_v5_ExtCompiler struct { + IValue interface{} + WCompile func(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error) +} + +func (W _github_com_santhosh_tekuri_jsonschema_v5_ExtCompiler) Compile(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error) { + return W.WCompile(ctx, m) +} + +// _github_com_santhosh_tekuri_jsonschema_v5_ExtSchema is an interface wrapper for ExtSchema type +type _github_com_santhosh_tekuri_jsonschema_v5_ExtSchema struct { + IValue interface{} + WValidate func(ctx jsonschema.ValidationContext, v interface{}) error +} + +func (W _github_com_santhosh_tekuri_jsonschema_v5_ExtSchema) Validate(ctx jsonschema.ValidationContext, v interface{}) error { + return W.WValidate(ctx, v) +} diff --git a/internal/builtin/resty/exports.go b/internal/builtin/resty/exports.go index 5ea479f..17dba99 100644 --- a/internal/builtin/resty/exports.go +++ b/internal/builtin/resty/exports.go @@ -9,7 +9,7 @@ import ( "github.com/go-resty/resty/v2" "github.com/imdario/mergo" - "github.com/szkiba/xk6-g0/internal/builtin/stdlib" + "github.com/szkiba/xk6-g0/g0/addon" "github.com/traefik/yaegi/interp" "go.k6.io/k6/js/modules" ) @@ -19,7 +19,7 @@ var Symbols = interp.Exports{} //go:generate yaegi extract -name resty github.com/go-resty/resty/v2 func Exports(vu modules.VU) interp.Exports { - transport := stdlib.NewTransport(vu) + transport := addon.NewTransport(vu) newClient := func() *resty.Client { client := resty.New() diff --git a/internal/builtin/stdlib/http.go b/internal/builtin/stdlib/http.go index b360cdc..cfd72c7 100644 --- a/internal/builtin/stdlib/http.go +++ b/internal/builtin/stdlib/http.go @@ -5,132 +5,16 @@ package stdlib import ( - "bytes" - "io" "net/http" "reflect" - "strconv" - "strings" - "time" + "github.com/szkiba/xk6-g0/g0/addon" "github.com/traefik/yaegi/interp" "go.k6.io/k6/js/modules" - khttp "go.k6.io/k6/js/modules/k6/http" - "go.k6.io/k6/lib/netext/httpext" ) -type tripware struct { - vu modules.VU -} - -const ( - httpTimeout = 60 * time.Second - protoFields = 2 -) - -func (t *tripware) toParsedRequest(req *http.Request) (*httpext.ParsedHTTPRequest, error) { - state := t.vu.State() - if state == nil { - return nil, khttp.ErrHTTPForbiddenInInitContext - } - - u := req.URL.String() - - url, err := httpext.NewURL(u, u) - if err != nil { - return nil, err - } - - preq := &httpext.ParsedHTTPRequest{ - URL: &url, - Req: req, - Timeout: httpTimeout, - Throw: state.Options.Throw.Bool, - Redirects: state.Options.MaxRedirects, - Cookies: make(map[string]*httpext.HTTPRequestCookie), - TagsAndMeta: t.vu.State().Tags.GetCurrentValues(), - } - - if state.Options.DiscardResponseBodies.Bool { - preq.ResponseType = httpext.ResponseTypeNone - } else { - preq.ResponseType = httpext.ResponseTypeBinary - } - - if req.Body != nil { - data, err := io.ReadAll(req.Body) - if err != nil { - return nil, err - } - - preq.Body = bytes.NewBuffer(data) - - req.Body.Close() - } - - preq.Req.Header.Set("User-Agent", state.Options.UserAgent.String) - - return preq, nil -} - -func (t *tripware) toResponse(req *http.Request, eresp *httpext.Response) (*http.Response, error) { - resp := new(http.Response) - - resp.Request = req - - resp.Header = http.Header{} - - for k, v := range eresp.Headers { - resp.Header.Set(k, v) - } - - resp.Proto = eresp.Proto - fields := strings.SplitN(resp.Proto, "/", protoFields) - - if major, err := strconv.Atoi(fields[0]); err == nil { - resp.ProtoMajor = major - } - - if len(fields) > 0 { - if minor, err := strconv.Atoi(fields[1]); err == nil { - resp.ProtoMinor = minor - } - } - - if eresp.Body != nil { - if data, ok := eresp.Body.([]byte); ok { - resp.Body = io.NopCloser(bytes.NewBuffer(data)) - } - } - - resp.Status = eresp.StatusText - resp.StatusCode = eresp.Status - - return resp, nil -} - -func (t *tripware) RoundTrip(req *http.Request) (*http.Response, error) { - preq, err := t.toParsedRequest(req) - if err != nil { - return nil, err - } - - resp, err := httpext.MakeRequest(t.vu.Context(), t.vu.State(), preq) - if err != nil { - return nil, err - } - - return t.toResponse(req, resp) -} - -var _ http.RoundTripper = (*tripware)(nil) - -func NewTransport(vu modules.VU) http.RoundTripper { - return &tripware{vu: vu} -} - func httpExports(vu modules.VU) interp.Exports { - transport := NewTransport(vu) + transport := addon.NewTransport(vu) client := &http.Client{Transport: transport} return interp.Exports{ diff --git a/register_test.go b/register_test.go deleted file mode 100644 index 1b7b542..0000000 --- a/register_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Iván Szkiba -// -// SPDX-License-Identifier: MIT - -package g0 - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestRegister(t *testing.T) { - t.Parallel() - - assert.Panics(t, register) // already registered -} diff --git a/scripts/gjson/script.go b/scripts/gjson/script.go new file mode 100644 index 0000000..117ebfa --- /dev/null +++ b/scripts/gjson/script.go @@ -0,0 +1,22 @@ +package main + +import ( + "net/http" + + "github.com/go-resty/resty/v2" + "github.com/stretchr/testify/require" + "github.com/tidwall/gjson" +) + +func Default(require *require.Assertions) { + res, err := resty.New().R().Get("https://httpbin.test.k6.io/get") + + require.NoError(err, "request success") + require.Equal(http.StatusOK, res.StatusCode(), "status code 200") + + body := res.Body() + + val := gjson.GetBytes(body, "headers.Host").Str + + require.Equal("httpbin.test.k6.io", val, "headers.Host value OK") +} diff --git a/scripts/jsonpath/script.go b/scripts/jsonpath/script.go new file mode 100644 index 0000000..3c532bb --- /dev/null +++ b/scripts/jsonpath/script.go @@ -0,0 +1,22 @@ +package main + +import ( + "net/http" + + "github.com/PaesslerAG/jsonpath" + "github.com/go-resty/resty/v2" + "github.com/stretchr/testify/require" +) + +func Default(require *require.Assertions) { + body := make(map[string]interface{}) + res, err := resty.New().R().SetResult(&body).Get("https://httpbin.test.k6.io/get") + + require.NoError(err, "request success") + require.Equal(http.StatusOK, res.StatusCode(), "status code 200") + + val, err := jsonpath.Get("$.headers.Host", body) + + require.NoError(err, "$.headers.Host no error") + require.Equal("httpbin.test.k6.io", val, "$.headers.Host value OK") +}