diff --git a/pkg/yqlib/lib_test.go b/pkg/yqlib/lib_test.go index 0b601817..fb3d5c77 100644 --- a/pkg/yqlib/lib_test.go +++ b/pkg/yqlib/lib_test.go @@ -15,11 +15,16 @@ func TestGetLogger(t *testing.T) { } type parseSnippetScenario struct { - snippet string - expected *yaml.Node + snippet string + expected *yaml.Node + expectedError string } var parseSnippetScenarios = []parseSnippetScenario{ + { + snippet: ":", + expectedError: "yaml: did not find expected key", + }, { snippet: "", expected: &yaml.Node{ @@ -82,6 +87,14 @@ var parseSnippetScenarios = []parseSnippetScenario{ func TestParseSnippet(t *testing.T) { for _, tt := range parseSnippetScenarios { actual, err := parseSnippet(tt.snippet) + if tt.expectedError != "" { + if err == nil { + t.Errorf("Expected error '%v' but it worked!", tt.expectedError) + } else { + test.AssertResultComplexWithContext(t, tt.expectedError, err.Error(), tt.snippet) + } + return + } if err != nil { t.Error(tt.snippet) t.Error(err)