// This test needs internal/provider, which imports internal/catalog, so it // lives in the external test package to avoid an import cycle. package catalog_test import ( "testing" "git.starwarslab.us/ATOM_IT/Deployr/internal/catalog" "git.starwarslab.us/ATOM_IT/Deployr/internal/provider" ) // TestSourcesUseKnownProviders catches a typo in a catalog source before it // turns into a runtime "unknown provider" on someone's endpoint. func TestSourcesUseKnownProviders(t *testing.T) { cat, err := catalog.Embedded() if err != nil { t.Fatal(err) } for _, app := range cat.Apps { for _, goos := range app.Platforms() { for _, src := range app.TargetFor(goos).Sources { p, ok := provider.Get(src.Provider) if !ok { t.Errorf("%s/%s: unknown provider %q", app.ID, goos, src.Provider) continue } supported := false for _, os := range p.OSes() { if os == goos { supported = true break } } if !supported { t.Errorf("%s: provider %q cannot run on %s", app.ID, src.Provider, goos) } } } } } // TestDirectSourcesAreInstallable checks the two rules the direct provider // enforces at runtime: an exe needs silent switches, and a zip needs somewhere // to go. Catching these here beats catching them on an endpoint. func TestDirectSourcesAreInstallable(t *testing.T) { cat, err := catalog.Embedded() if err != nil { t.Fatal(err) } for _, app := range cat.Apps { for _, goos := range app.Platforms() { for _, src := range app.TargetFor(goos).Sources { if src.Provider != "direct" { continue } kind := src.Kind if kind == "" { kind = provider.InferKind(src.URLFor("amd64")) } switch kind { case "": t.Errorf("%s/%s: cannot infer installer kind from %q; set kind", app.ID, goos, src.URL) case "exe": if len(src.SilentArgs) == 0 { t.Errorf("%s/%s: exe source has no silent_args", app.ID, goos) } case "zip": if src.Dest == "" && goos != "darwin" { t.Errorf("%s/%s: zip source has no dest", app.ID, goos) } } } } } }