Add add config validators

This commit is contained in:
2025-02-24 04:33:43 +01:00
parent dfe1bdfeb4
commit d4c83e27d2
8 changed files with 262 additions and 42 deletions

View File

@@ -0,0 +1,55 @@
package configloader
import (
"testing"
)
// Test that ValidateInstanceLink() fails on non-URLs.
func TestValidateInstanceFailsOnNonUrl(t *testing.T) {
_, err := ValidateInstanceLink("abcmuseum-digital.org")
if err == nil {
t.Fatalf("ValidateInstanceLink() does not return an error on a non-URL")
}
}
// Test that ValidateInstanceLink() fails on links outside of md.
func TestValidateInstanceLinkFailsOutsideOfMd(t *testing.T) {
_, err := ValidateInstanceLink("test.museum-digital.de")
if err == nil {
t.Fatalf("ValidateInstanceLink() accepts URLs outside of the main museum-digital")
}
}
// Test that ValidateInstanceLink() fails on valid md aggregated instances
// (uploads can only happen to regional instances / those that have a dedicated
// instance of musdb).
func TestValidateInstanceLinkFailsWithAggregatedInstance(t *testing.T) {
_, err := ValidateInstanceLink("https://nat.museum-digital.de")
if err == nil {
t.Fatalf("ValidateInstanceLink() accepts URLs of aggregated instance")
}
}
// Test that ValidateInstanceLink() works with a valid instance of md.
func TestValidateInstanceWorks(t *testing.T) {
result, err := ValidateInstanceLink("https://hessen.museum-digital.de")
if err != nil {
t.Fatalf("ValidateInstanceLink() returns an error where it should work")
}
if result != "https://hessen.museum-digital.de" {
t.Fatalf("Output of ValidateInstanceLink() is not https://hessen.museum-digital.de where it should be")
}
}