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

Function TestObjectBasics

jetstream/test/object_test.go:36–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestObjectBasics(t *testing.T) {
37 s := RunBasicJetStreamServer()
38 defer shutdownJSServerAndRemoveStorage(t, s)
39
40 nc, js := jsClient(t, s)
41 defer nc.Close()
42 ctx := context.Background()
43
44 _, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: "notok!", Description: "testing"})
45 expectErr(t, err, jetstream.ErrInvalidStoreName)
46
47 obs, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: "OBJS", Description: "testing"})
48 expectOk(t, err)
49
50 // Create ~16MB object.
51 blob := make([]byte, 16*1024*1024+22)
52 _, err = rand.Read(blob)
53 expectOk(t, err)
54
55 now := time.Now().UTC().Round(time.Second)
56 _, err = obs.PutBytes(ctx, "BLOB", blob)
57 expectOk(t, err)
58
59 // Test info
60 info, err := obs.GetInfo(ctx, "BLOB")
61 expectOk(t, err)
62 if len(info.NUID) == 0 {
63 t.Fatalf("Expected object to have a NUID")
64 }
65 if info.ModTime.IsZero() {
66 t.Fatalf("Expected object to have a non-zero ModTime")
67 }
68 if mt := info.ModTime.Round(time.Second); mt.Sub(now) != 0 && mt.Sub(now) != time.Second {
69 t.Fatalf("Expected ModTime to be about %v, got %v", now, mt)
70 }
71
72 // Make sure the stream is sealed.
73 err = obs.Seal(ctx)
74 expectOk(t, err)
75 si, err := js.Stream(ctx, "OBJ_OBJS")
76 expectOk(t, err)
77 if !si.CachedInfo().Config.Sealed {
78 t.Fatalf("Expected the object stream to be sealed, got %+v", si)
79 }
80
81 status, err := obs.Status(ctx)
82 expectOk(t, err)
83 if !status.Sealed() {
84 t.Fatalf("expected sealed status")
85 }
86 if status.Size() == 0 {
87 t.Fatalf("size is 0")
88 }
89 if status.Storage() != jetstream.FileStorage {
90 t.Fatalf("status reports %d storage", status.Storage())
91 }
92 if status.Description() != "testing" {
93 t.Fatalf("invalid description: '%s'", status.Description())

Callers

nothing calls this directly

Calls 15

FatalfMethod · 0.80
EqualMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
jsClientFunction · 0.70
expectErrFunction · 0.70
expectOkFunction · 0.70
CreateObjectStoreMethod · 0.65
PutBytesMethod · 0.65
GetInfoMethod · 0.65
SealMethod · 0.65
StreamMethod · 0.65

Tested by

no test coverage detected