2020-01-13 09:11:56 +00:00
|
|
|
package cmd
|
2017-09-22 19:58:12 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2019-12-09 02:44:53 +00:00
|
|
|
"github.com/mikefarah/yq/v3/test"
|
2019-12-01 20:10:42 +00:00
|
|
|
"github.com/spf13/cobra"
|
2017-09-22 19:58:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getRootCommand() *cobra.Command {
|
2020-01-13 09:11:56 +00:00
|
|
|
return New()
|
2017-09-22 19:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRootCmd(t *testing.T) {
|
|
|
|
cmd := getRootCommand()
|
2019-11-23 03:52:29 +00:00
|
|
|
result := test.RunCmd(cmd, "")
|
2017-09-22 19:58:12 +00:00
|
|
|
if result.Error != nil {
|
|
|
|
t.Error(result.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(result.Output, "Usage:") {
|
|
|
|
t.Error("Expected usage message to be printed out, but the usage message was not found.")
|
|
|
|
}
|
2019-05-14 17:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRootCmd_Help(t *testing.T) {
|
|
|
|
cmd := getRootCommand()
|
2019-11-23 03:52:29 +00:00
|
|
|
result := test.RunCmd(cmd, "--help")
|
2019-05-14 17:28:06 +00:00
|
|
|
if result.Error != nil {
|
|
|
|
t.Error(result.Error)
|
|
|
|
}
|
2017-09-22 19:58:12 +00:00
|
|
|
|
2019-05-14 17:28:06 +00:00
|
|
|
if !strings.Contains(result.Output, "yq is a lightweight and portable command-line YAML processor. It aims to be the jq or sed of yaml files.") {
|
|
|
|
t.Error("Expected usage message to be printed out, but the usage message was not found.")
|
|
|
|
}
|
2017-09-22 19:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRootCmd_VerboseLong(t *testing.T) {
|
|
|
|
cmd := getRootCommand()
|
2019-11-23 03:52:29 +00:00
|
|
|
result := test.RunCmd(cmd, "--verbose")
|
2017-09-22 19:58:12 +00:00
|
|
|
if result.Error != nil {
|
|
|
|
t.Error(result.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !verbose {
|
|
|
|
t.Error("Expected verbose to be true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRootCmd_VerboseShort(t *testing.T) {
|
|
|
|
cmd := getRootCommand()
|
2019-11-23 03:52:29 +00:00
|
|
|
result := test.RunCmd(cmd, "-v")
|
2017-09-22 19:58:12 +00:00
|
|
|
if result.Error != nil {
|
|
|
|
t.Error(result.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !verbose {
|
|
|
|
t.Error("Expected verbose to be true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 04:45:31 +00:00
|
|
|
func TestRootCmd_VersionShort(t *testing.T) {
|
|
|
|
cmd := getRootCommand()
|
2019-11-23 03:52:29 +00:00
|
|
|
result := test.RunCmd(cmd, "-V")
|
2017-09-23 04:45:31 +00:00
|
|
|
if result.Error != nil {
|
|
|
|
t.Error(result.Error)
|
|
|
|
}
|
2018-04-09 05:43:22 +00:00
|
|
|
if !strings.Contains(result.Output, "yq version") {
|
2017-09-23 04:45:31 +00:00
|
|
|
t.Error("expected version message to be printed out, but the message was not found.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRootCmd_VersionLong(t *testing.T) {
|
|
|
|
cmd := getRootCommand()
|
2019-11-23 03:52:29 +00:00
|
|
|
result := test.RunCmd(cmd, "--version")
|
2017-09-23 04:45:31 +00:00
|
|
|
if result.Error != nil {
|
|
|
|
t.Error(result.Error)
|
|
|
|
}
|
2018-04-09 05:43:22 +00:00
|
|
|
if !strings.Contains(result.Output, "yq version") {
|
2017-09-23 04:45:31 +00:00
|
|
|
t.Error("expected version message to be printed out, but the message was not found.")
|
|
|
|
}
|
|
|
|
}
|