[v11.1.x] Fix: Ensure SA migrations doesn't hit migrated SAs if rerun (#94398)

Fix: Ensure SA migrations doesn't hit migrated SAs if rerun (#94347)

* ensure mig doesn't hit migrated SAs if rerun

* Fix small issue with the test

---------

Co-authored-by: gamab <gabriel.mabille@grafana.com>
(cherry picked from commit 945dd052b1)

Co-authored-by: Jo <joao.guerreiro@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-10-10 11:35:41 +02:00
committed by GitHub
co-authored by Jo
parent df4c5f46f8
commit 7ece6b35f0
2 changed files with 74 additions and 24 deletions
@@ -15,6 +15,9 @@ import (
)
func TestIntegrationServiceAccountMigration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}
// Run initial migration to have a working DB
x := setupTestDB(t)
@@ -211,6 +214,43 @@ func TestIntegrationServiceAccountMigration(t *testing.T) {
},
},
},
{
desc: "avoid reapply of migration",
serviceAccounts: []*user.User{
{
ID: 11,
UID: "u11",
Name: "sa-1-extsvc-bug",
Login: "sa-1-extsvc-bug",
Email: "sa-1-extsvc-bug@org.com",
OrgID: 1,
Created: now,
Updated: now,
IsServiceAccount: true,
},
{
ID: 12,
UID: "u12",
Name: "sa-2-extsvc-bug2",
Login: "sa-2-extsvc-bug2",
Email: "sa-2-extsvc-bug2@org.com",
OrgID: 2,
Created: now,
Updated: now,
IsServiceAccount: true,
},
},
wantServiceAccounts: []*user.User{
{
ID: 11,
Login: "sa-1-extsvc-bug",
},
{
ID: 12,
Login: "sa-2-extsvc-bug2",
},
},
},
}
for _, tc := range testCases {