2020-04-17 01:03:43 +00:00
|
|
|
package cmd
|
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// import (
|
|
|
|
// "fmt"
|
|
|
|
// "testing"
|
2020-04-17 01:03:43 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// "github.com/mikefarah/yq/v3/test"
|
|
|
|
// )
|
2020-04-17 01:03:43 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewCmd(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b.c 3")
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// c: 3
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|
2020-04-17 01:03:43 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewCmdScript(t *testing.T) {
|
|
|
|
// updateScript := `- command: update
|
|
|
|
// path: b.c
|
|
|
|
// value: 7`
|
|
|
|
// scriptFilename := test.WriteTempYamlFile(updateScript)
|
|
|
|
// defer test.RemoveTempYamlFile(scriptFilename)
|
2020-09-09 01:02:00 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, fmt.Sprintf("new --script %s", scriptFilename))
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// c: 7
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|
2020-09-09 01:02:00 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewAnchorCmd(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b.c 3 --anchorName=fred")
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// c: &fred 3
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|
2020-06-11 03:57:13 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewAliasCmd(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b.c foo --makeAlias")
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// c: *foo
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|
2020-06-11 03:57:13 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewArrayCmd(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b[0] 3")
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// - 3
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|
2020-04-17 01:03:43 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewCmd_Error(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b.c")
|
|
|
|
// if result.Error == nil {
|
|
|
|
// t.Error("Expected command to fail due to missing arg")
|
|
|
|
// }
|
|
|
|
// expectedOutput := `Must provide <path_to_update> <value>`
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Error.Error())
|
|
|
|
// }
|
2020-04-17 01:03:43 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewWithTaggedStyleCmd(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b.c cat --tag=!!str --style=tagged")
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// c: !!str cat
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|
2020-04-17 01:03:43 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewWithDoubleQuotedStyleCmd(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b.c cat --style=double")
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// c: "cat"
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|
2020-04-17 01:03:43 +00:00
|
|
|
|
2020-10-13 01:51:37 +00:00
|
|
|
// func TestNewWithSingleQuotedStyleCmd(t *testing.T) {
|
|
|
|
// cmd := getRootCommand()
|
|
|
|
// result := test.RunCmd(cmd, "new b.c cat --style=single")
|
|
|
|
// if result.Error != nil {
|
|
|
|
// t.Error(result.Error)
|
|
|
|
// }
|
|
|
|
// expectedOutput := `b:
|
|
|
|
// c: 'cat'
|
|
|
|
// `
|
|
|
|
// test.AssertResult(t, expectedOutput, result.Output)
|
|
|
|
// }
|