Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion testdata/invalid.publiccode.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion testdata/valid.publiccode.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading