61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package catalog_test
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
catalogdata "git.zaynet.fr/DoGaMa/DoGaMa-serv/catalog"
|
|
"git.zaynet.fr/DoGaMa/DoGaMa-serv/internal/catalog"
|
|
)
|
|
|
|
func TestBuiltInCatalogValidatesDeterministically(t *testing.T) {
|
|
first, err := catalog.LoadFS(catalogdata.Files, ".")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := catalog.LoadFS(catalogdata.Files, ".")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(first) != 1 || first[0].Template.ID != "palworld-official" || first[0].Digest != second[0].Digest || first[0].CanonicalYAML != second[0].CanonicalYAML {
|
|
t.Fatalf("catalog snapshots = %#v, %#v", first, second)
|
|
}
|
|
}
|
|
|
|
func TestSchemaErrorsContainFieldPathAndLine(t *testing.T) {
|
|
body, err := catalogdata.Files.ReadFile("palworld/template.yaml")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body = []byte(strings.Replace(string(body), "schema_version: 1", "schema_version: 2", 1))
|
|
_, err = catalog.Validate(body, "palworld", catalogdata.Files)
|
|
var validation *catalog.ValidationErrors
|
|
if !errors.As(err, &validation) || len(validation.Issues) == 0 {
|
|
t.Fatalf("validation error = %#v", err)
|
|
}
|
|
if validation.Issues[0].Path == "" || validation.Issues[0].Line == 0 {
|
|
t.Fatalf("validation issue = %#v", validation.Issues[0])
|
|
}
|
|
}
|
|
|
|
func TestCrossValidationRejectsUnknownBackupMount(t *testing.T) {
|
|
body, err := catalogdata.Files.ReadFile("palworld/template.yaml")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body = []byte(strings.Replace(string(body), " - saved\n restart_after_backup", " - missing\n restart_after_backup", 1))
|
|
_, err = catalog.Validate(body, "palworld", catalogdata.Files)
|
|
var validation *catalog.ValidationErrors
|
|
if !errors.As(err, &validation) {
|
|
t.Fatalf("validation error = %#v", err)
|
|
}
|
|
found := false
|
|
for _, issue := range validation.Issues {
|
|
found = found || issue.Path == "/backup/source_mounts"
|
|
}
|
|
if !found {
|
|
t.Fatalf("issues = %#v", validation.Issues)
|
|
}
|
|
}
|