diff --git a/main_test.go b/main_test.go index 6b3a914..86f1b1f 100644 --- a/main_test.go +++ b/main_test.go @@ -134,6 +134,7 @@ func TestApi(t *testing.T) { func TestValidateEndpoint(t *testing.T) { validYml := loadTestdata(t, "valid.publiccode.yml") invalidYml := loadTestdata(t, "invalid.publiccode.yml") + malformedYml := loadTestdata(t, "malformed.publiccode.yml") externalChecksYml := strings.Replace( validYml, "https://github.com/example/project.git", @@ -248,6 +249,20 @@ func TestValidateEndpoint(t *testing.T) { assert.Nil(t, response["normalized"]) }, }, + { + description: "validate: malformed YAML", + query: "QUERY /v1/validate", + body: malformedYml, + expectedCode: 200, + expectedContentType: "application/json; charset=utf-8", + validateFunc: func(t *testing.T, response map[string]any) { + assert.Equal(t, false, response["valid"]) + results, ok := response["results"].([]any) + assert.True(t, ok) + assert.NotEmpty(t, results) + assert.Nil(t, response["normalized"]) + }, + }, } runTestCases(t, tests) diff --git a/testdata/malformed.publiccode.yml b/testdata/malformed.publiccode.yml new file mode 100644 index 0000000..3d31616 --- /dev/null +++ b/testdata/malformed.publiccode.yml @@ -0,0 +1,2 @@ +publiccodeYmlVersion: "0" +name: [unterminated