Skip to content

Commit

Permalink
Migrate to the new versioning API
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Feb 11, 2025
1 parent 084ff89 commit 7e172af
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 44 deletions.
5 changes: 2 additions & 3 deletions cloudapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
"time"

"go.k6.io/k6/lib/fsext"

"go.k6.io/k6/lib/consts"
"go.k6.io/k6/version"

"go.k6.io/k6/lib"

Expand Down Expand Up @@ -111,7 +110,7 @@ func TestCreateTestRun(t *testing.T) {

arc := &lib.Archive{
Type: "js",
K6Version: consts.Version,
K6Version: version.SemVer,
Options: lib.Options{},
FilenameURL: &url.URL{Scheme: "file", Path: "/path/to/a.js"},
Data: []byte(`// a contents`),
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.k6.io/k6/errext/exitcodes"
"go.k6.io/k6/internal/ui/pb"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/version"

"github.com/fatih/color"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -164,7 +164,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
// Start cloud test run
modifyAndPrintBar(c.gs, progressBar, pb.WithConstProgress(0, "Validating script options"))
client := cloudapi.NewClient(
logger, cloudConfig.Token.String, cloudConfig.Host.String, consts.Version, cloudConfig.Timeout.TimeDuration())
logger, cloudConfig.Token.String, cloudConfig.Host.String, version.SemVer, cloudConfig.Timeout.TimeDuration())
if err = client.ValidateOptions(arc.Options); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/cloud_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"go.k6.io/k6/cloudapi"
"go.k6.io/k6/cmd/state"
"go.k6.io/k6/internal/ui"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/version"
)

const cloudLoginCommandName = "login"
Expand Down Expand Up @@ -163,7 +163,7 @@ func validateToken(gs *state.GlobalState, jsonRawConf json.RawMessage, token str
gs.Logger,
token,
consolidatedCurrentConfig.Host.String,
consts.Version,
version.SemVer,
consolidatedCurrentConfig.Timeout.TimeDuration(),
)

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/login_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"go.k6.io/k6/cloudapi"
"go.k6.io/k6/cmd/state"
"go.k6.io/k6/internal/ui"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/version"
)

//nolint:funlen,gocognit
Expand Down Expand Up @@ -110,7 +110,7 @@ Please use the "k6 cloud login" command instead.
gs.Logger,
"",
consolidatedCurrentConfig.Host.String,
consts.Version,
version.SemVer,
consolidatedCurrentConfig.Timeout.TimeDuration())

var res *cloudapi.LoginResponse
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"gopkg.in/guregu/null.v3"

"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/lib/types"
"go.k6.io/k6/metrics"
"go.k6.io/k6/version"
)

var (
Expand All @@ -37,7 +37,7 @@ func optionFlagSet() *pflag.FlagSet {
flags.Int64("batch", 20, "max parallel batch reqs")
flags.Int64("batch-per-host", 6, "max parallel batch reqs per host")
flags.Int64("rps", 0, "limit requests per second")
flags.String("user-agent", fmt.Sprintf("k6/%s (https://k6.io/)", consts.Version), "user agent for http requests")
flags.String("user-agent", fmt.Sprintf("k6/%s (https://k6.io/)", version.SemVer), "user agent for http requests")
flags.String("http-debug", "", "log all HTTP requests and responses. Excludes body by default. To include body use '--http-debug=full'") //nolint:lll
flags.Lookup("http-debug").NoOptDefVal = "headers"
flags.Bool("insecure-skip-tls-verify", false, "skip verification of TLS certificates")
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/outputs_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"go.k6.io/k6/cloudapi"
"go.k6.io/k6/cmd/state"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/metrics"
"go.k6.io/k6/version"
)

const (
Expand Down Expand Up @@ -116,7 +116,7 @@ func createCloudTest(gs *state.GlobalState, test *loadedAndConfiguredTest) error
logger := gs.Logger.WithFields(logrus.Fields{"output": builtinOutputCloud.String()})

apiClient := cloudapi.NewClient(
logger, conf.Token.String, conf.Host.String, consts.Version, conf.Timeout.TimeDuration())
logger, conf.Token.String, conf.Host.String, version.SemVer, conf.Timeout.TimeDuration())

response, err := apiClient.CreateTestRun(testRun)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

"go.k6.io/k6/internal/execution"
"go.k6.io/k6/internal/usage"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/version"
)

func createReport(u *usage.Usage, execScheduler *execution.Scheduler) map[string]any {
execState := execScheduler.GetState()
m := u.Map()

m["k6_version"] = consts.Version
m["k6_version"] = version.SemVer
m["duration"] = execState.GetCurrentTestRunDuration().String()
m["goos"] = runtime.GOOS
m["goarch"] = runtime.GOARCH
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"go.k6.io/k6/internal/lib/testutils"
"go.k6.io/k6/internal/usage"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/lib/executor"
"go.k6.io/k6/version"
"gopkg.in/guregu/null.v3"
)

Expand Down Expand Up @@ -53,7 +53,7 @@ func TestCreateReport(t *testing.T) {
m := createReport(usage.New(), s)
require.NoError(t, err)

assert.Equal(t, consts.Version, m["k6_version"])
assert.Equal(t, version.SemVer, m["k6_version"])
assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"])
assert.EqualValues(t, 6, m["vus_max"])
assert.EqualValues(t, 170, m["iterations"])
Expand All @@ -75,7 +75,7 @@ func TestCreateReport(t *testing.T) {
m := createReport(usage.New(), s)
require.NoError(t, err)

assert.Equal(t, consts.Version, m["k6_version"])
assert.Equal(t, version.SemVer, m["k6_version"])
assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"])
assert.EqualValues(t, 0, m["vus_max"])
assert.EqualValues(t, 0, m["iterations"])
Expand All @@ -97,7 +97,7 @@ func TestCreateReport(t *testing.T) {
m := createReport(usage.New(), s)
require.NoError(t, err)

assert.Equal(t, consts.Version, m["k6_version"])
assert.Equal(t, version.SemVer, m["k6_version"])
assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"])
assert.EqualValues(t, 0, m["vus_max"])
assert.EqualValues(t, 0, m["iterations"])
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"go.k6.io/k6/internal/lib/testutils"
"go.k6.io/k6/internal/lib/testutils/httpmultibin"
"go.k6.io/k6/js/modules"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/lib/fsext"
"go.k6.io/k6/version"
)

func TestVersion(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func TestVersion(t *testing.T) {
cmd.ExecuteWithGlobalState(ts.GlobalState)

stdout := ts.Stdout.String()
assert.Contains(t, stdout, "k6 v"+consts.Version)
assert.Contains(t, stdout, "k6 v"+version.SemVer)
assert.Contains(t, stdout, runtime.Version())
assert.Contains(t, stdout, runtime.GOOS)
assert.Contains(t, stdout, runtime.GOARCH)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
"go.k6.io/k6/cmd/state"
"go.k6.io/k6/ext"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/version"
)

const (
Expand Down Expand Up @@ -45,7 +45,7 @@ func fullVersion() string {

// versionDetails returns the structured details about version
func versionDetails() map[string]interface{} {
v := consts.Version
v := version.SemVer
if !strings.HasPrefix(v, "v") {
v = "v" + v
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"go.k6.io/k6/internal/cmd/tests"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/version"
)

func TestVersionFlag(t *testing.T) {
Expand All @@ -25,7 +25,7 @@ func TestVersionFlag(t *testing.T) {

// Check that the version/format string is correct
assert.Contains(t, stdout, "k6 v")
assert.Contains(t, stdout, consts.Version)
assert.Contains(t, stdout, version.SemVer)
assert.Contains(t, stdout, runtime.Version())
assert.Contains(t, stdout, runtime.GOOS)
assert.Contains(t, stdout, runtime.GOARCH)
Expand All @@ -46,7 +46,7 @@ func TestVersionSubCommand(t *testing.T) {

// Check that the version/format string is correct
assert.Contains(t, stdout, "k6 v")
assert.Contains(t, stdout, consts.Version)
assert.Contains(t, stdout, version.SemVer)
assert.Contains(t, stdout, runtime.Version())
assert.Contains(t, stdout, runtime.GOOS)
assert.Contains(t, stdout, runtime.GOARCH)
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestVersionJSONSubCommand(t *testing.T) {
assert.Contains(t, details, "go_version")
assert.Contains(t, details, "go_os")
assert.Contains(t, details, "go_arch")
assert.Equal(t, "v"+consts.Version, details["version"])
assert.Equal(t, "v"+version.SemVer, details["version"])
assert.Equal(t, runtime.Version(), details["go_version"])
assert.Equal(t, runtime.GOOS, details["go_os"])
assert.Equal(t, runtime.GOARCH, details["go_arch"])
Expand Down
3 changes: 2 additions & 1 deletion internal/js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/lib/fsext"
"go.k6.io/k6/version"
)

// A Bundle is a self-contained bundle of scripts and resources.
Expand Down Expand Up @@ -176,7 +177,7 @@ func (b *Bundle) makeArchive() *lib.Archive {
PwdURL: clonedPwdURL,
Env: make(map[string]string, len(b.preInitState.RuntimeOptions.Env)),
CompatibilityMode: b.CompatibilityMode.String(),
K6Version: consts.Version,
K6Version: version.SemVer,
Goos: runtime.GOOS,
}
// Copy env so changes in the archive are not reflected in the source Bundle
Expand Down
5 changes: 3 additions & 2 deletions internal/js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.k6.io/k6/lib/fsext"
"go.k6.io/k6/lib/types"
"go.k6.io/k6/metrics"
"go.k6.io/k6/version"
)

const isWindows = runtime.GOOS == "windows"
Expand Down Expand Up @@ -584,7 +585,7 @@ func TestNewBundleFromArchive(t *testing.T) {
arc := &lib.Archive{
Type: "js",
FilenameURL: &url.URL{Scheme: "file", Path: "/script"},
K6Version: consts.Version,
K6Version: version.SemVer,
Data: []byte(code),
Options: lib.Options{VUs: null.IntFrom(999)},
PwdURL: &url.URL{Scheme: "file", Path: "/"},
Expand Down Expand Up @@ -948,7 +949,7 @@ func TestBundleMakeArchive(t *testing.T) {
fileData, err := fsext.ReadFile(arc.Filesystems["file"], "/path/to/file.txt")
require.NoError(t, err)
assert.Equal(t, `hi`, string(fileData))
assert.Equal(t, consts.Version, arc.K6Version)
assert.Equal(t, version.SemVer, arc.K6Version)
assert.Equal(t, tc.cm.String(), arc.CompatibilityMode)
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/output/cloud/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"go.k6.io/k6/errext"
"go.k6.io/k6/internal/usage"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/metrics"
"go.k6.io/k6/output"
cloudv2 "go.k6.io/k6/output/cloud/expv2"
"go.k6.io/k6/version"
)

const (
Expand Down Expand Up @@ -141,7 +141,7 @@ func newOutput(params output.Params) (*Output, error) {
}

apiClient := cloudapi.NewClient(
logger, conf.Token.String, conf.Host.String, consts.Version, conf.Timeout.TimeDuration())
logger, conf.Token.String, conf.Host.String, version.SemVer, conf.Timeout.TimeDuration())

return &Output{
config: conf,
Expand Down
16 changes: 8 additions & 8 deletions lib/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"testing"

"go.k6.io/k6/internal/lib/testutils"
"go.k6.io/k6/version"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v3"

"go.k6.io/k6/lib/consts"
"go.k6.io/k6/lib/fsext"
"go.k6.io/k6/metrics"
)
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestArchiveReadWrite(t *testing.T) {
t.Parallel()
arc1 := &Archive{
Type: "js",
K6Version: consts.Version,
K6Version: version.SemVer,
Options: Options{
VUs: null.IntFrom(12345),
SystemTags: &metrics.DefaultSystemTagSet,
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestArchiveReadWrite(t *testing.T) {
SystemTags: &metrics.DefaultSystemTagSet,
},
FilenameURL: &url.URL{Scheme: "file", Path: fmt.Sprintf("%s/a.js", entry.Pwd)},
K6Version: consts.Version,
K6Version: version.SemVer,
Data: []byte(`// a contents`),
PwdURL: &url.URL{Scheme: "file", Path: entry.Pwd},
Filesystems: map[string]fsext.Fs{
Expand All @@ -194,7 +194,7 @@ func TestArchiveReadWrite(t *testing.T) {
SystemTags: &metrics.DefaultSystemTagSet,
},
FilenameURL: &url.URL{Scheme: "file", Path: fmt.Sprintf("%s/a.js", entry.PwdNormAnon)},
K6Version: consts.Version,
K6Version: version.SemVer,
Data: []byte(`// a contents`),
PwdURL: &url.URL{Scheme: "file", Path: entry.PwdNormAnon},

Expand Down Expand Up @@ -253,7 +253,7 @@ func TestUsingCacheFromCacheOnReadFs(t *testing.T) {
arc := &Archive{
Type: "js",
FilenameURL: &url.URL{Scheme: "file", Path: "/correct"},
K6Version: consts.Version,
K6Version: version.SemVer,
Data: []byte(`test`),
PwdURL: &url.URL{Scheme: "file", Path: "/"},
Filesystems: map[string]fsext.Fs{
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestArchiveWithDataNotInFS(t *testing.T) {
arc := &Archive{
Type: "js",
FilenameURL: &url.URL{Scheme: "file", Path: "/script"},
K6Version: consts.Version,
K6Version: version.SemVer,
Data: []byte(`test`),
PwdURL: &url.URL{Scheme: "file", Path: "/"},
Filesystems: nil,
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestStrangePaths(t *testing.T) {
}
arc1 := &Archive{
Type: "js",
K6Version: consts.Version,
K6Version: version.SemVer,
Options: Options{
VUs: null.IntFrom(12345),
SystemTags: &metrics.DefaultSystemTagSet,
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestStdinArchive(t *testing.T) {
arc := &Archive{
Type: "js",
FilenameURL: &url.URL{Scheme: "file", Path: "/-"},
K6Version: consts.Version,
K6Version: version.SemVer,
Data: []byte(`test`),
PwdURL: &url.URL{Scheme: "file", Path: "/"},
Filesystems: map[string]fsext.Fs{
Expand Down
Loading

0 comments on commit 7e172af

Please sign in to comment.