Skip to content

Commit

Permalink
store: Fix test for CheckGPG
Browse files Browse the repository at this point in the history
Forgot the #1 rule of map iteration. Don't depend on the order.
This uses a slice instead, which should be just as good for testing the
loop variable alias behavior.

(cherry picked from commit 8e933f8)
  • Loading branch information
bcl authored and achilleas-k committed Nov 17, 2023
1 parent ec4cefc commit 1ecfc21
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions internal/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,16 @@ func (suite *storeTest) TestRepoConfigMirrorlist() {
// Test multiple SourceConfigs with different CheckGPG and CheckRepoGPG settings
func (suite *storeTest) TestSourceConfigGPGKeysTrueFalse() {
// We only care about the GPG bools
sources := map[string]SourceConfig{
"source-with-true": {Name: "source-with-true", CheckGPG: true, CheckRepoGPG: true},
"source-with-false": {Name: "source-with-false", CheckGPG: false, CheckRepoGPG: false},
sources := []SourceConfig{
{Name: "source-with-true", CheckGPG: true, CheckRepoGPG: true},
{Name: "source-with-false", CheckGPG: false, CheckRepoGPG: false},
}

// source is reused inside the loop, which can result in unexpected changes in go < 1.22
// https://go.dev/blog/loopvar-preview
var repos []rpmmd.RepoConfig
for id, source := range sources {
repos = append(repos, source.RepoConfig(id))
for _, source := range sources {
repos = append(repos, source.RepoConfig(source.Name))
}

// First repo should be true, second should be false
Expand All @@ -512,14 +512,14 @@ func (suite *storeTest) TestSourceConfigGPGKeysTrueFalse() {

// We only care about the GPG bools
// Test with false then true
sources = map[string]SourceConfig{
"source-with-false": {Name: "source-with-false", CheckGPG: false, CheckRepoGPG: false},
"source-with-true": {Name: "source-with-true", CheckGPG: true, CheckRepoGPG: true},
sources = []SourceConfig{
{Name: "source-with-false", CheckGPG: false, CheckRepoGPG: false},
{Name: "source-with-true", CheckGPG: true, CheckRepoGPG: true},
}

repos = []rpmmd.RepoConfig{}
for id, source := range sources {
repos = append(repos, source.RepoConfig(id))
for _, source := range sources {
repos = append(repos, source.RepoConfig(source.Name))
}

// First repo should be false, second should be true
Expand Down

0 comments on commit 1ecfc21

Please sign in to comment.