diff --git a/go.mod b/go.mod index 73871cd..61b434c 100644 --- a/go.mod +++ b/go.mod @@ -3,42 +3,50 @@ module github.com/grafana/xk6-webcrypto go 1.19 require ( - github.com/dop251/goja v0.0.0-20230531210528-d7324b2d74f7 + github.com/dop251/goja v0.0.0-20231027120936-b396bb4c349d github.com/google/uuid v1.3.0 - github.com/stretchr/testify v1.8.2 - go.k6.io/k6 v0.45.1 + github.com/stretchr/testify v1.8.4 + go.k6.io/k6 v0.48.0 gopkg.in/guregu/null.v3 v3.3.0 ) require ( - github.com/andybalholm/brotli v1.0.5 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.9.0 // indirect github.com/fatih/color v1.15.0 // indirect + github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect - github.com/gorilla/websocket v1.5.0 // indirect + github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/josharian/intern v1.0.0 // indirect - github.com/klauspost/compress v1.16.5 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.18 // indirect - github.com/mccutchen/go-httpbin v1.1.2-0.20190116014521-c5cb2f4802fa // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/gomega v1.20.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect - github.com/sirupsen/logrus v1.9.0 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/afero v1.1.2 // indirect - golang.org/x/crypto v0.9.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + go.opentelemetry.io/otel v1.19.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/sdk v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect + go.opentelemetry.io/proto/otlp v1.0.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect - google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect - google.golang.org/grpc v1.55.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect + google.golang.org/grpc v1.58.3 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5359c94..4e0fd47 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= -github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -12,8 +13,8 @@ github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnm github.com/dlclark/regexp2 v1.9.0 h1:pTK/l/3qYIKaRXuHnEnIf7Y5NxfRPfpb7dis6/gdlVI= github.com/dlclark/regexp2 v1.9.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= -github.com/dop251/goja v0.0.0-20230531210528-d7324b2d74f7 h1:cVGkvrdHgyBkYeB6kMCaF5j2d9Bg4trgbIpcUrKrvk4= -github.com/dop251/goja v0.0.0-20230531210528-d7324b2d74f7/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= +github.com/dop251/goja v0.0.0-20231027120936-b396bb4c349d h1:wi6jN5LVt/ljaBG4ue79Ekzb12QfJ52L9Q98tl8SWhw= +github.com/dop251/goja v0.0.0-20231027120936-b396bb4c349d/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= @@ -21,10 +22,16 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBD github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible h1:bopx7t9jyUNX1ebhr0G4gtQWmUOgwQRI0QsYhdYLgkU= github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= @@ -40,22 +47,23 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U= github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg= +github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 h1:ZgoomqkdjGbQ3+qQXCkvYMCDvGDNg2k5JJDjjdTB6jY= +github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -65,10 +73,9 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= -github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mccutchen/go-httpbin v1.1.2-0.20190116014521-c5cb2f4802fa h1:lx8ZnNPwjkXSzOROz0cg69RlErRXs+L3eDkggASWKLo= -github.com/mccutchen/go-httpbin v1.1.2-0.20190116014521-c5cb2f4802fa/go.mod h1:fhpOYavp5g2K74XDl/ao2y4KvhqVtKlkg1e+0UaQv7I= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk= github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1 h1:94EkGmhXrVUEal+uLwFUf4fMXPhZpM5tYxuIsxrCCbI= @@ -85,33 +92,45 @@ github.com/onsi/gomega v1.20.2 h1:8uQq0zMgLEfa0vRrrBgaJF2gyW9Da9BmfGV+OyUzfkY= github.com/onsi/gomega v1.20.2/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -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/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= 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= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 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.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/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.k6.io/k6 v0.45.1 h1:z+iVxE7Qze2Ka8tKvnjerOsoTuQb8e27Vqd1wcG2IFI= -go.k6.io/k6 v0.45.1/go.mod h1:SBO/sqx6h/a0lJqEioMEpneb6zULogIyDmz+ufFqtIE= +go.k6.io/k6 v0.48.0 h1:Y/XHlTBmtE8RyQtCqDJILQDX95xILyXVpLtle89T5/o= +go.k6.io/k6 v0.48.0/go.mod h1:fFrCFuMWj8q2crX5w9Znvr0h9tqxrojuoRMwNfhsnCE= +go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= +go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 h1:3d+S281UTjM+AbF31XSOYn1qXn3BgIdWl8HNEpx08Jk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0/go.mod h1:0+KuTDyKL4gjKCF75pHOX4wuzYDUZYfAQdSu43o+Z2I= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= +go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= +go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= +go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= +go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= +go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= +go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -121,8 +140,8 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -144,8 +163,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -153,8 +172,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -165,10 +184,13 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s= -google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag= -google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= +google.golang.org/genproto v0.0.0-20230726155614-23370e0ffb3e h1:xIXmWJ303kJCuogpj0bHq+dcjcZHU+XFyc1I0Yl9cRg= +google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1:FmF5cCW94Ij59cfpoLiwTgodWmm60eEV0CjlsVg2fuw= +google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf h1:guOdSPaeFgN+jEJwTo1dQ71hdBm+yKSCCKuTRkJzcVo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf/go.mod h1:zBEcrKX2ZOcEkHWxBPAIvYUWOKKMIhYcmNiUIu2ji3I= +google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= +google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/webcrypto/crypto_test.go b/webcrypto/crypto_test.go index 9752da2..ef9e44f 100644 --- a/webcrypto/crypto_test.go +++ b/webcrypto/crypto_test.go @@ -10,10 +10,9 @@ import ( func TestGetRandomValues(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - _, err := ts.rt.RunString(` + _, gotErr := ts.RunOnEventLoop(` var input = new Uint8Array(10); var output = crypto.getRandomValues(input); @@ -26,12 +25,9 @@ func TestGetRandomValues(t *testing.T) { if (input !== output) { throw new Error("input !== output"); } - `) + `) - return err - }) - - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) } // TODO: Add tests for DataView @@ -53,7 +49,7 @@ func TestGetRandomValues(t *testing.T) { func TestGetRandomValuesSupportedTypedArrays(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) type testCase struct { name string @@ -122,25 +118,20 @@ func TestGetRandomValuesSupportedTypedArrays(t *testing.T) { } for _, tc := range testCases { - gotScriptErr := ts.ev.Start(func() error { - script := fmt.Sprintf(` + _, gotErr := ts.RunOnEventLoop(fmt.Sprintf(` var buf = new %s(10); crypto.getRandomValues(buf); if (buf.length != 10) { throw new Error("buf.length != 10"); } - `, tc.typedArray) - - _, err := ts.rt.RunString(script) - return err - }) + `, tc.typedArray)) - if tc.wantErr != (gotScriptErr != nil) { - t.Fatalf("unexpected error: %v", gotScriptErr) + if tc.wantErr != (gotErr != nil) { + t.Fatalf("unexpected error: %v", gotErr) } - assert.Equal(t, tc.wantErr, gotScriptErr != nil, tc.name) + assert.Equal(t, tc.wantErr, gotErr != nil, tc.name) } } @@ -155,19 +146,15 @@ func TestGetRandomValuesSupportedTypedArrays(t *testing.T) { func TestGetRandomValuesQuotaExceeded(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - _, err := ts.rt.RunString(` + _, gotErr := ts.RunOnEventLoop(` var buf = new Uint8Array(1000000000); crypto.getRandomValues(buf); - `) - - return err - }) + `) - assert.Error(t, gotScriptErr) - assert.Contains(t, gotScriptErr.Error(), "QuotaExceededError") + assert.Error(t, gotErr) + assert.Contains(t, gotErr.Error(), "QuotaExceededError") } // TestRandomUUIDIsTheNamespaceFormat tests that the UUID generated by @@ -179,10 +166,9 @@ func TestGetRandomValuesQuotaExceeded(t *testing.T) { func TestRandomUUIDIsInTheNamespaceFormat(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - _, err := ts.rt.RunString(` + _, gotErr := ts.RunOnEventLoop(` const iterations = 256; const uuids = new Set(); @@ -201,12 +187,9 @@ func TestRandomUUIDIsInTheNamespaceFormat(t *testing.T) { // that it is unique. UUIDRegex.test(randomUUID()); } - `) + `) - return err - }) - - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) } // TestRandomUUIDIVersion tests that the UUID generated by @@ -219,10 +202,9 @@ func TestRandomUUIDIsInTheNamespaceFormat(t *testing.T) { func TestRandomUUIDVersion(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - _, err := ts.rt.RunString(` + _, gotErr := ts.RunOnEventLoop(` const iterations = 256; const uuids = new Set(); @@ -242,12 +224,9 @@ func TestRandomUUIDVersion(t *testing.T) { throw new Error("UUID version is not 4: " + value); } } - `) - - return err - }) + `) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) } // TestRandomUUIDIVariant tests that the UUID generated by @@ -260,10 +239,9 @@ func TestRandomUUIDVersion(t *testing.T) { func TestRandomUUIDVariant(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - _, err := ts.rt.RunString(` + _, gotErr := ts.RunOnEventLoop(` const iterations = 256; const uuids = new Set(); @@ -283,10 +261,7 @@ func TestRandomUUIDVariant(t *testing.T) { throw new Error("UUID variant is not 1: " + value); } } - `) - - return err - }) + `) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) } diff --git a/webcrypto/subtle_crypto_test.go b/webcrypto/subtle_crypto_test.go index c00f5ff..0d2fe5d 100644 --- a/webcrypto/subtle_crypto_test.go +++ b/webcrypto/subtle_crypto_test.go @@ -17,16 +17,16 @@ import ( func TestSubtleDigest(t *testing.T) { t.Parallel() - ts := newTestSetup(t) digestTestScript, err := CompileFile("./tests", "digest.js") assert.NoError(t, err) - gotScriptErr := ts.ev.Start(func() error { - _, err := ts.rt.RunProgram(digestTestScript) - return err + ts := newConfiguredRuntime(t) + gotErr := ts.EventLoop.Start(func() error { + _, programErr := ts.VU.Runtime().RunProgram(digestTestScript) + return programErr }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) } func TestSubtleCryptoGenerateKey(t *testing.T) { @@ -35,39 +35,35 @@ func TestSubtleCryptoGenerateKey(t *testing.T) { t.Run("successes", func(t *testing.T) { t.Parallel() - ts := newTestSetup(t) - err := ts.rt.GlobalObject().Set("CryptoKey", CryptoKey{}) - require.NoError(t, err) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - err := executeTestScripts(ts.rt, "./tests/generateKey", "successes.js") + gotErr := ts.EventLoop.Start(func() error { + err := executeTestScripts(ts.VU.Runtime(), "./tests/generateKey", "successes.js") require.NoError(t, err) - _, err = ts.rt.RunString(`run_test()`) + _, err = ts.VU.Runtime().RunString(`run_test()`) return err }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) }) t.Run("failures", func(t *testing.T) { t.Parallel() - ts := newTestSetup(t) - err := ts.rt.GlobalObject().Set("CryptoKey", CryptoKey{}) - require.NoError(t, err) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - err := executeTestScripts(ts.rt, "./tests/generateKey", "failures.js") + gotErr := ts.EventLoop.Start(func() error { + err := executeTestScripts(ts.VU.Runtime(), "./tests/generateKey", "failures.js") require.NoError(t, err) - _, err = ts.rt.RunString(`run_test()`) + _, err = ts.VU.Runtime().RunString(`run_test()`) return err }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) }) } @@ -77,17 +73,15 @@ func TestSubtleCryptoImportExportKey(t *testing.T) { t.Run("symmetric", func(t *testing.T) { t.Parallel() - ts := newTestSetup(t) - err := ts.rt.GlobalObject().Set("CryptoKey", CryptoKey{}) - require.NoError(t, err) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - err := executeTestScripts(ts.rt, "./tests/import_export", "symmetric.js") + gotErr := ts.EventLoop.Start(func() error { + err := executeTestScripts(ts.VU.Runtime(), "./tests/import_export", "symmetric.js") return err }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) }) } @@ -97,56 +91,56 @@ func TestSubtleCryptoEncryptDecrypt(t *testing.T) { t.Run("AES CBC", func(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - err := executeTestScripts(ts.rt, "./tests/encrypt_decrypt", "aes_cbc_vectors.js", "aes.js") + gotErr := ts.EventLoop.Start(func() error { + err := executeTestScripts(ts.VU.Runtime(), "./tests/encrypt_decrypt", "aes_cbc_vectors.js", "aes.js") require.NoError(t, err) - _, err = ts.rt.RunString(`run_test()`) + _, err = ts.VU.Runtime().RunString(`run_test()`) return err }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) }) t.Run("AES CTR", func(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - err := executeTestScripts(ts.rt, "./tests/encrypt_decrypt", "aes_ctr_vectors.js", "aes.js") + gotErr := ts.EventLoop.Start(func() error { + err := executeTestScripts(ts.VU.Runtime(), "./tests/encrypt_decrypt", "aes_ctr_vectors.js", "aes.js") require.NoError(t, err) - _, err = ts.rt.RunString(`run_test()`) + _, err = ts.VU.Runtime().RunString(`run_test()`) return err }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) }) // Note @oleiade: although the specification targets support // for various iv sizes, go AES GCM cipher only supports 96bits. - // Thus, alghought the official WebPlatform test suite contains + // Thus, although the official WebPlatform test suite contains // vectors for various iv sizes, we only test the 96bits one. t.Run("AES GCM 96bits iv", func(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - err := executeTestScripts(ts.rt, "./tests/encrypt_decrypt", "aes_gcm_96_iv_fixtures.js", "aes_gcm_vectors.js", "aes.js") + gotErr := ts.EventLoop.Start(func() error { + err := executeTestScripts(ts.VU.Runtime(), "./tests/encrypt_decrypt", "aes_gcm_96_iv_fixtures.js", "aes_gcm_vectors.js", "aes.js") require.NoError(t, err) - _, err = ts.rt.RunString(`run_test()`) + _, err = ts.VU.Runtime().RunString(`run_test()`) return err }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) }) } @@ -156,18 +150,18 @@ func TestSubtleCryptoSignVerify(t *testing.T) { t.Run("HMAC", func(t *testing.T) { t.Parallel() - ts := newTestSetup(t) + ts := newConfiguredRuntime(t) - gotScriptErr := ts.ev.Start(func() error { - err := executeTestScripts(ts.rt, "./tests/sign_verify", "hmac_vectors.js", "hmac.js") + gotErr := ts.EventLoop.Start(func() error { + err := executeTestScripts(ts.VU.Runtime(), "./tests/sign_verify", "hmac_vectors.js", "hmac.js") require.NoError(t, err) - _, err = ts.rt.RunString(`run_test()`) + _, err = ts.VU.Runtime().RunString(`run_test()`) return err }) - assert.NoError(t, gotScriptErr) + assert.NoError(t, gotErr) }) } diff --git a/webcrypto/test_setup.go b/webcrypto/test_setup.go index 3f27b6a..abcec9a 100644 --- a/webcrypto/test_setup.go +++ b/webcrypto/test_setup.go @@ -7,36 +7,31 @@ import ( "path/filepath" "testing" + "go.k6.io/k6/js/compiler" + "github.com/dop251/goja" "github.com/stretchr/testify/require" - "go.k6.io/k6/js/common" - "go.k6.io/k6/js/eventloop" "go.k6.io/k6/js/modulestest" - "go.k6.io/k6/lib" - "go.k6.io/k6/lib/testutils/httpmultibin" - "go.k6.io/k6/metrics" - "gopkg.in/guregu/null.v3" ) -// testSetup is a helper struct holding components -// necessary to test the redis client, in the context -// of the execution of a k6 script. -type testSetup struct { - rt *goja.Runtime - state *lib.State - samples chan metrics.SampleContainer - ev *eventloop.EventLoop -} +const initGlobals = ` + globalThis.CryptoKey = require("k6/x/webcrypto").CryptoKey; +` -// newTestSetup initializes a new test setup. +// newConfiguredRuntime initializes a new test setup. // It prepares a test setup with a mocked redis server and a goja runtime, // and event loop, ready to execute scripts as if being executed in the // main context of k6. -func newTestSetup(t testing.TB) testSetup { - tb := httpmultibin.NewHTTPMultiBin(t) - - rt := goja.New() - rt.SetFieldNameMapper(common.FieldNameMapper{}) +func newConfiguredRuntime(t testing.TB) *modulestest.Runtime { + var err error + runtime := modulestest.NewRuntime(t) + + err = runtime.SetupModuleSystem( + map[string]interface{}{"k6/x/webcrypto": New()}, + nil, + compiler.New(runtime.VU.InitEnv().Logger), + ) + require.NoError(t, err) // We compile the Web Platform testharness script into a goja.Program harnessProgram, err := CompileFile("./tests/util", "testharness.js") @@ -45,68 +40,36 @@ func newTestSetup(t testing.TB) testSetup { // We execute the harness script in the goja runtime // in order to make the Web Platform assertion functions available // to the tests. - _, err = rt.RunProgram(harnessProgram) + _, err = runtime.VU.Runtime().RunProgram(harnessProgram) require.NoError(t, err) // We compile the Web Platform helpers script into a goja.Program helpersProgram, err := CompileFile("./tests/util", "helpers.js") require.NoError(t, err) + // We execute the helpers script in the goja runtime // in order to make the Web Platform helpers available // to the tests. - _, err = rt.RunProgram(helpersProgram) + _, err = runtime.VU.Runtime().RunProgram(helpersProgram) require.NoError(t, err) - root, err := lib.NewGroup("", nil) - require.NoError(t, err) + m := new(RootModule).NewModuleInstance(runtime.VU) - samples := make(chan metrics.SampleContainer, 1000) - - state := &lib.State{ - Group: root, - Dialer: tb.Dialer, - Options: lib.Options{ - SystemTags: metrics.NewSystemTagSet( - metrics.TagURL, - metrics.TagProto, - metrics.TagStatus, - metrics.TagSubproto, - ), - UserAgent: null.StringFrom("TestUserAgent"), - }, - Samples: samples, - TLSConfig: tb.TLSClientConfig, - BuiltinMetrics: metrics.RegisterBuiltinMetrics(metrics.NewRegistry()), - Tags: lib.NewVUStateTags(metrics.NewRegistry().RootTagSet()), - } - - vu := &modulestest.VU{ - CtxField: tb.Context, - InitEnvField: &common.InitEnvironment{}, - RuntimeField: rt, - StateField: state, - } - - m := new(RootModule).NewModuleInstance(vu) - require.NoError(t, rt.Set("crypto", m.Exports().Named["crypto"])) + err = runtime.VU.Runtime().Set("crypto", m.Exports().Named["crypto"]) + require.NoError(t, err) - ev := eventloop.New(vu) - vu.RegisterCallbackField = ev.RegisterCallback + _, err = runtime.VU.Runtime().RunString(initGlobals) + require.NoError(t, err) - return testSetup{ - rt: rt, - state: state, - samples: samples, - ev: ev, - } + return runtime } // CompileFile compiles a javascript file as a goja.Program. func CompileFile(base, name string) (*goja.Program, error) { - fname := path.Join(base, name) + filename := path.Join(base, name) //nolint:forbidigo // Allow os.Open in tests - f, err := os.Open(filepath.Clean(fname)) + f, err := os.Open(filepath.Clean(filename)) if err != nil { return nil, err }