mirror of
https://github.com/kopia/kopia.git
synced 2026-06-26 14:55:40 -04:00
* cli: added a flag to create repository with v2 index features * content: plumb through compression.ID parameter to content.Manager.WriteContent() * content: expose content.Manager.SupportsContentCompression This allows object manager to decide whether to create compressed object or let the content manager do it. * object: if compression is requested and the repo supports it, pass compression ID to the content manager * cli: show compression status in 'repository status' * cli: output compression information in 'content list' and 'content stats' * content: compression and decompression support * content: unit tests for compression * object: compression tests * testing: added integration tests against v2 index * testing: run all e2e tests with and without content-level compression * htmlui: added UI for specifying index format on creation * cli: additional tests for 'content ls' and 'content stats' * applied pr suggestions
99 lines
2.4 KiB
Go
99 lines
2.4 KiB
Go
package endtoend_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"reflect"
|
|
"strings"
|
|
"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 TestCompression(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)
|
|
|
|
// set global policy
|
|
e.RunAndExpectSuccess(t, "policy", "set", "--global", "--compression", "pgzip")
|
|
|
|
dataDir := testutil.TempDirectory(t)
|
|
|
|
dataLines := []string{
|
|
"hello world",
|
|
"how are you",
|
|
"hello world",
|
|
"how are you",
|
|
"hello world",
|
|
"how are you",
|
|
"hello world",
|
|
"how are you",
|
|
"hello world",
|
|
"how are you",
|
|
"hello world",
|
|
"how are you",
|
|
"hello world",
|
|
"how are you",
|
|
"hello world",
|
|
"how are you",
|
|
}
|
|
|
|
// add a file that compresses well
|
|
require.NoError(t, ioutil.WriteFile(filepath.Join(dataDir, "some-file1"), []byte(strings.Join(dataLines, "\n")), 0o600))
|
|
|
|
e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
|
|
sources := clitestutil.ListSnapshotsAndExpectSuccess(t, e)
|
|
oid := sources[0].Snapshots[0].ObjectID
|
|
entries := clitestutil.ListDirectory(t, e, oid)
|
|
|
|
supportsContentLevelCompression := containsLineStartingWith(
|
|
e.RunAndExpectSuccess(t, "repo", "status"),
|
|
"Content compression: true",
|
|
)
|
|
|
|
// without content-level compression, we'll do it at object level and object ID will be prefixed with 'Z'
|
|
if !supportsContentLevelCompression {
|
|
if !strings.HasPrefix(entries[0].ObjectID, "Z") {
|
|
t.Errorf("expected compressed object, got %v", entries[0].ObjectID)
|
|
}
|
|
} else {
|
|
// with content-level compression we're looking for a content with compression.
|
|
lines := e.RunAndExpectSuccess(t, "content", "ls", "-c")
|
|
found := false
|
|
|
|
for _, l := range lines {
|
|
if strings.HasPrefix(l, entries[0].ObjectID) {
|
|
require.Contains(t, l, "pgzip")
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
require.True(t, found)
|
|
}
|
|
|
|
if lines := e.RunAndExpectSuccess(t, "show", entries[0].ObjectID); !reflect.DeepEqual(dataLines, lines) {
|
|
t.Errorf("invalid object contents")
|
|
}
|
|
}
|
|
|
|
func containsLineStartingWith(lines []string, prefix string) bool {
|
|
for _, l := range lines {
|
|
if strings.HasPrefix(l, prefix) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|