This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package dashboard
|
||||
|
||||
import "testing"
|
||||
|
||||
func valid() Document {
|
||||
return Document{"schemaVersion": 1, "id": "00000000-0000-0000-0000-000000000001", "slug": "overview", "name": "Overview", "scope": "system", "variables": []any{}, "widgets": []any{}, "settings": map[string]any{}}
|
||||
}
|
||||
func TestInvalidDocumentRejected(t *testing.T) {
|
||||
doc := valid()
|
||||
delete(doc, "widgets")
|
||||
if err := Validate(doc); err == nil {
|
||||
t.Fatal("expected invalid document rejection")
|
||||
}
|
||||
}
|
||||
func TestMigrationIsDeterministicAndPreservesCustomSettings(t *testing.T) {
|
||||
doc := valid()
|
||||
doc["settings"].(map[string]any)["refreshSeconds"] = 90
|
||||
first, err := Migrate(doc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := Migrate(doc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if first["schemaVersion"] != 2 || first["settings"].(map[string]any)["refreshSeconds"] != float64(90) {
|
||||
t.Fatalf("migration overwrote custom value: %+v", first)
|
||||
}
|
||||
if len(first["widgets"].([]any)) != len(second["widgets"].([]any)) {
|
||||
t.Fatal("migration not deterministic")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user