1package main23import (4 "reflect"5 "testing"6)78func TestRegistry(t *testing.T) {9 if len(sources) != 5 {10 t.Fatalf("registry holds %d sources, want 5", len(sources))11 }12 for _, slug := range []string{"mapgenie", "ign-wiki", "piggyback", "nasa-trek", "arcgis-hub"} {13 src, ok := sourceBySlug(slug)14 if !ok {15 t.Fatalf("registry misses %s", slug)16 }17 // Every source publishes a complete map save for icons, which Trek18 // and the civic importer leave to the standard library's glyphs; the19 // game sources differ in quality per component, never in kind.20 wanted := []Component{21 ComponentRaster, ComponentIcons, ComponentLocations, ComponentMetadata,22 }23 if slug == "nasa-trek" || slug == "arcgis-hub" {24 wanted = []Component{ComponentRaster, ComponentLocations, ComponentMetadata}25 if src.Components().Has(ComponentIcons) {26 t.Errorf("%s claims icons it does not fetch", slug)27 }28 }29 for _, component := range wanted {30 if !src.Components().Has(component) {31 t.Errorf("%s misses component %s", slug, component)32 }33 }34 if src.Name() == "" || src.Description() == "" || src.TargetHint() == "" {35 t.Errorf("%s is missing a face: %q %q %q", slug, src.Name(), src.Description(), src.TargetHint())36 }37 }38 if _, ok := sourceBySlug("nowhere"); ok {39 t.Error("registry answered for a source it does not hold")40 }41}4243func TestFetchArgs(t *testing.T) {44 good := []struct {45 source string46 target string47 want []string48 }{49 {"mapgenie", "cyberpunk-2077", []string{"-game", "cyberpunk-2077"}},50 {"ign-wiki", "cyberpunk-2077/night-city", []string{"-ign", "cyberpunk-2077/night-city"}},51 {"piggyback", "cyberpunk-2077/night-city", []string{"-piggyback", "cyberpunk-2077/night-city"}},52 {"nasa-trek", "mars", []string{"-trek", "mars"}},53 {"arcgis-hub", "bend-or", []string{"-arcgis", "bend-or"}},54 }55 for _, at := range good {56 src, _ := sourceBySlug(at.source)57 got, err := src.FetchArgs(at.target)58 if err != nil {59 t.Errorf("%s %q refused: %v", at.source, at.target, err)60 continue61 }62 if !reflect.DeepEqual(got, at.want) {63 t.Errorf("%s %q built %v, want %v", at.source, at.target, got, at.want)64 }65 }6667 bad := []struct {68 source string69 target string70 }{71 {"mapgenie", ""},72 {"mapgenie", "cyberpunk-2077/night-city"}, // single-slug source takes no slash73 {"mapgenie", "-list"}, // a target must never read as a flag74 {"mapgenie", "night city"},75 {"ign-wiki", "night-city"}, // pair source needs its slash76 {"ign-wiki", "a/b/c"}, // exactly one77 {"piggyback", "/night-city"}, // no empty half78 {"piggyback", "night-city/"},79 {"piggyback", "Night-City/x"}, // slugs are lowercase80 {"nasa-trek", "mars/global"}, // a body is one slug81 {"arcgis-hub", "bend/or"}, // a city is one slug82 }83 for _, at := range bad {84 src, _ := sourceBySlug(at.source)85 if _, err := src.FetchArgs(at.target); err == nil {86 t.Errorf("%s accepted %q", at.source, at.target)87 }88 }89}