Skip to content

Commit 42d625e

Browse files
mirkoCrobumirkoCrobu
authored andcommitted
refactoring store_test
1 parent 7cb0eb0 commit 42d625e

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

internal/store/store_test.go

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package store
22

33
import (
4-
"os"
54
"testing"
65

76
"github.com/arduino/go-paths-helper"
@@ -18,7 +17,6 @@ func TestGetBrickReadmeFromID(t *testing.T) {
1817
brickID string
1918
wantContent string
2019
wantErr bool
21-
wantErrIs error
2220
wantErrMsg string
2321
}{
2422
{
@@ -32,7 +30,7 @@ func TestGetBrickReadmeFromID(t *testing.T) {
3230
brickID: "namespace:non_existent_brick",
3331
wantContent: "",
3432
wantErr: true,
35-
wantErrIs: os.ErrNotExist,
33+
wantErrMsg: "open testdata/assets/0.4.8/docs/namespace/non_existent_brick/README.md: no such file or directory",
3634
},
3735
{
3836
name: "Failure - invalid ID",
@@ -48,9 +46,6 @@ func TestGetBrickReadmeFromID(t *testing.T) {
4846
content, err := store.GetBrickReadmeFromID(tc.brickID)
4947
if tc.wantErr {
5048
require.Error(t, err, "should have returned an error")
51-
if tc.wantErrIs != nil {
52-
require.ErrorIs(t, err, tc.wantErrIs, "error type mismatch")
53-
}
5449
if tc.wantErrMsg != "" {
5550
require.EqualError(t, err, tc.wantErrMsg, "error message mismatch")
5651
}
@@ -105,47 +100,42 @@ func TestGetBrickComposeFilePathFromID(t *testing.T) {
105100

106101
func TestGetBrickCodeExamplesPathFromID(t *testing.T) {
107102
store := NewStaticStore(paths.New("testdata", "assets", "0.4.8").String())
108-
const expectedEntryCount = 2
109103

110104
testCases := []struct {
111105
name string
112106
brickID string
113-
wantNilList bool
114107
wantEntryCount int
115-
wantErr bool
116-
wantErrMsg string
108+
wantErr string
117109
}{
118110
{
119111
name: "Success - directory found",
120112
brickID: validBrickID,
121-
wantNilList: false,
122-
wantEntryCount: expectedEntryCount,
123-
wantErr: false,
113+
wantEntryCount: 2,
114+
wantErr: "",
124115
},
125116
{
126-
name: "Success - directory not found",
127-
brickID: "namespace:non_existent_brick",
128-
wantNilList: true,
129-
wantErr: false,
117+
name: "Success - directory not found",
118+
brickID: "namespace:non_existent_brick",
119+
wantEntryCount: 0,
120+
wantErr: "",
130121
},
131122
{
132-
name: "Failure - invalid ID",
133-
brickID: "invalid-id",
134-
wantNilList: true,
135-
wantErr: true,
136-
wantErrMsg: "invalid ID",
123+
name: "Failure - invalid ID",
124+
brickID: "invalid-id",
125+
wantEntryCount: 0,
126+
wantErr: "invalid ID",
137127
},
138128
}
139129
for _, tc := range testCases {
140130
t.Run(tc.name, func(t *testing.T) {
141131
pathList, err := store.GetBrickCodeExamplesPathFromID(tc.brickID)
142-
if tc.wantErr {
132+
if tc.wantErr != "" {
143133
require.Error(t, err, "should have returned an error")
144-
require.EqualError(t, err, tc.wantErrMsg, "error message mismatch")
134+
require.EqualError(t, err, tc.wantErr, "error message mismatch")
145135
} else {
146136
require.NoError(t, err, "should not have returned an error")
147137
}
148-
if tc.wantNilList {
138+
if tc.wantEntryCount == 0 {
149139
require.Nil(t, pathList, "pathList should be nil")
150140
} else {
151141
require.NotNil(t, pathList, "pathList should not be nil")

0 commit comments

Comments
 (0)