Files
kopia/cli/command_content_verify_test.go
Eng Zer Jun 73e492c9db refactor: move from io/ioutil to io and os package (#1360)
* refactor: move from io/ioutil to io and os package

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* chore: remove //nolint:gosec for os.ReadFile

At the time of this commit, the G304 rule of gosec does not include the
`os.ReadFile` function. We remove `//nolint:gosec` temporarily until
https://github.com/securego/gosec/pull/706 is merged.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-10-06 08:39:10 -07:00

41 lines
1.3 KiB
Go

package cli_test
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/kopia/kopia/internal/testutil"
"github.com/kopia/kopia/tests/testenv"
)
func (s *formatSpecificTestSuite) TestContentVerify(t *testing.T) {
env := testenv.NewCLITest(t, s.formatFlags, testenv.NewInProcRunner(t))
dir := testutil.TempDirectory(t)
require.NoError(t, os.WriteFile(filepath.Join(dir, "file1.txt"), bytes.Repeat([]byte{1, 2, 3, 4, 5}, 15000), 0o600))
env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", env.RepoDir)
env.RunAndExpectSuccess(t, "content", "verify")
env.RunAndExpectSuccess(t, "snapshot", "create", dir)
env.RunAndExpectSuccess(t, "content", "verify", "--download-percent=30")
// delete one of 'p' blobs.
blobIDToDelete := strings.Split(env.RunAndExpectSuccess(t, "blob", "list", "--prefix=p")[0], " ")[0]
blobList := env.RunAndExpectSuccess(t, "blob", "list")
t.Logf("blob list: %v", strings.Join(blobList, "\n"))
env.RunAndExpectSuccess(t, "blob", "delete", blobIDToDelete)
_, verifyStderr, err := env.Run(t, true, "content", "verify")
require.Error(t, err)
// this fails if not found
mustGetLineContaining(t, verifyStderr, "missing blob "+blobIDToDelete)
env.RunAndExpectFailure(t, "content", "verify", "--full")
}