From defd27f75df3a6eef84ac33adf89b1ce255e738c Mon Sep 17 00:00:00 2001 From: "Joe Richey joerichey@google.com" Date: Wed, 31 May 2017 17:54:35 -0700 Subject: actions: Simplify the callback mechanism This commit makes the callbacks for getting keys easier to understand. Functions which need keys now take a KeyFunc callback. This callback contains a ProtectorInfo parameter (basically a read-only version of metadata.ProtectorData) and a boolean which indicates if the call is being retried. The documentation is also updated to say which functions will retry the KeyFunc. For selecting a protector, there is now an OptionFunc callback which takes a slice of ProtectorOptions. A ProtectorOption is a ProtectorInfo along with additional information about a linked filesystem (if applicable). This commit also adds in methods for getting the protector options for a specific filesystem or policy. It also adds a function for getting the policy descriptor for a specific path. Change-Id: I41e0d94ffd44e7166b0c5cf1b5d18437960bdf90 --- actions/policy_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'actions/policy_test.go') diff --git a/actions/policy_test.go b/actions/policy_test.go index 3a64e01..07a7f87 100644 --- a/actions/policy_test.go +++ b/actions/policy_test.go @@ -27,11 +27,11 @@ func makeAll() (ctx *Context, protector *Protector, policy *Policy, err error) { if err != nil { return } - protector, err = ctx.NewProtector(testProtectorName, goodCallback) + protector, err = CreateProtector(ctx, testProtectorName, goodCallback) if err != nil { return } - policy, err = ctx.NewPolicy(protector) + policy, err = CreatePolicy(ctx, protector) return } @@ -47,7 +47,7 @@ func cleanupAll(protector *Protector, policy *Policy) { } // Tests that we can make a policy/protector pair -func TestNewPolicy(t *testing.T) { +func TestCreatePolicy(t *testing.T) { _, pro, pol, err := makeAll() defer cleanupAll(pro, pol) if err != nil { @@ -63,7 +63,7 @@ func TestPolicyGoodAddProtector(t *testing.T) { t.Fatal(err) } - pro2, err := ctx.NewProtector(testProtectorName2, goodCallback) + pro2, err := CreateProtector(ctx, testProtectorName2, goodCallback) if err != nil { t.Fatal(err) } @@ -96,7 +96,7 @@ func TestPolicyGoodRemoveProtector(t *testing.T) { t.Fatal(err) } - pro2, err := ctx.NewProtector(testProtectorName2, goodCallback) + pro2, err := CreateProtector(ctx, testProtectorName2, goodCallback) if err != nil { t.Fatal(err) } @@ -107,7 +107,7 @@ func TestPolicyGoodRemoveProtector(t *testing.T) { t.Fatal(err) } - err = pol.RemoveProtector(pro1) + err = pol.RemoveProtector(pro1.data.ProtectorDescriptor) if err != nil { t.Error(err) } @@ -121,17 +121,17 @@ func TestPolicyBadRemoveProtector(t *testing.T) { t.Fatal(err) } - pro2, err := ctx.NewProtector(testProtectorName2, goodCallback) + pro2, err := CreateProtector(ctx, testProtectorName2, goodCallback) if err != nil { t.Fatal(err) } defer pro2.Wipe() - if pol.RemoveProtector(pro2) == nil { + if pol.RemoveProtector(pro2.data.ProtectorDescriptor) == nil { t.Error("we should not be able to remove a protector we did not add") } - if pol.RemoveProtector(pro1) == nil { + if pol.RemoveProtector(pro1.data.ProtectorDescriptor) == nil { t.Error("we should not be able to remove all the protectors from a policy") } } -- cgit v1.2.3