Skip to content

Commit 8c86374

Browse files
authored
Merge pull request #4703 from kersten/chore/store-tests-init-vars
🌱 (chore): refactor unit tests to isolate mutable state with BeforeEach for pkg/config/store
2 parents 17fab17 + 44b85bc commit 8c86374

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pkg/config/store/errors_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ func TestConfigStore(t *testing.T) {
3131

3232
var _ = Describe("LoadError", func() {
3333
var (
34-
wrapped = fmt.Errorf("error message")
35-
err = LoadError{Err: wrapped}
34+
wrapped error
35+
err LoadError
3636
)
3737

38+
BeforeEach(func() {
39+
wrapped = fmt.Errorf("error message")
40+
err = LoadError{Err: wrapped}
41+
})
42+
3843
Context("Error", func() {
3944
It("should return the correct error message", func() {
4045
Expect(err.Error()).To(Equal(fmt.Sprintf("unable to load the configuration: %v", wrapped)))
@@ -50,10 +55,15 @@ var _ = Describe("LoadError", func() {
5055

5156
var _ = Describe("SaveError", func() {
5257
var (
53-
wrapped = fmt.Errorf("error message")
54-
err = SaveError{Err: wrapped}
58+
wrapped error
59+
err SaveError
5560
)
5661

62+
BeforeEach(func() {
63+
wrapped = fmt.Errorf("error message")
64+
err = SaveError{Err: wrapped}
65+
})
66+
5767
Context("Error", func() {
5868
It("should return the correct error message", func() {
5969
Expect(err.Error()).To(Equal(fmt.Sprintf("unable to save the configuration: %v", wrapped)))

pkg/config/store/yaml/store_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ layout: ""
6262
)
6363

6464
var (
65-
s *yamlStore
66-
67-
path = DefaultPath + "2"
65+
s *yamlStore
66+
path string
6867
)
6968

7069
BeforeEach(func() {
7170
s = New(machinery.Filesystem{FS: afero.NewMemMapFs()}).(*yamlStore)
71+
path = DefaultPath + "2"
7272
})
7373

7474
Context("New", func() {

0 commit comments

Comments
 (0)