Require nonempty source in Execute()

This commit is contained in:
Tim Van Baak 2025-01-29 07:39:00 -08:00
parent 6c312a1aae
commit 421271e2c3
2 changed files with 7 additions and 4 deletions

View File

@ -134,6 +134,9 @@ func Execute(
if len(argv) == 0 {
return nil, errors.New("empty argv")
}
if source == "" {
return nil, errors.New("empty source")
}
env = append(env, "STATE_PATH=")

View File

@ -72,7 +72,7 @@ func TestExecute(t *testing.T) {
}
}
execute := func(argv []string) ([]Item, error) {
return Execute("", argv, nil, "", time.Minute)
return Execute("_", argv, nil, "", time.Minute)
}
res, err := execute([]string{"true"})
@ -89,7 +89,7 @@ func TestExecute(t *testing.T) {
assertLen(res, 0)
// Timeout
res, err = Execute("", []string{"sleep", "10"}, nil, "", time.Millisecond)
res, err = Execute("_", []string{"sleep", "10"}, nil, "", time.Millisecond)
assertNotNil(err)
assertLen(res, 0)
@ -102,7 +102,7 @@ func TestExecute(t *testing.T) {
}
// Read from stdin
res, err = Execute("", []string{"jq", "-cR", `{id: .}`}, nil, "bar", time.Minute)
res, err = Execute("_", []string{"jq", "-cR", `{id: .}`}, nil, "bar", time.Minute)
assertNil(err)
assertLen(res, 1)
if res[0].Id != "bar" {
@ -110,7 +110,7 @@ func TestExecute(t *testing.T) {
}
// Set env
res, err = Execute("", []string{"jq", "-cn", `{id: env.HELLO}`}, []string{"HELLO=baz"}, "", time.Minute)
res, err = Execute("_", []string{"jq", "-cn", `{id: env.HELLO}`}, []string{"HELLO=baz"}, "", time.Minute)
assertNil(err)
assertLen(res, 1)
if res[0].Id != "baz" {