Skip to content

Commit a21d86d

Browse files
authored
Merge pull request #32 from arduino/per1234/validate-project-path
Validate project path argument
2 parents a530b08 + bf22327 commit a21d86d

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
@@ -73,9 +73,15 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
7373
reportFilePathString, _ := flags.GetString("report-file")
7474
reportFilePath = paths.New(reportFilePathString)
7575

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

8086
// TODO: set via environment variable
8187
// 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)