MCPcopy
hub / github.com/nats-io/nats.go / TestConsumerCachedInfo

Function TestConsumerCachedInfo

jetstream/test/consumer_test.go:1440–1525  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1438}
1439
1440func TestConsumerCachedInfo(t *testing.T) {
1441 srv := RunBasicJetStreamServer()
1442 defer shutdownJSServerAndRemoveStorage(t, srv)
1443 nc, err := nats.Connect(srv.ClientURL())
1444 if err != nil {
1445 t.Fatalf("Unexpected error: %v", err)
1446 }
1447
1448 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1449 defer cancel()
1450 js, err := jetstream.New(nc)
1451 if err != nil {
1452 t.Fatalf("Unexpected error: %v", err)
1453 }
1454 defer nc.Close()
1455
1456 for _, consType := range []string{"pull", "push"} {
1457 t.Run(consType, func(t *testing.T) {
1458 s, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "foo", Subjects: []string{"FOO.*"}})
1459 if err != nil {
1460 t.Fatalf("Unexpected error: %v", err)
1461 }
1462 var c consInfoConstraint
1463 if consType == "pull" {
1464 c, err = s.CreateOrUpdateConsumer(ctx, jetstream.ConsumerConfig{
1465 Durable: "cons",
1466 AckPolicy: jetstream.AckExplicitPolicy,
1467 Description: "test consumer",
1468 })
1469 } else {
1470 c, err = s.CreateOrUpdatePushConsumer(ctx, jetstream.ConsumerConfig{
1471 DeliverSubject: "inbox",
1472 Durable: "cons",
1473 AckPolicy: jetstream.AckExplicitPolicy,
1474 Description: "test consumer",
1475 })
1476 }
1477 if err != nil {
1478 t.Fatalf("Unexpected error: %v", err)
1479 }
1480
1481 info := c.CachedInfo()
1482
1483 if info.Stream != "foo" {
1484 t.Fatalf("Invalid stream name; expected: 'foo'; got: %s", info.Stream)
1485 }
1486 if info.Config.Description != "test consumer" {
1487 t.Fatalf("Invalid consumer description; expected: 'test consumer'; got: %s", info.Config.Description)
1488 }
1489
1490 // update consumer and see if info is updated
1491 if consType == "pull" {
1492 _, err = s.CreateOrUpdateConsumer(ctx, jetstream.ConsumerConfig{
1493 Durable: "cons",
1494 AckPolicy: jetstream.AckExplicitPolicy,
1495 Description: "updated consumer",
1496 })
1497 } else {

Callers

nothing calls this directly

Calls 11

CachedInfoMethod · 0.95
NewFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
CreateStreamMethod · 0.65
DeleteStreamMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected