This commit is contained in:
@@ -45,6 +45,8 @@ func (r Reference) Validate() error {
|
||||
|
||||
// Associations are an immutable revision's term memberships and explicit links.
|
||||
// Reverse discovery reads the same links; callers must not store a second edge.
|
||||
// Terms and Links are independently optional. The zero value is valid for a
|
||||
// valid source; unclassified content never needs a placeholder taxonomy or link.
|
||||
type Associations struct {
|
||||
Terms []string `json:"terms,omitempty"`
|
||||
Links []Reference `json:"links,omitempty"`
|
||||
|
||||
@@ -24,6 +24,20 @@ func TestAssociationsBoundsAndIdentity(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssociationsAreOptional(t *testing.T) {
|
||||
for _, source := range []Reference{{Kind: "news", ID: "article"}, {Kind: "project", ID: "project"}, {Kind: "policy", ID: "terms"}} {
|
||||
for _, raw := range []string{`{}`, `{"terms":null,"links":null}`, `{"terms":[],"links":[]}`, `{"terms":["go"]}`, `{"links":[{"kind":"project","id":"other"}]}`} {
|
||||
var value Associations
|
||||
if err := json.Unmarshal([]byte(raw), &value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := value.Validate(source); err != nil {
|
||||
t.Fatalf("optional associations rejected: %s: %v", raw, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestTaxonomyAndTermText(t *testing.T) {
|
||||
tax := Taxonomy{ID: "categories", Slug: "categories", Name: "Categories", Revision: 1, Active: true}
|
||||
if tax.Validate() != nil {
|
||||
|
||||
Reference in New Issue
Block a user