BucketStreamConfig and ModuleStreamConfig are the stream configurations the controller's CreateOrUpdateKeyValue (BucketConfig) and StreamConfigFor assert at its start, pure, for the grants part's create of a bucket or stream a manifest declares and the bus lacks. A log already has Log.Config. Never used for an update. Issue: 1790
47 lines
2.1 KiB
Go
47 lines
2.1 KiB
Go
package buscompose
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
)
|
|
|
|
// Defends issue 1790 (ADR 0547 §5): the grants part creates a declared bucket and stream as the controller asserts them.
|
|
func TestDeclaredStreamsAreCreatedAsTheControllerAssertsThem(t *testing.T) {
|
|
plain := BucketStreamConfig(Bucket{Module: "mesh-vault", Name: "bus-accounts"})
|
|
keyed := BucketStreamConfig(Bucket{Module: "m", Name: "presence", History: 5, TTLSeconds: 60, KeyTTL: true})
|
|
queue := ModuleStreamConfig(ModuleStream{Module: "b", Name: "ASKS", Events: []string{"ask"}, MaxAgeDays: 7, MaxMiB: 32,
|
|
WorkQueue: true, Duplicates: 1})
|
|
for _, row := range []struct {
|
|
what string
|
|
got, want any
|
|
}{
|
|
{"bucket name", plain.Name, "KV_mesh-vault_bus-accounts"},
|
|
{"bucket subjects", plain.Subjects[0], "$KV.mesh-vault_bus-accounts.>"},
|
|
{"bucket history defaults to one", plain.MaxMsgsPerSubject, int64(1)},
|
|
{"bucket cap", plain.MaxBytes, int64(StateMaxBytes)},
|
|
{"bucket value cap", plain.MaxMsgSize, int32(StateMaxValueBytes)},
|
|
{"bucket duplicate window", plain.Duplicates, 2 * time.Minute},
|
|
{"bucket discards new", plain.Discard, jetstream.DiscardNew},
|
|
{"bucket direct and rollup, no delete", plain.AllowDirect && plain.AllowRollup && plain.DenyDelete, true},
|
|
{"bucket without key ttl", plain.AllowMsgTTL, false},
|
|
{"history", keyed.MaxMsgsPerSubject, int64(5)},
|
|
{"age", keyed.MaxAge, time.Minute},
|
|
{"duplicate window under the age", keyed.Duplicates, time.Minute},
|
|
{"key ttl markers", keyed.SubjectDeleteMarkerTTL, KeyTTLMarkerTTL},
|
|
{"key ttl", keyed.AllowMsgTTL, true},
|
|
{"queue retention", queue.Retention, jetstream.WorkQueuePolicy},
|
|
{"queue subjects", queue.Subjects[0], "mesh.stream.b.event.ask"},
|
|
{"queue age", queue.MaxAge, 7 * 24 * time.Hour},
|
|
{"queue cap", queue.MaxBytes, int64(32 << 20)},
|
|
{"queue discards new", queue.Discard, jetstream.DiscardNew},
|
|
{"queue duplicates", queue.Duplicates, time.Hour},
|
|
{"queue metadata", queue.Metadata[WorkQueueMetadata] + queue.Metadata[RestrictedMetadata], "truetrue"},
|
|
} {
|
|
if row.got != row.want {
|
|
t.Errorf("%s: %v, want %v", row.what, row.got, row.want)
|
|
}
|
|
}
|
|
}
|