diff --git a/main_test.go b/main_test.go index 47d6c7a..d1a8b68 100644 --- a/main_test.go +++ b/main_test.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "io" "log" "net/http" @@ -133,6 +134,12 @@ func TestApi(t *testing.T) { func TestValidateEndpoint(t *testing.T) { validYml := loadTestdata(t, "valid.publiccode.yml") invalidYml := loadTestdata(t, "invalid.publiccode.yml") + externalChecksYml := strings.Replace( + validYml, + "https://github.com/example/project.git", + "http://127.0.0.1/repository.git", + 1, + ) tests := []TestCase{ { @@ -167,6 +174,32 @@ func TestValidateEndpoint(t *testing.T) { assert.NotNil(t, response["normalized"]) }, }, + { + description: "validate: external checks disabled", + query: "QUERY /v1/validate", + body: externalChecksYml, + expectedCode: 200, + expectedContentType: "application/json; charset=utf-8", + validateFunc: func(t *testing.T, response map[string]any) { + assert.Equal(t, true, response["valid"]) + assert.Empty(t, response["results"]) + }, + }, + { + description: "validate: external checks enabled", + query: "QUERY /v1/validate?external-checks=true", + body: externalChecksYml, + 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.Contains(t, fmt.Sprint(results), "non-public") + assert.Nil(t, response["normalized"]) + }, + }, { description: "validate: invalid file", query: "QUERY /v1/validate", diff --git a/testdata/invalid.publiccode.yml b/testdata/invalid.publiccode.yml index 63daa3c..c050635 100644 --- a/testdata/invalid.publiccode.yml +++ b/testdata/invalid.publiccode.yml @@ -1,7 +1,7 @@ publiccodeYmlVersion: "0" name: Medusa -url: "https://github.com/italia/developers.italia.it.git" +url: "https://github.com/example/project.git" platforms: - web diff --git a/testdata/valid.publiccode.yml b/testdata/valid.publiccode.yml index 712ebe3..f197344 100644 --- a/testdata/valid.publiccode.yml +++ b/testdata/valid.publiccode.yml @@ -1,7 +1,7 @@ publiccodeYmlVersion: "0" name: Medusa -url: "https://github.com/italia/developers.italia.it.git" +url: "https://github.com/example/project.git" platforms: - web