1package curation23import (4 "strings"5 "testing"67 "github.com/FelineStateMachine/atlas/format/semconv"8)910func TestTheEmbeddedCorpusIsReadable(t *testing.T) {11 tables, err := Load()12 if err != nil {13 t.Fatal(err)14 }15 if len(tables.Queue()) == 0 {16 t.Fatal("the corpus declares no queue")17 }18 // The queue is a decision, so it is spelled out rather than derived.19 want := []string{"merge", "national", "stdicons", "lenses"}20 for at, name := range want {21 if tables.Queue()[at] != name {22 t.Errorf("position %d runs %q, want %q", at, tables.Queue()[at], name)23 }24 }25 if tables.MatchRadiusPx() != 160 || tables.SeparateRadiusPx() != 320 || tables.NearbyFloorPx() != 48 {26 t.Errorf("the resolution distances read %g/%g/%g",27 tables.MatchRadiusPx(), tables.SeparateRadiusPx(), tables.NearbyFloorPx())28 }29 for _, key := range []string{30 semconv.KeyNoteText, semconv.KeyGeoLat, semconv.KeyGeoLon, semconv.KeyIconStd,31 } {32 if !tables.DonorFillsEmpty(key) {33 t.Errorf("%s is not a donor-fills-empty attribute", key)34 }35 }36 if tables.DonorFillsEmpty(semconv.KeyRenderAs) {37 t.Error("an unlisted attribute is not serving-wins")38 }39 if len(tables.EvidenceCollections("bend-or")) == 0 {40 t.Error("the city volume names no evidence collections")41 }42 if len(tables.EvidenceCollections("tunic")) != 0 {43 t.Error("a volume nobody surveyed names evidence collections")44 }45}4647func TestCurationIsHeldToItsSchema(t *testing.T) {48 cases := []struct {49 what string50 data string51 refuse string52 }{53 {54 what: "another schema",55 data: `{"schema": 99}`,56 refuse: "schema",57 },58 {59 what: "no queue at all",60 data: `{"schema": 1, "merge": {"matchRadiusPx": 1, "separateRadiusPx": 2}}`,61 refuse: "no enricher queue",62 },63 {64 what: "radii that cannot hold anything back",65 data: `{"schema": 1, "queue": {"order": ["merge"]},66 "merge": {"matchRadiusPx": 320, "separateRadiusPx": 160}}`,67 refuse: "the second has to be the larger",68 },69 {70 what: "a policy for an attribute nobody registered",71 data: `{"schema": 1, "queue": {"order": ["merge"]},72 "merge": {"matchRadiusPx": 160, "separateRadiusPx": 320,73 "attributes": {"donorFillsEmpty": ["atlas.invented.key"]}}}`,74 refuse: "the conventions registry does not know it",75 },76 }77 for _, c := range cases {78 t.Run(c.what, func(t *testing.T) {79 if _, err := LoadFrom([]byte(c.data)); err == nil ||80 !strings.Contains(err.Error(), c.refuse) {81 t.Fatalf("error %v, expected something about %q", err, c.refuse)82 }83 })84 }85}8687func TestProseRidesBesideTheData(t *testing.T) {88 // Every section carries its own explanation as a sibling key, the way the89 // generate lane's curation does. A value that is not the shape a section90 // expects is commentary, not data.91 tables, err := LoadFrom([]byte(`{92 "schema": 1,93 "queue": {"what": "why these run in this order", "order": ["merge"]},94 "merge": {"what": "the distances", "matchRadiusPx": 160, "separateRadiusPx": 320},95 "national": {"what": "the evidence", "evidenceCollections": {96 "what": "keyed by volume", "city": ["Subwatersheds"]}}97 }`))98 if err != nil {99 t.Fatal(err)100 }101 if len(tables.EvidenceCollections("city")) != 1 {102 t.Error("a volume's evidence was lost among the prose")103 }104 if len(tables.EvidenceCollections("what")) != 0 {105 t.Error("commentary was read as a volume")106 }107}