Files
kopia/tests/end_to_end_test/diff_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

75 lines
2.0 KiB
Go

package endtoend_test
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/kopia/kopia/internal/testutil"
"github.com/kopia/kopia/tests/clitestutil"
"github.com/kopia/kopia/tests/testenv"
)
func TestDiff(t *testing.T) {
t.Parallel()
runner := testenv.NewInProcRunner(t)
e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
defer e.RunAndExpectSuccess(t, "repo", "disconnect")
e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
dataDir := testutil.TempDirectory(t)
// initial snapshot
require.NoError(t, os.MkdirAll(dataDir, 0o777))
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
// create some directories and files
require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "foo"), 0o700))
require.NoError(t, os.WriteFile(filepath.Join(dataDir, "some-file1"), []byte(`
hello world
how are you
`), 0o600))
require.NoError(t, os.WriteFile(filepath.Join(dataDir, "some-file2"), []byte(`
quick brown
fox jumps
over the lazy
dog
`), 0o600))
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
// change some files
require.NoError(t, os.WriteFile(filepath.Join(dataDir, "some-file2"), []byte(`
quick brown
fox jumps
over the lazy
canary
`), 0o600))
require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "bar"), 0o700))
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
// change some files
os.Remove(filepath.Join(dataDir, "some-file1"))
require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "bar"), 0o700))
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
si := clitestutil.ListSnapshotsAndExpectSuccess(t, e, dataDir)
if got, want := len(si), 1; got != want {
t.Fatalf("got %v sources, wanted %v", got, want)
}
// make sure we can generate between all versions of the directory
snapshots := si[0].Snapshots
for _, s1 := range snapshots {
for _, s2 := range snapshots {
e.RunAndExpectSuccess(t, "diff", "-f", s1.ObjectID, s2.ObjectID)
}
}
}