package catalogue import ( "strings" "testing" ) // A provision names what the consumer is coupled to (novox/hq ADR 0027). // // The fault this defends against does not look like a fault: resolution succeeds, the module // deploys, and the first query fails somewhere else entirely. Every earlier test had exactly one // provider of each name, so no mismatch was expressible and none was caught. func TestAModuleMayNotProvideAGenericDatabase(t *testing.T) { for _, hidden := range []string{"database", "db", "sql", "sql-database"} { _, err := ParseManifest([]byte(`{"module":"postgres","version":"1", "provides":[{"name":"` + hidden + `","scope":"mesh"}]}`)) if err == nil { t.Fatalf("providing %q was accepted; a requirement for it matches any engine", hidden) } for _, want := range []string{hidden, "postgres-database", "first query"} { if !strings.Contains(err.Error(), want) { t.Errorf("refusing %q did not mention %q, so nobody learns what to write:\n%v", hidden, want, err) } } } } // The rule is about coupling, not about specificity everywhere. Naming `route` after a particular // proxy would be the same error in the other direction. func TestARoleNameIsFineWhereTheConsumerCannotTellTheDifference(t *testing.T) { for _, role := range []string{"route", "resolver", "artifact-store", "postgres-database"} { if _, err := ParseManifest([]byte(`{"module":"m","version":"1", "provides":[{"name":"` + role + `","scope":"mesh"}]}`)); err != nil { t.Errorf("providing %q was refused, and it names what a consumer actually gets: %v", role, err) } } }