Skip to content

Commit ea06b5e

Browse files
dido18lucarin91
authored andcommitted
fix(app): improve error messages for invalid app paths in Load function
1 parent f61b73f commit ea06b5e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

internal/orchestrator/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Load(appPath string) (ArduinoApp, error) {
4848
return ArduinoApp{}, fmt.Errorf("app path is not valid: %w", err)
4949
}
5050
if !exist {
51-
return ArduinoApp{}, fmt.Errorf("no such file or directory: %s", path)
51+
return ArduinoApp{}, fmt.Errorf("app path must be a directory: %s", path)
5252
}
5353
path, err = path.Abs()
5454
if err != nil {

internal/orchestrator/app/app_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@ import (
2525
)
2626

2727
func TestLoad(t *testing.T) {
28-
t.Run("empty", func(t *testing.T) {
28+
t.Run("empty path returns an error", func(t *testing.T) {
2929
app, err := Load("")
3030
assert.Error(t, err)
3131
assert.Empty(t, app)
32+
assert.Contains(t, err.Error(), "empty")
3233
})
3334

34-
t.Run("AppSimple", func(t *testing.T) {
35+
t.Run("it fails if the app path is an existing file", func(t *testing.T) {
36+
_, err := Load("testdata/app.yaml")
37+
assert.Error(t, err)
38+
assert.Contains(t, err.Error(), "app path must be a directory")
39+
})
40+
41+
t.Run("it fails if the app path does not exist", func(t *testing.T) {
42+
_, err := Load("testdata/this-folder-does-not-exist")
43+
assert.Error(t, err)
44+
assert.Contains(t, err.Error(), "app path is not valid")
45+
})
46+
47+
t.Run("it load an app correctly", func(t *testing.T) {
3548
app, err := Load("testdata/AppSimple")
3649
assert.NoError(t, err)
3750
assert.NotEmpty(t, app)

0 commit comments

Comments
 (0)