package vaultik_test import ( "encoding/json" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sneak.berlin/go/vaultik/internal/log" "sneak.berlin/go/vaultik/internal/vaultik" ) // TestPruneBlobs_JSONDeletesWithoutAsking checks that prune with --json // and without --force deletes an unreferenced blob without the // confirmation prompt. Stdin is empty, so a prompt would read no answer // and cancel, and its text would come before the JSON document. func TestPruneBlobs_JSONDeletesWithoutAsking(t *testing.T) { log.Initialize(log.Config{}) t.Parallel() env := newListEnv(t) // The store holds no manifest, so nothing references this blob. addBlob(t, env.store.testStorer, testBlobHashA) err := env.v.PruneBlobs(&vaultik.PruneOptions{JSON: true}) require.NoError(t, err) blobKey := "blobs/" + testBlobHashA[:2] + "/" + testBlobHashA[2:4] + "/" + testBlobHashA assert.False(t, env.store.hasKey(blobKey), "the unreferenced blob must be deleted") var result vaultik.PruneBlobsResult require.NoError(t, json.Unmarshal(env.stdout.Bytes(), &result), "stdout must hold only the JSON document, got:\n%s", env.stdout.String()) assert.Equal(t, 1, result.BlobsDeleted) }