mirror of
https://github.com/kopia/kopia.git
synced 2026-06-26 06:45:47 -04:00
* cli: fixed remaining testability indirections for output and logging * cli: added cli.RunSubcommand() which is used in testing to execute a subcommand in the same process * tests: refactored most e2e tests to invoke kopia subcommands in-process * Makefile: enable code coverage for cli/ and internal/ * testing: pass 'testing' tag to unit tests which uses much faster (insecure) password hashing scheme * Makefile: push coverage from PRs again * tests: disable buffer management to reduce memory usage on ARM * cli: fixed misaligned atomic field on ARMHF also temporarily fixed statup-time benign race condition when setting default on the timeZone variable, which is the last global variable.
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package endtoend_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"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, 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, ioutil.WriteFile(filepath.Join(dataDir, "some-file1"), []byte(`
|
|
hello world
|
|
how are you
|
|
`), 0o600))
|
|
require.NoError(t, ioutil.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, ioutil.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)
|
|
}
|
|
}
|
|
}
|