-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces --json flag for k6 version sub-command
- Loading branch information
1 parent
ec1f601
commit dfe1539
Showing
3 changed files
with
174 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.k6.io/k6/cmd/tests" | ||
"go.k6.io/k6/lib/consts" | ||
) | ||
|
||
func TestVersionFlag(t *testing.T) { | ||
t.Parallel() | ||
|
||
ts := tests.NewGlobalTestState(t) | ||
ts.ExpectedExitCode = 0 | ||
ts.CmdArgs = []string{"k6", "--version"} | ||
|
||
ExecuteWithGlobalState(ts.GlobalState) | ||
|
||
stdout := ts.Stdout.String() | ||
t.Log(stdout) | ||
assert.NotEmpty(t, stdout) | ||
|
||
// Check that the version/format string is correct | ||
assert.Contains(t, stdout, "k6 v") | ||
assert.Contains(t, stdout, consts.Version) | ||
assert.Contains(t, stdout, runtime.Version()) | ||
assert.Contains(t, stdout, runtime.GOOS) | ||
assert.Contains(t, stdout, runtime.GOARCH) | ||
} | ||
|
||
func TestVersionSubCommand(t *testing.T) { | ||
t.Parallel() | ||
|
||
ts := tests.NewGlobalTestState(t) | ||
ts.ExpectedExitCode = 0 | ||
ts.CmdArgs = []string{"k6", "version"} | ||
|
||
ExecuteWithGlobalState(ts.GlobalState) | ||
|
||
stdout := ts.Stdout.String() | ||
t.Log(stdout) | ||
assert.NotEmpty(t, stdout) | ||
|
||
// Check that the version/format string is correct | ||
assert.Contains(t, stdout, "k6 v") | ||
assert.Contains(t, stdout, consts.Version) | ||
assert.Contains(t, stdout, runtime.Version()) | ||
assert.Contains(t, stdout, runtime.GOOS) | ||
assert.Contains(t, stdout, runtime.GOARCH) | ||
} | ||
|
||
func TestVersionJSONSubCommand(t *testing.T) { | ||
t.Parallel() | ||
|
||
ts := tests.NewGlobalTestState(t) | ||
ts.ExpectedExitCode = 0 | ||
ts.CmdArgs = []string{"k6", "version", "--json"} | ||
|
||
ExecuteWithGlobalState(ts.GlobalState) | ||
|
||
stdout := ts.Stdout.String() | ||
t.Log(stdout) | ||
assert.NotEmpty(t, stdout) | ||
|
||
// try to unmarshal the JSON output | ||
var details map[string]interface{} | ||
err := json.Unmarshal([]byte(stdout), &details) | ||
assert.NoError(t, err) | ||
|
||
// Check that details are correct | ||
assert.Contains(t, details, "version") | ||
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, runtime.Version(), details["go_version"]) | ||
assert.Equal(t, runtime.GOOS, details["go_os"]) | ||
assert.Equal(t, runtime.GOARCH, details["go_arch"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters