Skip to content

Commit bf22327

Browse files
committed
Validate project path argument
Exit with a helpful error message if the path provided via the PROJECT_PATH argument doesn't exist.
1 parent 2c5f5af commit bf22327

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: configuration/configuration.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
7474
reportFilePathString, _ := flags.GetString("report-file")
7575
reportFilePath = paths.New(reportFilePathString)
7676

77-
// TODO validate target path value, exit if not found
7877
// TODO support multiple paths
7978
targetPath = paths.New(projectPaths[0])
79+
targetPathExists, err := targetPath.ExistCheck()
80+
if err != nil {
81+
return fmt.Errorf("Problem processing PROJECT_PATH argument value %v: %v", projectPaths[0], err)
82+
}
83+
if !targetPathExists {
84+
return fmt.Errorf("PROJECT_PATH argument %v does not exist", projectPaths[0])
85+
}
8086

8187
// TODO: set via environment variable
8288
// customCheckModes[checkmode.Official] = false

Diff for: configuration/configuration_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package configuration
1717

1818
import (
19+
"os"
1920
"testing"
2021

2122
"github.com/arduino/arduino-check/configuration/checkmode"
@@ -24,12 +25,15 @@ import (
2425
"github.com/arduino/arduino-check/util/test"
2526
"github.com/arduino/go-paths-helper"
2627
"github.com/stretchr/testify/assert"
28+
"github.com/stretchr/testify/require"
2729
)
2830

2931
func TestInitialize(t *testing.T) {
3032
flags := test.ConfigurationFlags()
3133

32-
projectPaths := []string{"/foo"}
34+
projectPath, err := os.Getwd()
35+
require.Nil(t, err)
36+
projectPaths := []string{projectPath}
3337

3438
flags.Set("format", "foo")
3539
assert.Error(t, Initialize(flags, projectPaths))
@@ -125,8 +129,8 @@ func TestInitialize(t *testing.T) {
125129
assert.Nil(t, Initialize(flags, projectPaths))
126130
assert.Equal(t, reportFilePath, ReportFilePath())
127131

128-
reportFilePath = paths.New("/baz")
129-
projectPaths = []string{reportFilePath.String()}
130132
assert.Nil(t, Initialize(flags, projectPaths))
131-
assert.Equal(t, reportFilePath, TargetPath())
133+
assert.Equal(t, paths.New(projectPaths[0]), TargetPath())
134+
135+
assert.Error(t, Initialize(flags, []string{"/nonexistent"}))
132136
}

0 commit comments

Comments
 (0)