2023-05-22 18:55:42 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2023-06-01 10:03:22 +00:00
|
|
|
"encoding/json"
|
2023-05-22 18:55:42 +00:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/internal/build"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var expectedVersion = fmt.Sprintf("Databricks CLI v%s\n", build.GetInfo().Version)
|
|
|
|
|
|
|
|
func TestVersionFlagShort(t *testing.T) {
|
|
|
|
stdout, stderr := RequireSuccessfulRun(t, "-v")
|
|
|
|
assert.Equal(t, expectedVersion, stdout.String())
|
|
|
|
assert.Equal(t, "", stderr.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVersionFlagLong(t *testing.T) {
|
|
|
|
stdout, stderr := RequireSuccessfulRun(t, "--version")
|
|
|
|
assert.Equal(t, expectedVersion, stdout.String())
|
|
|
|
assert.Equal(t, "", stderr.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVersionCommand(t *testing.T) {
|
|
|
|
stdout, stderr := RequireSuccessfulRun(t, "version")
|
|
|
|
assert.Equal(t, expectedVersion, stdout.String())
|
|
|
|
assert.Equal(t, "", stderr.String())
|
|
|
|
}
|
2023-06-01 10:03:22 +00:00
|
|
|
|
|
|
|
func TestVersionCommandWithJSONOutput(t *testing.T) {
|
|
|
|
stdout, stderr := RequireSuccessfulRun(t, "version", "--output", "json")
|
|
|
|
assert.NotEmpty(t, stdout.String())
|
|
|
|
assert.Equal(t, "", stderr.String())
|
|
|
|
|
|
|
|
// Deserialize stdout and confirm we see the right fields.
|
|
|
|
var output map[string]any
|
|
|
|
err := json.Unmarshal(stdout.Bytes(), &output)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, build.GetInfo().Version, output["Version"])
|
|
|
|
}
|