INNER CODE UNIT · Go

TestBucketDeleteOrphanChunks

256dpi/lungo · bucket_test.go:161

func TestBucketDeleteOrphanChunks(t *testing.T) {
	bucketTest(t, 0, func(t *testing.T, b *Bucket) {
		id, err := b.UploadFromStream(nil, "foo", strings.NewReader("Hello World!"))
		assert.NoError(t, err)

		// remove only the files row, leaving chunks behind
		_, err = b.files.DeleteOne(nil, bson.M{"_id": id})
		assert.NoError(t, err)

		// Delete must surface ErrFileNotFound (the orphan chunks are still
		// cleaned up internally so subsequent finds return nothing)
		err = b.Delete(nil, id)
		assert.Equal(t, ErrFileNotFound, err)

		n, err := b.chunks.CountDocuments(nil, bson.M{"files_id": id})
		assert.NoError(t, err)
		assert.Equal(t, int64(0), n)
	})

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…