Skip to content
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

Error if the file does not exist. #662

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func TestInclude(t *testing.T) {
book string
}{
{"testdata/book/include_main.yml"},
{"testdata/book/include_vars.yml"},
{"testdata/book/include_vars_main.yml"},
}
ctx := context.Background()
for _, tt := range tests {
Expand Down
7 changes: 4 additions & 3 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ func fetchPaths(pathp string) ([]string, error) {

// Local single file
if !strings.Contains(pattern, "*") {
if _, err := readFile(pp); err == nil {
paths = append(paths, pp)
} // skip if file not found
if _, err := readFile(pp); err != nil {
return nil, err
}
paths = append(paths, pp)
continue
}

Expand Down
33 changes: 20 additions & 13 deletions path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import (

func TestFetchPaths(t *testing.T) {
tests := []struct {
pathp string
want int
pathp string
want int
wantErr bool
}{
{"testdata/book/book.yml", 1},
{"testdata/book/notexist.yml", 0},
{"testdata/book/runn_*", 4},
{"testdata/book/book.yml:testdata/book/http.yml", 2},
{"testdata/book/book.yml:testdata/book/runn_*.yml", 5},
{"testdata/book/book.yml:testdata/book/book.yml", 1},
{"testdata/book/testdata/book/runn_0_success.yml:testdata/book/runn_*.yml", 4},
{"github://k1LoW/runn/testdata/book/book.yml", 1},
{"github://k1LoW/runn/testdata/book/runn_*", 4},
{"https://raw.githubusercontent.com/k1LoW/runn/main/testdata/book/book.yml", 1},
{"testdata/book/book.yml", 1, false},
{"testdata/book/notexist.yml", 0, true},
{"testdata/book/runn_*", 4, false},
{"testdata/book/book.yml:testdata/book/http.yml", 2, false},
{"testdata/book/book.yml:testdata/book/runn_*.yml", 5, false},
{"testdata/book/book.yml:testdata/book/book.yml", 1, false},
{"testdata/book/runn_0_success.yml:testdata/book/runn_*.yml", 4, false},
{"github://k1LoW/runn/testdata/book/book.yml", 1, false},
{"github://k1LoW/runn/testdata/book/runn_*", 4, false},
{"https://raw.githubusercontent.com/k1LoW/runn/main/testdata/book/book.yml", 1, false},
}
t.Cleanup(func() {
if err := RemoveCacheDir(); err != nil {
Expand All @@ -29,7 +30,13 @@ func TestFetchPaths(t *testing.T) {
t.Run(tt.pathp, func(t *testing.T) {
paths, err := fetchPaths(tt.pathp)
if err != nil {
t.Error(err)
if !tt.wantErr {
t.Errorf("got %v", err)
}
return
}
if tt.wantErr {
t.Errorf("want err")
}
got := len(paths)
if got != tt.want {
Expand Down
12 changes: 7 additions & 5 deletions testdata/book/include_vars_included.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ steps:
&& vars.b == "54321"
// If there is a variable expansion, it is reinterpreted in a form without quotes.
&& vars.c == 12345
&& vars.d == 54321
&& vars.e == 123459
&& vars.f == 543219
&& vars.d == "54321"
// When combining, the value to be expanded is treated as a string.
&& vars.e == "123459"
&& vars.f == "543219"
// If the beginning of the value to be combined is a number, it is treated as a number.
&& vars.g == 912345
&& vars.h == 954321
// If cast with string(), it is treated as a string.
&& vars.i == "12345"
&& vars.j == "54321"
// If the expanded value is to be passed as a string, enclose it in double quotes.
&& vars.k == "123459"
&& vars.l == "543219"
&& vars.k == "912345"
&& vars.l == "954321"
4 changes: 2 additions & 2 deletions testdata/book/include_vars_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ steps:
i: '{{ string(vars.intNumber) }}'
j: '{{ string(vars.strNumber) }}'
# If the expanded value is to be passed as a string, enclose it in double quotes.
k: '"{{ vars.intNumber }}9"'
l: '"{{ vars.strNumber }}9"'
k: '"9{{ vars.intNumber }}"'
l: '"9{{ vars.strNumber }}"'
Loading