Skip to content

Commit

Permalink
feature(cli): adding server and cli version match (#2598)
Browse files Browse the repository at this point in the history
* feature(cli): adding server and cli version match

* feature(cli): adding server and cli version match

* feature(cli): adding stdout resulkt

* feature(cli): adding server and cli version match

* feature(cli): adding server env for version test

* fixing tests

* feature(cli): updating version mismatch error message
  • Loading branch information
xoscar authored May 29, 2023
1 parent ef82333 commit 96aa3c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
13 changes: 5 additions & 8 deletions cli/actions/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,34 @@ func NewGetServerVersionAction(options ...ActionArgsOption) versionAction {
}

func (a versionAction) Run(ctx context.Context, args VersionConfig) error {
versionText := a.GetVersionText(ctx)
versionText, _ := a.GetVersion(ctx)

fmt.Println(versionText)
return nil
}

func (a versionAction) GetVersionText(ctx context.Context) string {
func (a versionAction) GetVersion(ctx context.Context) (string, bool) {
result := fmt.Sprintf(`CLI: %s`, config.Version)

if a.config.IsEmpty() {
return result + `
Server: Not Configured`
Server: Not Configured`, false
}

version, err := a.GetServerVersion(ctx)
if err != nil {
return result + fmt.Sprintf(`
Server: Failed to get the server version - %s`, err.Error())
Server: Failed to get the server version - %s`, err.Error()), false
}

isVersionMatch := version == config.Version
if isVersionMatch {
version += `
✔️ Version match`
} else {
version += `
✖️ Version mismatch`
}

return result + fmt.Sprintf(`
Server: %s`, version)
Server: %s`, version), isVersionMatch
}

func (a versionAction) GetServerVersion(ctx context.Context) (string, error) {
Expand Down
17 changes: 13 additions & 4 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
var (
cliConfig config.Config
cliLogger *zap.Logger
resourceRegistry = actions.NewResourceRegistry()
versionText string
isVersionMatch bool
resourceRegistry = actions.NewResourceRegistry()
resourceParams = &parameters.ResourceParams{}
)

Expand Down Expand Up @@ -200,7 +201,15 @@ func setupVersion() {
}

action := actions.NewGetServerVersionAction(options...)
version := action.GetVersionText(ctx)

versionText = version
versionText, isVersionMatch = action.GetVersion(ctx)

if !isVersionMatch && os.Getenv("TRACETEST_DEV") == "" {
fmt.Fprintf(os.Stderr, versionText+`
✖️ Error: Version Mismatch
The CLI version and the server version are not compatible. To fix this, you'll need to make sure that both your CLI and server are using compatible versions.
We recommend upgrading both of them to the latest available version. Check out our documentation https://docs.tracetest.io/configuration/upgrade for simple instructions on how to upgrade.
Thank you for using Tracetest! We apologize for any inconvenience caused.
`)
ExitCLI(1)
}
}
11 changes: 9 additions & 2 deletions testing/cli-e2etest/testscenarios/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testscenarios
import (
"testing"

"github.com/kubeshop/tracetest/cli-e2etest/environment"
"github.com/kubeshop/tracetest/cli-e2etest/tracetestcli"
"github.com/stretchr/testify/require"
)
Expand All @@ -11,11 +12,17 @@ func TestVersionCommand(t *testing.T) {
// instantiate require with testing helper
require := require.New(t)

// setup test server environment
env := environment.CreateAndStart(t)
defer env.Close(t)

cliConfig := env.GetCLIConfigPath(t)

// Given I am a Tracetest CLI user
// When I try to check the tracetest version
// Then I should receive a version string with sucess
// Then I should receive a version string with success
result := tracetestcli.Exec(t, "version", tracetestcli.WithCLIConfig(cliConfig))

result := tracetestcli.Exec(t, "version")
require.Equal(0, result.ExitCode)
require.Greater(len(result.StdOut), 0)
}

0 comments on commit 96aa3c8

Please sign in to comment.