11package store
22
33import (
4- "os"
54"testing"
65
76"github.com/arduino/go-paths-helper"
@@ -18,7 +17,6 @@ func TestGetBrickReadmeFromID(t *testing.T) {
1817brickID string
1918wantContent string
2019wantErr bool
21- wantErrIs error
2220wantErrMsg string
2321}{
2422{
@@ -32,7 +30,7 @@ func TestGetBrickReadmeFromID(t *testing.T) {
3230brickID :"namespace:non_existent_brick" ,
3331wantContent :"" ,
3432wantErr :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{
3836name :"Failure - invalid ID" ,
@@ -48,9 +46,6 @@ func TestGetBrickReadmeFromID(t *testing.T) {
4846content ,err := store .GetBrickReadmeFromID (tc .brickID )
4947if tc .wantErr {
5048require .Error (t ,err ,"should have returned an error" )
51- if tc .wantErrIs != nil {
52- require .ErrorIs (t ,err ,tc .wantErrIs ,"error type mismatch" )
53- }
5449if tc .wantErrMsg != "" {
5550require .EqualError (t ,err ,tc .wantErrMsg ,"error message mismatch" )
5651}
@@ -105,47 +100,42 @@ func TestGetBrickComposeFilePathFromID(t *testing.T) {
105100
106101func TestGetBrickCodeExamplesPathFromID (t * testing.T ) {
107102store := NewStaticStore (paths .New ("testdata" ,"assets" ,"0.4.8" ).String ())
108- const expectedEntryCount = 2
109103
110104testCases := []struct {
111105name string
112106brickID string
113- wantNilList bool
114107wantEntryCount int
115- wantErr bool
116- wantErrMsg string
108+ wantErr string
117109}{
118110{
119111name :"Success - directory found" ,
120112brickID :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}
139129for _ ,tc := range testCases {
140130t .Run (tc .name ,func (t * testing.T ) {
141131pathList ,err := store .GetBrickCodeExamplesPathFromID (tc .brickID )
142- if tc .wantErr {
132+ if tc .wantErr != "" {
143133require .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 {
146136require .NoError (t ,err ,"should not have returned an error" )
147137}
148- if tc .wantNilList {
138+ if tc .wantEntryCount == 0 {
149139require .Nil (t ,pathList ,"pathList should be nil" )
150140}else {
151141require .NotNil (t ,pathList ,"pathList should not be nil" )