Skip to content

Commit

Permalink
🐛 Fix data race when testing config parsing
Browse files Browse the repository at this point in the history
There was a data race issue when parallel tests were being run. This
was caused by a global variable which was used to assert the error type
to match the returned error.

Refactoring allowed for the removal of the global variable.
  • Loading branch information
mikelorant committed Feb 6, 2023
1 parent 20901bf commit 983288a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"gopkg.in/yaml.v3"
)

var typeError *yaml.TypeError

func TestConfig(t *testing.T) {
t.Parallel()

Expand All @@ -29,7 +27,7 @@ func TestConfig(t *testing.T) {
{
name: "invalid",
data: "invalid",
err: typeError,
err: new(yaml.TypeError),
},
{
name: "focus_empty",
Expand Down Expand Up @@ -195,7 +193,7 @@ func TestConfig(t *testing.T) {
name: "signoff_invalid",
data: "commit: {signoff: invalid}",
config: config.Config{Commit: config.Commit{Signoff: false}},
err: typeError,
err: new(yaml.TypeError),
},
{
name: "theme_empty",
Expand Down Expand Up @@ -392,7 +390,7 @@ func TestConfig(t *testing.T) {
{Name: "John Doe", Email: "[email protected]"},
},
},
err: typeError,
err: new(yaml.TypeError),
},
}

Expand All @@ -405,7 +403,10 @@ func TestConfig(t *testing.T) {
cfg, err := new(config.Config).Load(strings.NewReader(tt.data))
if tt.err != nil {
assert.NotNil(t, err)

var typeError *yaml.TypeError
assert.ErrorAs(t, err, &typeError)

return
}
assert.Nil(t, err)
Expand Down

0 comments on commit 983288a

Please sign in to comment.