package buscompose import ( "slices" "testing" ) // A reader of a stream kept last per subject is granted what an ordered consumer of that stream uses, and a reader of // another stream only its own durable (design 47 G ยง556, A-4). func TestAReaderOfAStreamKeptLastPerSubjectIsGrantedItsOrderedConsumer(t *testing.T) { p := Principal{Module: "m", Node: "a"} ordered := []string{"$JS.API.CONSUMER.CREATE.S", "$JS.API.CONSUMER.MSG.NEXT.S.*", "$JS.API.CONSUMER.INFO.S.*", "$JS.API.CONSUMER.DELETE.S.*"} last := heardGrants(p, []Heard{{Stream: "S", Filters: []string{"f"}, LastPerSubject: true}}) for _, w := range ordered { if !slices.Contains(last, w) { t.Errorf("a last-per-subject reader is not granted %s: %v", w, last) } } plain := heardGrants(p, []Heard{{Stream: "S", Filters: []string{"f"}}}) if slices.Contains(plain, ordered[0]) { t.Errorf("a reader of another stream is granted an ordered consumer: %v", plain) } }