From 704acceea6bc03021e379513b4fe4622a73f41fe Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Tue, 6 Dec 2022 15:15:29 +0100 Subject: [PATCH] acl: sso auth method snapshot restore test (#15482) --- nomad/fsm_test.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/nomad/fsm_test.go b/nomad/fsm_test.go index 1bcc72695..8013ea4ce 100644 --- a/nomad/fsm_test.go +++ b/nomad/fsm_test.go @@ -13,7 +13,7 @@ import ( memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/raft" "github.com/kr/pretty" - "github.com/shoenig/test/must" + "github.com/shoenig/test/must" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -2682,6 +2682,33 @@ func TestFSM_SnapshotRestore_ACLRoles(t *testing.T) { require.ElementsMatch(t, restoredACLRoles, aclRoles) } +func TestFSM_SnapshotRestore_ACLAuthMethods(t *testing.T) { + ci.Parallel(t) + + // Create our initial FSM which will be snapshotted. + fsm := testFSM(t) + testState := fsm.State() + + // Generate and upsert some ACL auth methods. + authMethods := []*structs.ACLAuthMethod{mock.ACLAuthMethod(), mock.ACLAuthMethod()} + must.NoError(t, testState.UpsertACLAuthMethods(10, authMethods)) + + // Perform a snapshot restore. + restoredFSM := testSnapshotRestore(t, fsm) + restoredState := restoredFSM.State() + + // List the ACL auth methods from restored state and ensure everything is as + // expected. + iter, err := restoredState.GetACLAuthMethods(memdb.NewWatchSet()) + must.NoError(t, err) + + var restoredACLAuthMethods []*structs.ACLAuthMethod + for raw := iter.Next(); raw != nil; raw = iter.Next() { + restoredACLAuthMethods = append(restoredACLAuthMethods, raw.(*structs.ACLAuthMethod)) + } + must.SliceContainsAll(t, restoredACLAuthMethods, authMethods) +} + func TestFSM_ReconcileSummaries(t *testing.T) { ci.Parallel(t) // Add some state