From d9f1126902a12740286b8e88700dfab42db05b0d Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Mon, 27 Jan 2025 20:30:21 +0100 Subject: [PATCH] WIP: use k6provider Signed-off-by: Pablo Chacin --- cmd/cmd.go | 8 ----- cmd/cmd_test.go | 6 ---- cmd/help.md | 6 ---- cmd/k6exec/main_internal_test.go | 4 +-- cmd/state.go | 41 ++++++---------------- cmd/state_internal_test.go | 29 ++++++---------- command.go | 16 ++------- command_test.go | 59 ++++++++++++++------------------ go.mod | 19 +++++++--- go.sum | 36 +++++++++++++++---- options.go | 11 +----- provision.go | 25 +++++++++----- 12 files changed, 115 insertions(+), 145 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 82fee98..446f811 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -51,12 +51,6 @@ func New(levelVar *slog.LevelVar) *cobra.Command { flags := root.PersistentFlags() - flags.StringVar( - &state.extensionCatalogURL, - "extension-catalog-url", - state.extensionCatalogURL, - "URL of the k6 extension catalog to be used", - ) flags.StringVar( &state.buildServiceURL, "build-service-url", @@ -72,8 +66,6 @@ func New(levelVar *slog.LevelVar) *cobra.Command { root.Flags().Lookup("help").Usage = "help for k6" root.Flags().BoolVar(&state.version, "version", false, "version for k6") - root.MarkFlagsMutuallyExclusive("extension-catalog-url", "build-service-url") - return root } diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index 2185cca..ffdec77 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -4,7 +4,6 @@ import ( "io" "log/slog" "os" - "strings" "testing" "github.com/grafana/k6exec/cmd" @@ -25,15 +24,10 @@ func TestNew(t *testing.T) { //nolint:paralleltest flags := c.PersistentFlags() - require.NotNil(t, flags.Lookup("extension-catalog-url")) require.NotNil(t, flags.Lookup("build-service-url")) require.NotNil(t, flags.Lookup("verbose")) require.NotNil(t, flags.Lookup("quiet")) require.NotNil(t, flags.Lookup("no-color")) - - out := captureStdout(t, func() { require.NoError(t, c.Execute()) }) - - require.True(t, strings.Contains(out, " k6")) } //nolint:forbidigo diff --git a/cmd/help.md b/cmd/help.md index 0b08306..b4b15f9 100644 --- a/cmd/help.md +++ b/cmd/help.md @@ -22,12 +22,6 @@ The build service URL can be specified in the `K6_BUILD_SERVICE_URL` environment There is no default URL for the build service, otherwise k6exec will automatically provide k6 with the native builder. -#### Native Builder - -To use the native builder, you only need to install the [Go language toolkit](https://go.dev/doc/install). - -The native builder uses a k6 extension catalog to resolve extension URLs and versions. The extension catalog URL has a default value. A different extension catalog URL can be specified in the `K6_EXTENSION_CATALOG_URL` environment variable or by using the `--extension-catalog-url` flag. - ### Dependencies Dependencies can come from three sources: k6 test script, manifest file, `K6_DEPENDENCIES` environment variable. Instead of these three sources, a k6 archive can also be specified, which can contain all three sources. diff --git a/cmd/k6exec/main_internal_test.go b/cmd/k6exec/main_internal_test.go index 02095ad..cde2992 100644 --- a/cmd/k6exec/main_internal_test.go +++ b/cmd/k6exec/main_internal_test.go @@ -17,9 +17,9 @@ func Test_newCmd(t *testing.T) { //nolint:paralleltest lvar := new(slog.LevelVar) + // TODO: add more assertions and more test cases cmd := newCmd([]string{"run", abs}, lvar) - - require.NoError(t, cmd.Execute()) + require.Equal(t, "k6exec", cmd.Name()) } func Test_initLogging(t *testing.T) { //nolint:paralleltest diff --git a/cmd/state.go b/cmd/state.go index 8a5c565..61d784f 100644 --- a/cmd/state.go +++ b/cmd/state.go @@ -3,7 +3,6 @@ package cmd import ( "context" "log/slog" - "net/url" "os" "os/exec" @@ -13,17 +12,14 @@ import ( type state struct { k6exec.Options - buildServiceURL string - extensionCatalogURL string - verbose bool - quiet bool - nocolor bool - version bool - usage bool - levelVar *slog.LevelVar - + buildServiceURL string // TODO: this field seems redundant with + verbose bool + quiet bool + nocolor bool + version bool + usage bool + levelVar *slog.LevelVar cmd *exec.Cmd - cleanup func() error } @@ -33,34 +29,18 @@ func newState(levelVar *slog.LevelVar) *state { s.levelVar = levelVar + // FIXME: Remove this as the k6provider library does it if value, found := os.LookupEnv("K6_BUILD_SERVICE_URL"); found { s.buildServiceURL = value } - if value, found := os.LookupEnv("K6_EXTENSION_CATALOG_URL"); found { - s.extensionCatalogURL = value - } - return s } func (s *state) persistentPreRunE(_ *cobra.Command, _ []string) error { + // TODO: is this check necessary? if len(s.buildServiceURL) > 0 { - val, err := url.Parse(s.buildServiceURL) - if err != nil { - return err - } - - s.Options.BuildServiceURL = val - } - - if len(s.extensionCatalogURL) > 0 { - val, err := url.Parse(s.extensionCatalogURL) - if err != nil { - return err - } - - s.Options.ExtensionCatalogURL = val + s.Options.BuildServiceURL = s.buildServiceURL } if s.verbose && s.levelVar != nil { @@ -122,6 +102,7 @@ func (s *state) preRunE(sub *cobra.Command, args []string) error { func (s *state) runE(_ *cobra.Command, _ []string) error { var err error + // FIXME: I think this code is not setting the error to the cleanup function (pablochacin) defer func() { e := s.cleanup() if err == nil { diff --git a/cmd/state_internal_test.go b/cmd/state_internal_test.go index f1763c6..a402f04 100644 --- a/cmd/state_internal_test.go +++ b/cmd/state_internal_test.go @@ -7,6 +7,7 @@ import ( "path/filepath" "testing" + "github.com/grafana/k6build/pkg/testutils" "github.com/grafana/k6exec" "github.com/stretchr/testify/require" ) @@ -15,21 +16,17 @@ func Test_newState(t *testing.T) { lvar := new(slog.LevelVar) t.Setenv("K6_BUILD_SERVICE_URL", "") - t.Setenv("K6_EXTENSION_CATALOG_URL", "") st := newState(lvar) require.Same(t, lvar, st.levelVar) require.Empty(t, st.buildServiceURL) - require.Empty(t, st.extensionCatalogURL) t.Setenv("K6_BUILD_SERVICE_URL", "foo") - t.Setenv("K6_EXTENSION_CATALOG_URL", "bar") st = newState(lvar) require.Equal(t, "foo", st.buildServiceURL) - require.Equal(t, "bar", st.extensionCatalogURL) } func Test_persistentPreRunE(t *testing.T) { @@ -38,26 +35,15 @@ func Test_persistentPreRunE(t *testing.T) { st := &state{levelVar: new(slog.LevelVar)} require.NoError(t, st.persistentPreRunE(nil, nil)) - require.Nil(t, st.BuildServiceURL) - require.Nil(t, st.ExtensionCatalogURL) + require.Empty(t, st.BuildServiceURL) require.Equal(t, slog.LevelInfo, st.levelVar.Level()) st.buildServiceURL = "http://example.com" - st.extensionCatalogURL = "http://example.net" require.NoError(t, st.persistentPreRunE(nil, nil)) - require.Equal(t, "http://example.com", st.BuildServiceURL.String()) - require.Equal(t, "http://example.net", st.ExtensionCatalogURL.String()) - - st.buildServiceURL = "http://example.com/%" - require.Error(t, st.persistentPreRunE(nil, nil)) - - st.buildServiceURL = "http://example.com" - st.extensionCatalogURL = "http://example.net/%" - require.Error(t, st.persistentPreRunE(nil, nil)) + require.Equal(t, "http://example.com", st.BuildServiceURL) st.buildServiceURL = "http://example.com" - st.extensionCatalogURL = "http://example.net" st.verbose = true require.NoError(t, st.persistentPreRunE(nil, nil)) @@ -70,9 +56,16 @@ func Test_persistentPreRunE(t *testing.T) { func Test_preRunE(t *testing.T) { t.Parallel() + env, err := testutils.NewTestEnv(testutils.TestEnvConfig{ + WorkDir: t.TempDir(), + }) + require.NoError(t, err) + + t.Cleanup(env.Cleanup) + st := &state{ levelVar: new(slog.LevelVar), - Options: k6exec.Options{CacheDir: t.TempDir()}, + Options: k6exec.Options{CacheDir: t.TempDir(), BuildServiceURL: env.BuildServiceURL()}, } sub := newSubcommand("version", st) diff --git a/command.go b/command.go index e2bc513..65bfb7f 100644 --- a/command.go +++ b/command.go @@ -2,39 +2,29 @@ package k6exec import ( "context" - "os" "os/exec" - "path/filepath" - - "github.com/grafana/k6provision" ) // Command returns the exec.Cmd struct to execute k6 with the given arguments. // If the given subcommand has a script argument, it analyzes the dependencies // in the script and provisions a k6 executable based on them. // In Options, you can also specify environment variable and manifest file as dependency sources. -// If no errors occur, the provisioned k6 executable will be placed in a temporary directory. // The second return value is a cleanup function that is used to delete this temporary directory. +// TODO: as the cache is now handled by the k6provider library, consider removing the cleanup function func Command(ctx context.Context, args []string, opts *Options) (*exec.Cmd, func() error, error) { deps, err := analyze(args, opts) if err != nil { return nil, nil, err } - dir, err := os.MkdirTemp("", "k6exec-*") //nolint:forbidigo + exe, err := provision(ctx, deps, opts) if err != nil { return nil, nil, err } - exe := filepath.Join(dir, k6provision.ExeName) - - if err := provision(ctx, deps, exe, opts); err != nil { - return nil, nil, err - } - cmd := exec.CommandContext(ctx, exe, args...) //nolint:gosec - return cmd, func() error { return os.RemoveAll(dir) }, nil //nolint:forbidigo + return cmd, func() error { return nil }, nil } /* diff --git a/command_test.go b/command_test.go index dc60d79..5f97d5c 100644 --- a/command_test.go +++ b/command_test.go @@ -2,32 +2,35 @@ package k6exec_test import ( "context" - "net/http" - "net/http/httptest" - "net/url" "strings" "testing" + "github.com/grafana/k6build/pkg/testutils" "github.com/grafana/k6deps" "github.com/grafana/k6exec" - "github.com/grafana/k6provision" + "github.com/grafana/k6provider" + "github.com/stretchr/testify/require" ) func TestCommand(t *testing.T) { t.Parallel() - srv := testWebServer(t) - defer srv.Close() - - u, err := url.Parse(srv.URL + "/minimal-catalog.json") + env, err := testutils.NewTestEnv(testutils.TestEnvConfig{ + WorkDir: t.TempDir(), + CatalogURL: "testdata/minimal-catalog.json", + }) require.NoError(t, err) - ctx := context.Background() + t.Cleanup(env.Cleanup) - opts := &k6exec.Options{ExtensionCatalogURL: u, Env: k6deps.Source{Ignore: true}, Manifest: k6deps.Source{Ignore: true}} + opts := &k6exec.Options{ + Env: k6deps.Source{Ignore: true}, + Manifest: k6deps.Source{Ignore: true}, + BuildServiceURL: env.BuildServiceURL(), + } - cmd, cleanup, err := k6exec.Command(ctx, []string{"version"}, opts) + cmd, cleanup, err := k6exec.Command(context.TODO(), []string{"version"}, opts) defer func() { require.NoError(t, cleanup()) }() require.NoError(t, err) @@ -42,31 +45,21 @@ func TestCommand(t *testing.T) { func TestCommand_errors(t *testing.T) { t.Parallel() - srv := testWebServer(t) - defer srv.Close() - - u, err := url.Parse(srv.URL + "/missing-catalog.json") + env, err := testutils.NewTestEnv(testutils.TestEnvConfig{ + WorkDir: t.TempDir(), + CatalogURL: "testdata/empty-catalog.json", + }) require.NoError(t, err) - ctx := context.Background() + t.Cleanup(env.Cleanup) - _, _, err = k6exec.Command(ctx, nil, &k6exec.Options{AppName: invalidAppName(t)}) - require.Error(t, err) - require.ErrorIs(t, err, k6provision.ErrCache) + opts := &k6exec.Options{ + Env: k6deps.Source{Ignore: true}, + Manifest: k6deps.Source{Ignore: true}, + BuildServiceURL: env.BuildServiceURL(), + } - _, _, err = k6exec.Command(ctx, nil, &k6exec.Options{ExtensionCatalogURL: u}) + _, _, err = k6exec.Command(context.TODO(), nil, opts) require.Error(t, err) - require.ErrorIs(t, err, k6provision.ErrBuild) -} - -func testWebServer(t *testing.T) *httptest.Server { - t.Helper() - - return httptest.NewServer(http.FileServer(http.Dir("testdata"))) -} - -func invalidAppName(t *testing.T) string { - t.Helper() - - return strings.Repeat("too long", 2048) + require.ErrorIs(t, err, k6provider.ErrInvalidParameters) } diff --git a/go.mod b/go.mod index 798a39a..21b4362 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/grafana/k6exec -go 1.22.2 +go 1.22.4 require ( github.com/grafana/clireadme v0.1.0 + github.com/grafana/k6build v0.5.4 github.com/grafana/k6deps v0.2.0 - github.com/grafana/k6provision v0.1.0 github.com/samber/slog-logrus/v2 v2.5.2 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.1 @@ -13,15 +13,26 @@ require ( golang.org/x/term v0.28.0 ) +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/prometheus/client_golang v1.20.5 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.55.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + google.golang.org/protobuf v1.34.2 // indirect +) + require ( github.com/Masterminds/semver/v3 v3.3.1 // indirect github.com/adrg/xdg v0.5.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/evanw/esbuild v0.24.2 // indirect github.com/google/btree v1.1.2 // indirect - github.com/grafana/k6build v0.5.2 // indirect - github.com/grafana/k6foundry v0.3.0 // indirect + github.com/grafana/k6foundry v0.3.1 // indirect github.com/grafana/k6pack v0.2.4 // indirect + github.com/grafana/k6provider v0.1.6 github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect diff --git a/go.sum b/go.sum index 5fb517b..aaa8348 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,10 @@ github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7r github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -14,28 +18,48 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/grafana/clireadme v0.1.0 h1:KYEYSnYdSzmHf3bufaK6fQZ5j4dzvM/T+G6Ba+qNnAM= github.com/grafana/clireadme v0.1.0/go.mod h1:Wy4KIG2ZBGMYAYyF9l7qAy+yoJVasqk/txsRgoRI3gc= -github.com/grafana/k6build v0.5.2 h1:BhR7n2+h9TVgAGlYswW8IKutX0aFu4OhaWzCOpqQ2M8= -github.com/grafana/k6build v0.5.2/go.mod h1:gqaAmSzsHRYOhGM9sXD06H82S0aCPOZcd0rlkKRO8bQ= +github.com/grafana/k6build v0.5.3 h1:UoyoffOFJXOyRW3spJX2pLN3QbbTk0Gvg/IMmqpT2Hg= +github.com/grafana/k6build v0.5.3/go.mod h1:9pjUdyz7XPAMa11IC29+i+L1Ms9LtAVSgmSk+Mj3tfk= +github.com/grafana/k6build v0.5.4 h1:RSaui4O1SySw6TADOwLod/SaRBiTq9bht6sKGePBIuA= +github.com/grafana/k6build v0.5.4/go.mod h1:LpBRh+nbwhCBt5v/LCa14taDuRbXKze56kZCKPNlWho= github.com/grafana/k6deps v0.2.0 h1:yF+Vh70aHoL+2VygK9IGXZ8ojnNd5QPAeQxlU0xXGWM= github.com/grafana/k6deps v0.2.0/go.mod h1:XD+wP7lkIYbre3CZ//vb/WW8I29r2a5ZveeICKR3FLc= github.com/grafana/k6foundry v0.3.0 h1:C+6dPbsOv7Uq4hEhBFNuYqmTdE9jQ0VqhXqBDtMkVTE= github.com/grafana/k6foundry v0.3.0/go.mod h1:/NtBSQQgXup5SVbfInl0Q8zKVx08xgvXIZ0xncqexEs= +github.com/grafana/k6foundry v0.3.1 h1:nv4BqlJfNXrVMk7ps7mlGiPgegR73ogTvisn1y0bYJ8= +github.com/grafana/k6foundry v0.3.1/go.mod h1:4Hw0ll6ZsKN8f3cgp7I4N6EkhXafZ6CBC6fDJWkW7/Q= github.com/grafana/k6pack v0.2.4 h1:JzbaO/NnLBaM2Shbn59WynaGAYL+jMvnjsoj/VTr3es= github.com/grafana/k6pack v0.2.4/go.mod h1:JTG8lQRU4U4WNKkznSL6zYokviiFVIp1I9W7z7NmrLA= +github.com/grafana/k6provider v0.1.6 h1:Hqa9R0TvR0Aci5/l94zufRSAUuXntmhRSg1x9W1iz5A= +github.com/grafana/k6provider v0.1.6/go.mod h1:6rZv0trsslg4cduSBaNWavxPRP7jUgIXez/fMA/uOMI= github.com/grafana/k6provision v0.1.0 h1:fnT7VrelUss46I6gZ6Iylbyxytwxd5stlZJ6shBWqhE= github.com/grafana/k6provision v0.1.0/go.mod h1:n8PG4ctVd9K8nq8zveReDO7+5fEH3LtjX2sjRZYGDn8= github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA= github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= 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/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -64,8 +88,8 @@ golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/options.go b/options.go index 42ca0af..efede9c 100644 --- a/options.go +++ b/options.go @@ -1,9 +1,6 @@ package k6exec import ( - "net/http" - "net/url" - "github.com/grafana/k6deps" ) @@ -34,13 +31,7 @@ type Options struct { // Its default is determined based on the XDG Base Directory Specification. // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html CacheDir string - // Client is used during HTTP communication with the build service. - // If absent, http.DefaultClient will be used. - Client *http.Client - // ExtensionCatalogURL contains the URL of the k6 extension catalog to be used. - // If absent, DefaultExtensionCatalogURL will be used. - ExtensionCatalogURL *url.URL // BuildServiceURL contains the URL of the k6 build service to be used. // If the value is not nil, the k6 binary is built using the build service instead of the local build. - BuildServiceURL *url.URL + BuildServiceURL string } diff --git a/provision.go b/provision.go index b697276..c87f1db 100644 --- a/provision.go +++ b/provision.go @@ -4,19 +4,26 @@ import ( "context" "github.com/grafana/k6deps" - "github.com/grafana/k6provision" + "github.com/grafana/k6provider" ) -func provision(ctx context.Context, deps k6deps.Dependencies, exe string, opts *Options) error { - popts := new(k6provision.Options) +func provision(ctx context.Context, deps k6deps.Dependencies, opts *Options) (string, error) { + config := k6provider.Config{} if opts != nil { - popts.AppName = opts.AppName - popts.CacheDir = opts.CacheDir - popts.Client = opts.Client - popts.BuildServiceURL = opts.BuildServiceURL - popts.ExtensionCatalogURL = opts.ExtensionCatalogURL + config.BinDir = opts.CacheDir + config.BuildServiceURL = opts.BuildServiceURL } - return k6provision.Provision(ctx, deps, exe, popts) + provider, err := k6provider.NewProvider(config) + if err != nil { + return "", err + } + + binary, err := provider.GetBinary(ctx, deps) + if err != nil { + return "",err + } + + return binary.Path, nil }