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

Function TestCompatibilityObjectStoreWatchUpdates

test/compat_test.go:341–392  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

339}
340
341func TestCompatibilityObjectStoreWatchUpdates(t *testing.T) {
342 t.Parallel()
343
344 type config struct {
345 Bucket string `json:"bucket"`
346 Object string `json:"object"`
347 }
348
349 nc := connect(t)
350 js, err := jetstream.New(nc)
351 if err != nil {
352 t.Fatalf("Error connecting to NATS: %v", err)
353 }
354 defer nc.Close()
355 ctx := context.Background()
356
357 // setup subscription on which tester will be sending requests
358 sub, err := nc.SubscribeSync("tests.object-store.watch-updates.>")
359 if err != nil {
360 t.Fatalf("Error subscribing to test subject: %v", err)
361 }
362 defer sub.Unsubscribe()
363
364 msg, err := sub.NextMsg(1 * time.Hour)
365 if err != nil {
366 t.Fatalf("Error getting message: %v", err)
367 }
368 // Watch object
369 var cfg config
370 if err := json.Unmarshal(msg.Data, &cfg); err != nil {
371 t.Fatalf("Error unmarshalling message: %v", err)
372 }
373 os, err := js.ObjectStore(ctx, cfg.Bucket)
374 if err != nil {
375 t.Fatalf("Error getting object store: %v", err)
376 }
377 watcher, err := os.Watch(ctx, jetstream.UpdatesOnly())
378 if err != nil {
379 t.Fatalf("Error getting watcher: %v", err)
380 }
381 var info *jetstream.ObjectInfo
382 select {
383 case info = <-watcher.Updates():
384 case <-time.After(30 * time.Second):
385 t.Fatalf("Timeout waiting for object update")
386 }
387
388 if err := msg.Respond([]byte(info.Digest)); err != nil {
389 t.Fatalf("Error responding to message: %v", err)
390 }
391 validateTestResult(t, sub)
392}
393
394func TestCompatibilityObjectStoreGetLink(t *testing.T) {
395 t.Parallel()

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
UpdatesOnlyFunction · 0.92
connectFunction · 0.85
validateTestResultFunction · 0.85
FatalfMethod · 0.80
UnsubscribeMethod · 0.80
NextMsgMethod · 0.80
SubscribeSyncMethod · 0.65
ObjectStoreMethod · 0.65
WatchMethod · 0.65
UpdatesMethod · 0.65
RespondMethod · 0.65

Tested by

no test coverage detected