diff options
| author | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-07-14 11:43:24 -0700 |
|---|---|---|
| committer | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-07-14 12:03:59 -0700 |
| commit | 7ee5d16c1d4da0561976b372da15bd2d7a32d8b8 (patch) | |
| tree | 6f8dcc9ed795e7b5827fae85af015dcbe65fe999 /crypto/crypto_test.go | |
| parent | 419fd9f24c2805c75a84da1cb52516de25dcecdd (diff) | |
crypto: Use single description parameter
Instead of using the service+descriptor parameters (which are always
combined in the same way), use a single description parameter.
Diffstat (limited to 'crypto/crypto_test.go')
| -rw-r--r-- | crypto/crypto_test.go | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index 8b63457..5655fef 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -237,27 +237,36 @@ func TestKeyLargeResize(t *testing.T) { // Adds and removes a key with various services. func TestAddRemoveKeys(t *testing.T) { for _, service := range []string{DefaultService, "ext4:", "f2fs:"} { - if err := InsertPolicyKey(fakeValidPolicyKey, fakeValidDescriptor, service); err != nil { + validDescription := service + fakeValidDescriptor + if err := InsertPolicyKey(fakeValidPolicyKey, validDescription); err != nil { t.Error(err) } - if err := RemovePolicyKey(fakeValidDescriptor, service); err != nil { + if err := RemovePolicyKey(validDescription); err != nil { t.Error(err) } } } -// Makes sure a key fails with bad descriptor, policy, or service +// Adds a key twice (both should succeed) +func TestAddTwice(t *testing.T) { + validDescription := DefaultService + fakeValidDescriptor + InsertPolicyKey(fakeValidPolicyKey, validDescription) + if InsertPolicyKey(fakeValidPolicyKey, validDescription) != nil { + t.Error("InsertPolicyKey should not fail if key already exists") + } + RemovePolicyKey(validDescription) +} + +// Makes sure a key fails with bad policy or service func TestBadAddKeys(t *testing.T) { - if InsertPolicyKey(fakeInvalidPolicyKey, fakeValidDescriptor, DefaultService) == nil { - RemovePolicyKey(fakeValidDescriptor, DefaultService) + validDescription := DefaultService + fakeValidDescriptor + if InsertPolicyKey(fakeInvalidPolicyKey, validDescription) == nil { + RemovePolicyKey(validDescription) t.Error("InsertPolicyKey should fail with bad policy key") } - if InsertPolicyKey(fakeValidPolicyKey, fakeInvalidDescriptor, DefaultService) == nil { - RemovePolicyKey(fakeInvalidDescriptor, DefaultService) - t.Error("InsertPolicyKey should fail with bad descriptor") - } - if InsertPolicyKey(fakeValidPolicyKey, fakeValidDescriptor, "ext4") == nil { - RemovePolicyKey(fakeValidDescriptor, "ext4") + invalidDescription := "ext4" + fakeValidDescriptor + if InsertPolicyKey(fakeValidPolicyKey, invalidDescription) == nil { + RemovePolicyKey(invalidDescription) t.Error("InsertPolicyKey should fail with bad service") } } |