Sync branch magefile with main #104308

Merged
Sybren A. Stüvel merged 85 commits from abelli/flamenco:magefile into magefile 2024-05-13 16:26:32 +02:00
Showing only changes of commit b313a2020d - Show all commits

View File

@ -3,6 +3,7 @@ package persistence
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
import ( import (
"slices"
"testing" "testing"
"time" "time"
@ -50,17 +51,7 @@ func TestFetchDeleteTags(t *testing.T) {
} }
require.NoError(t, f.db.CreateWorkerTag(f.ctx, &secondTag)) require.NoError(t, f.db.CreateWorkerTag(f.ctx, &secondTag))
assertTagsMatch(t, f, f.tag.UUID, secondTag.UUID)
allTags, err := f.db.FetchWorkerTags(f.ctx)
require.NoError(t, err)
require.Len(t, allTags, 2)
var allTagIDs [2]string
for idx := range allTags {
allTagIDs[idx] = allTags[idx].UUID
}
assert.Contains(t, allTagIDs, f.tag.UUID)
assert.Contains(t, allTagIDs, secondTag.UUID)
has, err = f.db.HasWorkerTags(f.ctx) has, err = f.db.HasWorkerTags(f.ctx)
require.NoError(t, err) require.NoError(t, err)
@ -68,11 +59,7 @@ func TestFetchDeleteTags(t *testing.T) {
// Test deleting the 2nd tag. // Test deleting the 2nd tag.
require.NoError(t, f.db.DeleteWorkerTag(f.ctx, secondTag.UUID)) require.NoError(t, f.db.DeleteWorkerTag(f.ctx, secondTag.UUID))
assertTagsMatch(t, f, f.tag.UUID)
allTags, err = f.db.FetchWorkerTags(f.ctx)
require.NoError(t, err)
require.Len(t, allTags, 1)
assert.Equal(t, f.tag.UUID, allTags[0].UUID)
// Test deleting the 1st tag. // Test deleting the 1st tag.
require.NoError(t, f.db.DeleteWorkerTag(f.ctx, f.tag.UUID)) require.NoError(t, f.db.DeleteWorkerTag(f.ctx, f.tag.UUID))
@ -163,3 +150,19 @@ func TestDeleteWorkerTagWithWorkersAssigned(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Empty(t, w.Tags) assert.Empty(t, w.Tags)
} }
func assertTagsMatch(t *testing.T, f WorkerTestFixture, expectUUIDs ...string) {
allTags, err := f.db.FetchWorkerTags(f.ctx)
require.NoError(t, err)
require.Len(t, allTags, len(expectUUIDs))
var actualUUIDs []string
for idx := range allTags {
actualUUIDs = append(actualUUIDs, allTags[idx].UUID)
}
slices.Sort(expectUUIDs)
slices.Sort(actualUUIDs)
assert.Equal(t, actualUUIDs, expectUUIDs)
}