MCPcopy
hub / github.com/perkeep/perkeep / TestDelete

Function TestDelete

pkg/blobserver/diskpacked/diskpacked_test.go:121–201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestDelete(t *testing.T) {
122 ctx := context.Background()
123 sto := newTempDiskpacked(t)
124
125 var (
126 A = &test.Blob{Contents: "some small blob"}
127 B = &test.Blob{Contents: strings.Repeat("some middle blob", 100)}
128 C = &test.Blob{Contents: strings.Repeat("A 8192 bytes length largish blob", 8192/32)}
129 )
130
131 type step func() error
132
133 stepAdd := func(tb *test.Blob) step { // add the blob
134 return func() error {
135 sb, err := sto.ReceiveBlob(ctxbg, tb.BlobRef(), tb.Reader())
136 if err != nil {
137 return fmt.Errorf("ReceiveBlob of %s: %w", sb, err)
138 }
139 if sb != tb.SizedRef() {
140 return fmt.Errorf("Received %v; want %v", sb, tb.SizedRef())
141 }
142 return nil
143 }
144 }
145
146 stepCheck := func(want ...*test.Blob) step { // check the blob
147 wantRefs := make([]blob.SizedRef, len(want))
148 for i, tb := range want {
149 wantRefs[i] = tb.SizedRef()
150 }
151 return func() error {
152 if err := storagetest.CheckEnumerate(sto, wantRefs); err != nil {
153 return err
154 }
155 return nil
156 }
157 }
158
159 stepDelete := func(tb *test.Blob) step {
160 return func() error {
161 if err := sto.RemoveBlobs(ctx, []blob.Ref{tb.BlobRef()}); err != nil {
162 return fmt.Errorf("RemoveBlob(%s): %w", tb.BlobRef(), err)
163 }
164 return nil
165 }
166 }
167
168 var deleteTests = [][]step{
169 {
170 stepAdd(A),
171 stepDelete(A),
172 stepCheck(),
173 stepAdd(B),
174 stepCheck(B),
175 stepDelete(B),
176 stepCheck(),
177 stepAdd(C),
178 stepCheck(C),

Callers

nothing calls this directly

Calls 8

CheckEnumerateFunction · 0.92
newTempDiskpackedFunction · 0.85
ReaderMethod · 0.80
ReceiveBlobMethod · 0.65
BlobRefMethod · 0.65
RemoveBlobsMethod · 0.65
sFunction · 0.50
SizedRefMethod · 0.45

Tested by

no test coverage detected