Skip to content

Commit 7cb0eb0

Browse files
mirkoCrobumirkoCrobu
authored andcommitted
refactoring store_test
1 parent 90d6f29 commit 7cb0eb0

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

internal/store/store_test.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,16 @@ package store
22

33
import (
44
"os"
5-
"path/filepath"
65
"testing"
76

87
"github.com/arduino/go-paths-helper"
98
"github.com/stretchr/testify/require"
10-
11-
"github.com/arduino/arduino-app-cli/internal/orchestrator/config"
129
)
1310

1411
const validBrickID = "arduino:arduino_cloud"
1512

16-
func setupTestStore(t *testing.T) (*StaticStore, string) {
17-
cfg, err := config.NewFromEnv()
18-
require.NoError(t, err)
19-
baseDir := paths.New("testdata", "assets", cfg.RunnerVersion).String()
20-
return NewStaticStore(baseDir), baseDir
21-
}
22-
2313
func TestGetBrickReadmeFromID(t *testing.T) {
24-
store, baseDir := setupTestStore(t)
25-
namespace, brickName, _ := parseBrickID(validBrickID)
26-
expectedReadmePath := filepath.Join(baseDir, "docs", namespace, brickName, "README.md")
27-
expectedContent, err := os.ReadFile(expectedReadmePath)
28-
require.NoError(t, err, "Error Reading README file: %s", expectedReadmePath)
29-
require.NotEmpty(t, expectedContent, "ReadME file is empty: %s", expectedReadmePath)
14+
store := NewStaticStore(paths.New("testdata", "assets", "0.4.8").String())
3015

3116
testCases := []struct {
3217
name string
@@ -39,7 +24,7 @@ func TestGetBrickReadmeFromID(t *testing.T) {
3924
{
4025
name: "Success - file found",
4126
brickID: validBrickID,
42-
wantContent: string(expectedContent),
27+
wantContent: "## Readme test file",
4328
wantErr: false,
4429
},
4530
{
@@ -78,9 +63,7 @@ func TestGetBrickReadmeFromID(t *testing.T) {
7863
}
7964

8065
func TestGetBrickComposeFilePathFromID(t *testing.T) {
81-
store, baseDir := setupTestStore(t)
82-
namespace, brickName, _ := parseBrickID(validBrickID)
83-
expectedPathString := filepath.Join(baseDir, "compose", namespace, brickName, "brick_compose.yaml")
66+
store := NewStaticStore(paths.New("testdata", "assets", "0.4.8").String())
8467

8568
testCases := []struct {
8669
name string
@@ -92,7 +75,7 @@ func TestGetBrickComposeFilePathFromID(t *testing.T) {
9275
{
9376
name: "Success - valid ID",
9477
brickID: validBrickID,
95-
wantPath: expectedPathString,
78+
wantPath: "testdata/assets/0.4.8/compose/arduino/arduino_cloud/brick_compose.yaml",
9679
wantErr: false,
9780
},
9881
{
@@ -121,7 +104,7 @@ func TestGetBrickComposeFilePathFromID(t *testing.T) {
121104
}
122105

123106
func TestGetBrickCodeExamplesPathFromID(t *testing.T) {
124-
store, _ := setupTestStore(t)
107+
store := NewStaticStore(paths.New("testdata", "assets", "0.4.8").String())
125108
const expectedEntryCount = 2
126109

127110
testCases := []struct {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test file
1+
## brick compose test file
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test file
1+
## Readme test file

0 commit comments

Comments
 (0)