Added test for err fix

This commit is contained in:
Mike Farah 2022-11-09 21:46:00 +11:00
parent 91b3fb2af3
commit 688fe55bb9

View File

@ -15,11 +15,16 @@ func TestGetLogger(t *testing.T) {
} }
type parseSnippetScenario struct { type parseSnippetScenario struct {
snippet string snippet string
expected *yaml.Node expected *yaml.Node
expectedError string
} }
var parseSnippetScenarios = []parseSnippetScenario{ var parseSnippetScenarios = []parseSnippetScenario{
{
snippet: ":",
expectedError: "yaml: did not find expected key",
},
{ {
snippet: "", snippet: "",
expected: &yaml.Node{ expected: &yaml.Node{
@ -82,6 +87,14 @@ var parseSnippetScenarios = []parseSnippetScenario{
func TestParseSnippet(t *testing.T) { func TestParseSnippet(t *testing.T) {
for _, tt := range parseSnippetScenarios { for _, tt := range parseSnippetScenarios {
actual, err := parseSnippet(tt.snippet) 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 { if err != nil {
t.Error(tt.snippet) t.Error(tt.snippet)
t.Error(err) t.Error(err)