MCPcopy
hub / github.com/containerd/containerd / TestContentLeased

Function TestContentLeased

core/metadata/content_test.go:97–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestContentLeased(t *testing.T) {
98 ctx, db := testDB(t)
99
100 cs := db.ContentStore()
101
102 blob := []byte("any content")
103 expected := digest.FromBytes(blob)
104
105 lctx, _, err := createLease(ctx, db, "lease-1")
106 if err != nil {
107 t.Fatal(err)
108 }
109 if err := content.WriteBlob(lctx, cs, "test-1", bytes.NewReader(blob),
110 ocispec.Descriptor{Size: int64(len(blob)), Digest: expected}); err != nil {
111 t.Fatal(err)
112 }
113 if err := checkContentLeased(lctx, db, expected); err != nil {
114 t.Fatal("lease checked failed:", err)
115 }
116 if err := checkIngestLeased(lctx, db, "test-1"); err == nil {
117 t.Fatal("test-1 should not be leased after write")
118 } else if !errdefs.IsNotFound(err) {
119 t.Fatal("lease checked failed:", err)
120 }
121
122 lctx, _, err = createLease(ctx, db, "lease-2")
123 if err != nil {
124 t.Fatal(err)
125 }
126
127 if _, err := cs.Writer(lctx,
128 content.WithRef("test-2"),
129 content.WithDescriptor(ocispec.Descriptor{Size: int64(len(blob)), Digest: expected})); err == nil {
130 t.Fatal("expected already exist error")
131 } else if !errdefs.IsAlreadyExists(err) {
132 t.Fatal(err)
133 }
134 if err := checkContentLeased(lctx, db, expected); err != nil {
135 t.Fatal("lease checked failed:", err)
136 }
137 if err := checkIngestLeased(lctx, db, "test-2"); err == nil {
138 t.Fatal("test-2 should not be leased")
139 } else if !errdefs.IsNotFound(err) {
140 t.Fatal("lease checked failed:", err)
141 }
142}
143
144func TestIngestLeased(t *testing.T) {
145 ctx, db := testDB(t)

Callers

nothing calls this directly

Calls 10

WriteBlobFunction · 0.92
WithRefFunction · 0.92
WithDescriptorFunction · 0.92
createLeaseFunction · 0.85
checkContentLeasedFunction · 0.85
checkIngestLeasedFunction · 0.85
FatalMethod · 0.80
testDBFunction · 0.70
ContentStoreMethod · 0.65
WriterMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…