Verify versioned contracts and exact offline distribution selection
This commit is contained in:
37
internal/validation/hosting_test.go
Normal file
37
internal/validation/hosting_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCanonicalStaticPaths(t *testing.T) {
|
||||
set := loadSet(t)
|
||||
server := httptest.NewServer(http.FileServer(http.Dir("../..")))
|
||||
defer server.Close()
|
||||
for _, record := range set.Catalog.Schemas {
|
||||
t.Run(record.Name, func(t *testing.T) {
|
||||
route := strings.TrimPrefix(record.ID, schemaBase)
|
||||
response, err := server.Client().Get(server.URL + "/" + route)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
got, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want, err := os.ReadFile("../../" + record.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response.StatusCode != 200 || string(got) != string(want) {
|
||||
t.Fatalf("canonical path %s did not serve the exact schema bytes", record.ID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user