Skip to content

Commit

Permalink
Change to using sobek instead of goja
Browse files Browse the repository at this point in the history
We are moving to a fork of goja under grafana org called sobek.

More info in:
- grafana/k6#3772
- grafana/k6#3773
  • Loading branch information
mstoykov committed Jun 10, 2024
1 parent fb02382 commit e4ff714
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 85 deletions.
22 changes: 11 additions & 11 deletions coap/coap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"path/filepath"
"time"

"github.com/dop251/goja"
"github.com/grafana/sobek"
"github.com/mstoykov/k6-taskqueue-lib/taskqueue"
piondtls "github.com/pion/dtls/v2"
"github.com/plgd-dev/go-coap/v3/dtls"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (c *CoAP) Exports() modules.Exports {

// client constructs a new CoAP client by establishing a new DTLS cnnection with
// the provided server endpoint.
func (c *CoAP) client(cc goja.ConstructorCall) *goja.Object {
func (c *CoAP) client(cc sobek.ConstructorCall) *sobek.Object {
rt := c.vu.Runtime()
endpoint := cc.Argument(endpointArgIdx).String()
conf := &piondtls.Config{
Expand All @@ -74,7 +74,7 @@ func (c *CoAP) client(cc goja.ConstructorCall) *goja.Object {
}

// Only ECDSA keys are currently supported.
if !goja.IsUndefined(cc.Argument(certPathArgIdx)) && !goja.IsUndefined(cc.Argument(keyPathArgIdx)) {
if !sobek.IsUndefined(cc.Argument(certPathArgIdx)) && !sobek.IsUndefined(cc.Argument(keyPathArgIdx)) {
pemCert, err := os.ReadFile(filepath.Clean(cc.Argument(certPathArgIdx).String()))
if err != nil {
common.Throw(rt, err)
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *CoAP) client(cc goja.ConstructorCall) *goja.Object {

// If certificates were provided, they take precedence over PSK as
// piondtls will always use PSK if provided.
if len(conf.Certificates) == 0 && !goja.IsUndefined(cc.Argument(pskIDEnvArgIdx)) && !goja.IsUndefined(cc.Argument(pskEnvArgIdx)) {
if len(conf.Certificates) == 0 && !sobek.IsUndefined(cc.Argument(pskIDEnvArgIdx)) && !sobek.IsUndefined(cc.Argument(pskEnvArgIdx)) {
pskID, _ := os.LookupEnv(cc.Argument(pskIDEnvArgIdx).String())
conf.PSKIdentityHint = []byte(pskID)
psk, _ := os.LookupEnv(cc.Argument(pskEnvArgIdx).String())
Expand Down Expand Up @@ -135,27 +135,27 @@ func (c *CoAP) client(cc goja.ConstructorCall) *goja.Object {
obj: rt.NewObject(),
}

if err := client.obj.DefineDataProperty("get", rt.ToValue(client.Get), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE); err != nil {
if err := client.obj.DefineDataProperty("get", rt.ToValue(client.Get), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE); err != nil {
common.Throw(rt, err)
return nil
}
if err := client.obj.DefineDataProperty("observe", rt.ToValue(client.Observe), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE); err != nil {
if err := client.obj.DefineDataProperty("observe", rt.ToValue(client.Observe), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE); err != nil {
common.Throw(rt, err)
return nil
}
if err := client.obj.DefineDataProperty("put", rt.ToValue(client.Put), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE); err != nil {
if err := client.obj.DefineDataProperty("put", rt.ToValue(client.Put), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE); err != nil {
common.Throw(rt, err)
return nil
}
if err := client.obj.DefineDataProperty("post", rt.ToValue(client.Post), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE); err != nil {
if err := client.obj.DefineDataProperty("post", rt.ToValue(client.Post), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE); err != nil {
common.Throw(rt, err)
return nil
}
if err := client.obj.DefineDataProperty("delete", rt.ToValue(client.Delete), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE); err != nil {
if err := client.obj.DefineDataProperty("delete", rt.ToValue(client.Delete), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE); err != nil {
common.Throw(rt, err)
return nil
}
if err := client.obj.DefineDataProperty("close", rt.ToValue(client.Close), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE); err != nil {
if err := client.obj.DefineDataProperty("close", rt.ToValue(client.Close), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE); err != nil {
common.Throw(rt, err)
return nil
}
Expand All @@ -167,7 +167,7 @@ type client struct {
vu modules.VU
tq *taskqueue.TaskQueue
conn *udp.Conn
obj *goja.Object
obj *sobek.Object
}

// Get sends a GET message to the specified path.
Expand Down
44 changes: 31 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,59 @@ module github.com/golioth/xk6-coap
go 1.20

require (
github.com/dop251/goja v0.0.0-20230531210528-d7324b2d74f7
github.com/grafana/sobek v0.0.0-20240607083612-4f0cd64f4e78
github.com/mstoykov/k6-taskqueue-lib v0.1.0
github.com/pion/dtls/v2 v2.2.6
github.com/plgd-dev/go-coap/v3 v3.1.2
go.k6.io/k6 v0.45.1
go.k6.io/k6 v0.51.1-0.20240610082146-1f01a9bc2365
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/dlclark/regexp2 v1.9.0 // indirect
github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 // indirect
github.com/dsnet/golib/memfile v1.0.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/evanw/esbuild v0.21.2 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/josharian/intern v1.0.0 // 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/mattn/go-isatty v0.0.20 // indirect
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/transport/v2 v2.2.0 // indirect
github.com/pion/udp/v2 v2.0.1 // 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
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/guregu/null.v3 v3.3.0 // indirect
)
Loading

0 comments on commit e4ff714

Please sign in to comment.