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") } } // Test that ValidateInstanceLink() works with a valid instance of md and cleans paths. func TestValidateInstanceDoesCleanPathFromUrl(t *testing.T) { result, err := ValidateInstanceLink("https://hessen.museum-digital.de/home") 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") } }