Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit42d625e

Browse files
mirkoCrobumirkoCrobu
mirkoCrobu
authored and
mirkoCrobu
committed
refactoring store_test
1 parent7cb0eb0 commit42d625e

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
brickIDstring
1918
wantContentstring
2019
wantErrbool
21-
wantErrIserror
2220
wantErrMsgstring
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
iftc.wantErr {
5048
require.Error(t,err,"should have returned an error")
51-
iftc.wantErrIs!=nil {
52-
require.ErrorIs(t,err,tc.wantErrIs,"error type mismatch")
53-
}
5449
iftc.wantErrMsg!="" {
5550
require.EqualError(t,err,tc.wantErrMsg,"error message mismatch")
5651
}
@@ -105,47 +100,42 @@ func TestGetBrickComposeFilePathFromID(t *testing.T) {
105100

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

110104
testCases:= []struct {
111105
namestring
112106
brickIDstring
113-
wantNilListbool
114107
wantEntryCountint
115-
wantErrbool
116-
wantErrMsgstring
108+
wantErrstring
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:=rangetestCases {
140130
t.Run(tc.name,func(t*testing.T) {
141131
pathList,err:=store.GetBrickCodeExamplesPathFromID(tc.brickID)
142-
iftc.wantErr {
132+
iftc.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-
iftc.wantNilList {
138+
iftc.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)

[8]ページ先頭

©2009-2025 Movatter.jp