Files
kopia/tests/end_to_end_test/policy_test.go
Jarek Kowalski b55d5b474c refactor(repository): refactored internal index read API to reduce memory allocations (#3754)
* refactor(repository): refactored internal index read API to reduce memory allocations

* fixed stress test flake, improved debuggability

* fixed spurious checklocks failures

* post-merge fixes

* pr feedback
2024-04-12 22:59:11 -07:00

55 lines
1.7 KiB
Go

package endtoend_test
import (
"testing"
"github.com/kopia/kopia/internal/testutil"
"github.com/kopia/kopia/repo/content"
"github.com/kopia/kopia/repo/manifest"
"github.com/kopia/kopia/snapshot/policy"
"github.com/kopia/kopia/tests/testenv"
)
func TestDefaultGlobalPolicy(t *testing.T) {
t.Parallel()
runner := testenv.NewInProcRunner(t)
e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
// make sure we can read policy
e.RunAndExpectSuccess(t, "policy", "show", "--global")
// verify we created global policy entry
var contents []content.Info
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "content", "ls", "--json"), &contents)
if got, want := len(contents), 1; got != want {
t.Fatalf("unexpected number of contents %v, want %v", got, want)
}
globalPolicyContentID := contents[0].ContentID
e.RunAndExpectSuccess(t, "content", "show", "-jz", globalPolicyContentID.String())
// make sure the policy is visible in the manifest list
var manifests []manifest.EntryMetadata
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "manifest", "list", "--filter=type:policy", "--filter=policyType:global", "--json"), &manifests)
if got, want := len(manifests), 1; got != want {
t.Fatalf("unexpected number of manifests %v, want %v", got, want)
}
// make sure the policy is visible in the policy list
var plist []policy.TargetWithPolicy
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "list", "--json"), &plist)
if got, want := len(plist), 1; got != want {
t.Fatalf("unexpected number of policies %v, want %v", got, want)
}
}