From d7f5094702a11886d92c1e9a4e085fd07e0efa5d Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 16 Mar 2021 17:12:15 -0400 Subject: [PATCH] state: add indexer tests for acl-roles table --- agent/consul/state/acl_oss_test.go | 46 ++++++++++++++++++++++++++++++ agent/consul/state/schema_test.go | 1 + 2 files changed, 47 insertions(+) diff --git a/agent/consul/state/acl_oss_test.go b/agent/consul/state/acl_oss_test.go index fab7197819..6d4b094177 100644 --- a/agent/consul/state/acl_oss_test.go +++ b/agent/consul/state/acl_oss_test.go @@ -33,3 +33,49 @@ func testIndexerTableACLPolicies() map[string]indexerTestCase { }, } } + +func testIndexerTableACLRoles() map[string]indexerTestCase { + obj := &structs.ACLRole{ + ID: "123e4567-e89a-12d7-a456-426614174abc", + Name: "RoLe", + Policies: []structs.ACLRolePolicyLink{ + {ID: "PolicyId1"}, {ID: "PolicyId2"}, + }, + } + encodedID := []byte{0x12, 0x3e, 0x45, 0x67, 0xe8, 0x9a, 0x12, 0xd7, 0xa4, 0x56, 0x42, 0x66, 0x14, 0x17, 0x4a, 0xbc} + return map[string]indexerTestCase{ + indexID: { + read: indexValue{ + source: obj.ID, + expected: encodedID, + }, + write: indexValue{ + source: obj, + expected: encodedID, + }, + }, + indexName: { + read: indexValue{ + source: "RoLe", + expected: []byte("role\x00"), + }, + write: indexValue{ + source: obj, + expected: []byte("role\x00"), + }, + }, + indexPolicies: { + read: indexValue{ + source: "PolicyId1", + expected: []byte("PolicyId1\x00"), + }, + writeMulti: indexValueMulti{ + source: obj, + expected: [][]byte{ + []byte("PolicyId1\x00"), + []byte("PolicyId2\x00"), + }, + }, + }, + } +} diff --git a/agent/consul/state/schema_test.go b/agent/consul/state/schema_test.go index 0992ded938..366647791e 100644 --- a/agent/consul/state/schema_test.go +++ b/agent/consul/state/schema_test.go @@ -129,6 +129,7 @@ func TestNewDBSchema_Indexers(t *testing.T) { var testcases = map[string]func() map[string]indexerTestCase{ tableACLPolicies: testIndexerTableACLPolicies, + tableACLRoles: testIndexerTableACLRoles, tableChecks: testIndexerTableChecks, tableServices: testIndexerTableServices, tableNodes: testIndexerTableNodes,