-
Notifications
You must be signed in to change notification settings - Fork 3
fix: make example code optional for brick example details endpoint request #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| package store | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/arduino/go-paths-helper" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/arduino/arduino-app-cli/internal/orchestrator/config" | ||
| ) | ||
|
|
||
| const validBrickID = "arduino:arduino_cloud" | ||
|
|
||
| func setupTestStore(t *testing.T) (*StaticStore, string) { | ||
| cfg, err := config.NewFromEnv() | ||
| require.NoError(t, err) | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| baseDir := paths.New("testdata", "assets", cfg.RunnerVersion).String() | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return NewStaticStore(baseDir), baseDir | ||
| } | ||
|
|
||
| func TestGetBrickReadmeFromID(t *testing.T) { | ||
| store, baseDir := setupTestStore(t) | ||
| namespace, brickName, _ := parseBrickID(validBrickID) | ||
| expectedReadmePath := filepath.Join(baseDir, "docs", namespace, brickName, "README.md") | ||
| expectedContent, err := os.ReadFile(expectedReadmePath) | ||
| require.NoError(t, err, "Error Reading README file: %s", expectedReadmePath) | ||
| require.NotEmpty(t, expectedContent, "ReadME file is empty: %s", expectedReadmePath) | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| testCases := []struct { | ||
| name string | ||
| brickID string | ||
| wantContent string | ||
| wantErr bool | ||
| wantErrIs error | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wantErrMsg string | ||
| }{ | ||
| { | ||
| name: "Success - file found", | ||
| brickID: validBrickID, | ||
| wantContent: string(expectedContent), | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Failure - file not found", | ||
| brickID: "namespace:non_existent_brick", | ||
| wantContent: "", | ||
| wantErr: true, | ||
| wantErrIs: os.ErrNotExist, | ||
| }, | ||
| { | ||
| name: "Failure - invalid ID", | ||
| brickID: "invalid-id", | ||
| wantContent: "", | ||
| wantErr: true, | ||
| wantErrMsg: "invalid ID", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| content, err := store.GetBrickReadmeFromID(tc.brickID) | ||
| if tc.wantErr { | ||
| require.Error(t, err, "should have returned an error") | ||
| if tc.wantErrIs != nil { | ||
| require.ErrorIs(t, err, tc.wantErrIs, "error type mismatch") | ||
| } | ||
| if tc.wantErrMsg != "" { | ||
| require.EqualError(t, err, tc.wantErrMsg, "error message mismatch") | ||
| } | ||
| } else { | ||
| require.NoError(t, err, "should not have returned an error") | ||
| } | ||
mirkoCrobu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| require.Equal(t, tc.wantContent, content, "content mismatch") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGetBrickComposeFilePathFromID(t *testing.T) { | ||
| store, baseDir := setupTestStore(t) | ||
| namespace, brickName, _ := parseBrickID(validBrickID) | ||
| expectedPathString := filepath.Join(baseDir, "compose", namespace, brickName, "brick_compose.yaml") | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| brickID string | ||
| wantPath string | ||
| wantErr bool | ||
| wantErrMsg string | ||
| }{ | ||
| { | ||
| name: "Success - valid ID", | ||
| brickID: validBrickID, | ||
| wantPath: expectedPathString, | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Failure - invalid ID", | ||
| brickID: "invalid ID", | ||
| wantPath: "", | ||
| wantErr: true, | ||
| wantErrMsg: "invalid ID", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| path, err := store.GetBrickComposeFilePathFromID(tc.brickID) | ||
| if tc.wantErr { | ||
| require.Error(t, err, "function was expected to return an error") | ||
| require.Nil(t, path, "path was expected to be nil") | ||
| require.EqualError(t, err, tc.wantErrMsg, "error message mismatch") | ||
| } else { | ||
| require.NoError(t, err, "function was not expected to return an error") | ||
| require.NotNil(t, path, "path was expected to be not nil") | ||
| require.Equal(t, tc.wantPath, path.String(), "path string mismatch") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGetBrickCodeExamplesPathFromID(t *testing.T) { | ||
| store, _ := setupTestStore(t) | ||
| const expectedEntryCount = 2 | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| brickID string | ||
| wantNilList bool | ||
| wantEntryCount int | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wantErr bool | ||
| wantErrMsg string | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }{ | ||
| { | ||
| name: "Success - directory found", | ||
| brickID: validBrickID, | ||
| wantNilList: false, | ||
| wantEntryCount: expectedEntryCount, | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Success - directory not found", | ||
| brickID: "namespace:non_existent_brick", | ||
| wantNilList: true, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Failure - invalid ID", | ||
| brickID: "invalid-id", | ||
| wantNilList: true, | ||
| wantErr: true, | ||
| wantErrMsg: "invalid ID", | ||
| }, | ||
| } | ||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| pathList, err := store.GetBrickCodeExamplesPathFromID(tc.brickID) | ||
| if tc.wantErr { | ||
| require.Error(t, err, "should have returned an error") | ||
| require.EqualError(t, err, tc.wantErrMsg, "error message mismatch") | ||
| } else { | ||
| require.NoError(t, err, "should not have returned an error") | ||
| } | ||
| if tc.wantNilList { | ||
| require.Nil(t, pathList, "pathList should be nil") | ||
| } else { | ||
| require.NotNil(t, pathList, "pathList should not be nil") | ||
| } | ||
| require.Equal(t, tc.wantEntryCount, len(pathList), "entry count mismatch") | ||
| }) | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1
internal/store/testdata/assets/0.4.8/compose/arduino/arduino_cloud/brick_compose.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| test file | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
1 change: 1 addition & 0 deletions
1
internal/store/testdata/assets/0.4.8/docs/arduino/arduino_cloud/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| test file |
1 change: 1 addition & 0 deletions
1
internal/store/testdata/assets/0.4.8/examples/arduino/arduino_cloud/example_1.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # test file 1 |
1 change: 1 addition & 0 deletions
1
internal/store/testdata/assets/0.4.8/examples/arduino/arduino_cloud/example_2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #test file 2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.