-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix data race when testing config parsing
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
1 parent
20901bf
commit 983288a
Showing
1 changed file
with
6 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ import ( | |
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var typeError *yaml.TypeError | ||
|
||
func TestConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
@@ -29,7 +27,7 @@ func TestConfig(t *testing.T) { | |
{ | ||
name: "invalid", | ||
data: "invalid", | ||
err: typeError, | ||
err: new(yaml.TypeError), | ||
}, | ||
{ | ||
name: "focus_empty", | ||
|
@@ -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", | ||
|
@@ -392,7 +390,7 @@ func TestConfig(t *testing.T) { | |
{Name: "John Doe", Email: "[email protected]"}, | ||
}, | ||
}, | ||
err: typeError, | ||
err: new(yaml.TypeError), | ||
}, | ||
} | ||
|
||
|
@@ -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) | ||
|