note: dependent on policy export working.
(t *testing.T)
| 17 | |
| 18 | // note: dependent on policy export working. |
| 19 | func TestImportPolicy(t *testing.T) { |
| 20 | e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t)) |
| 21 | defer e.RunAndExpectSuccess(t, "repo", "disconnect") |
| 22 | |
| 23 | e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir, "--override-username=user", "--override-hostname=host") |
| 24 | |
| 25 | td := testutil.TempDirectory(t) |
| 26 | policyFilePath := path.Join(td, "policy.json") |
| 27 | |
| 28 | // poor man's deep copy |
| 29 | defaultPolicyJSON, err := json.Marshal(policy.DefaultPolicy) |
| 30 | if err != nil { |
| 31 | t.Fatalf("unable to marshal policy: %v", err) |
| 32 | } |
| 33 | |
| 34 | var defaultPolicy *policy.Policy |
| 35 | |
| 36 | testutil.MustParseJSONLines(t, []string{string(defaultPolicyJSON)}, &defaultPolicy) |
| 37 | |
| 38 | specifiedPolicies := map[string]*policy.Policy{ |
| 39 | "(global)": defaultPolicy, |
| 40 | } |
| 41 | makePolicyFile := func() { |
| 42 | data, err := json.Marshal(specifiedPolicies) |
| 43 | if err != nil { |
| 44 | t.Fatalf("unable to marshal policy: %v", err) |
| 45 | } |
| 46 | |
| 47 | err = os.WriteFile(policyFilePath, data, 0o600) |
| 48 | if err != nil { |
| 49 | t.Fatalf("unable to write policy file: %v", err) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // sanity check that we have the default global policy |
| 54 | assertPoliciesEqual(t, e, specifiedPolicies) |
| 55 | |
| 56 | // change the global policy |
| 57 | specifiedPolicies["(global)"].SplitterPolicy.Algorithm = "FIXED-4M" |
| 58 | |
| 59 | makePolicyFile() |
| 60 | e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath) |
| 61 | assertPoliciesEqual(t, e, specifiedPolicies) |
| 62 | |
| 63 | // create a new policy |
| 64 | id := snapshot.SourceInfo{ |
| 65 | Host: "host", |
| 66 | UserName: "user", |
| 67 | Path: filepath.ToSlash(td), |
| 68 | }.String() |
| 69 | |
| 70 | specifiedPolicies[id] = &policy.Policy{ |
| 71 | SplitterPolicy: policy.SplitterPolicy{ |
| 72 | Algorithm: "FIXED-8M", |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | makePolicyFile() |
nothing calls this directly
no test coverage detected