2020-12-09 15:31:34 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-11-25 14:08:33 +00:00
|
|
|
"fmt"
|
2020-12-09 15:31:34 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-12-06 13:29:39 +00:00
|
|
|
"github.com/snyk/driftctl/pkg/version"
|
|
|
|
"github.com/snyk/driftctl/test"
|
2020-12-09 15:31:34 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersionCmd(t *testing.T) {
|
|
|
|
rootCmd := &cobra.Command{Use: "root"}
|
|
|
|
rootCmd.AddCommand(NewVersionCmd())
|
|
|
|
|
|
|
|
output, err := test.Execute(rootCmd, "version")
|
|
|
|
if output == "" {
|
|
|
|
t.Errorf("Unexpected output: %v", output)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 14:08:33 +00:00
|
|
|
expected := fmt.Sprintf("%s\n", version.Current())
|
2020-12-09 15:31:34 +00:00
|
|
|
if output != expected {
|
|
|
|
t.Errorf("Expected %v, got %v", expected, output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVersionCmd_Invalid(t *testing.T) {
|
|
|
|
rootCmd := &cobra.Command{Use: "root"}
|
|
|
|
rootCmd.AddCommand(NewVersionCmd())
|
|
|
|
|
|
|
|
_, err := test.Execute(rootCmd, "version", "test")
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Invalid arg should generate error")
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := `unknown command "test" for "root version"`
|
|
|
|
if err.Error() != expected {
|
|
|
|
t.Errorf("Expected %v, got %v", expected, err)
|
|
|
|
}
|
|
|
|
}
|