MCPcopy
hub / github.com/kopia/kopia / TestExportPolicy

Function TestExportPolicy

cli/command_policy_export_test.go:16–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestExportPolicy(t *testing.T) {
17 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
18 defer e.RunAndExpectSuccess(t, "repo", "disconnect")
19
20 e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir, "--override-username=user", "--override-hostname=host")
21
22 // check if we get the default global policy
23 var policies1 map[string]*policy.Policy
24
25 testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export"), &policies1)
26
27 assert.Len(t, policies1, 1, "unexpected number of policies")
28 assert.Equal(t, policy.DefaultPolicy, policies1["(global)"], "unexpected policy")
29
30 var policies2 map[string]*policy.Policy
31
32 // we only have one policy, so exporting all policies should be the same as exporting the global policy explicitly
33 testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export", "(global)"), &policies2)
34
35 assert.Len(t, policies2, 1, "unexpected number of policies")
36 assert.Equal(t, policies1, policies2, "unexpected policy")
37
38 // create a new policy
39 td := testutil.TempDirectory(t)
40 id := snapshot.SourceInfo{
41 Host: "host",
42 UserName: "user",
43 Path: td,
44 }.String()
45
46 e.RunAndExpectSuccess(t, "policy", "set", td, "--splitter=FIXED-4M")
47
48 expectedPolicy := &policy.Policy{
49 SplitterPolicy: policy.SplitterPolicy{
50 Algorithm: "FIXED-4M",
51 },
52 }
53 expectedPolicies := map[string]*policy.Policy{
54 "(global)": policy.DefaultPolicy,
55 id: expectedPolicy,
56 }
57
58 // check if we get the new policy
59 var policies3 map[string]*policy.Policy
60
61 testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export", id), &policies3)
62
63 assert.Len(t, policies3, 1, "unexpected number of policies")
64 assert.Equal(t, expectedPolicy, policies3[id], "unexpected policy")
65
66 // specifying a local id should return the same policy
67 var policies4 map[string]*policy.Policy
68
69 testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export", td), &policies4) // note: td, not id
70
71 assert.Len(t, policies4, 1, "unexpected number of policies")
72 assert.Equal(t, expectedPolicy, policies4[id], "unexpected policy") // thee key is always the full id however
73

Callers

nothing calls this directly

Calls 10

RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95
NewCLITestFunction · 0.92
NewInProcRunnerFunction · 0.92
MustParseJSONLinesFunction · 0.92
TempDirectoryFunction · 0.92
EqualMethod · 0.80
FatalfMethod · 0.80
LenMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected