mirror of
https://github.com/kopia/kopia.git
synced 2026-03-31 04:25:50 -04:00
refactored test helpers to separate package made all tests parallel and improved the code structure
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package endtoend_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/kopia/kopia/tests/testenv"
|
|
)
|
|
|
|
func TestDiff(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
e := testenv.NewCLITest(t)
|
|
defer e.Cleanup(t)
|
|
defer e.RunAndExpectSuccess(t, "repo", "disconnect")
|
|
|
|
e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
|
|
|
|
dataDir := makeScratchDir(t)
|
|
|
|
// initial snapshot
|
|
testenv.AssertNoError(t, os.MkdirAll(dataDir, 0777))
|
|
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
|
|
|
|
// create some directories and files
|
|
testenv.AssertNoError(t, os.MkdirAll(filepath.Join(dataDir, "foo"), 0700))
|
|
testenv.AssertNoError(t, ioutil.WriteFile(filepath.Join(dataDir, "some-file1"), []byte(`
|
|
hello world
|
|
how are you
|
|
`), 0600))
|
|
testenv.AssertNoError(t, ioutil.WriteFile(filepath.Join(dataDir, "some-file2"), []byte(`
|
|
quick brown
|
|
fox jumps
|
|
over the lazy
|
|
dog
|
|
`), 0600))
|
|
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
|
|
|
|
// change some files
|
|
testenv.AssertNoError(t, ioutil.WriteFile(filepath.Join(dataDir, "some-file2"), []byte(`
|
|
quick brown
|
|
fox jumps
|
|
over the lazy
|
|
canary
|
|
`), 0600))
|
|
|
|
testenv.AssertNoError(t, os.MkdirAll(filepath.Join(dataDir, "bar"), 0700))
|
|
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
|
|
|
|
// change some files
|
|
os.Remove(filepath.Join(dataDir, "some-file1"))
|
|
|
|
testenv.AssertNoError(t, os.MkdirAll(filepath.Join(dataDir, "bar"), 0700))
|
|
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
|
|
|
|
si := e.ListSnapshotsAndExpectSuccess(t, 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)
|
|
}
|
|
}
|
|
}
|