diff --git a/cli/fork.go b/cli/fork.go index 0711c76a..802b2b8c 100644 --- a/cli/fork.go +++ b/cli/fork.go @@ -42,6 +42,9 @@ func buildForkRequest(targetName, targetType string, traffic, port, memory *int) func parseForkArg(arg string) (resourceType, name string, err error) { parts := strings.SplitN(arg, "/", 2) if len(parts) == 1 { + if parts[0] == "" { + return "", "", fmt.Errorf("resource name must not be empty") + } return "", parts[0], nil } name = parts[1] diff --git a/cli/fork_test.go b/cli/fork_test.go index c18cb0e0..cbd652e1 100644 --- a/cli/fork_test.go +++ b/cli/fork_test.go @@ -19,6 +19,7 @@ func TestParseForkArg(t *testing.T) { {name: "untyped", arg: "source", resourceName: "source"}, {name: "sandbox", arg: "sbx/source", resourceType: "sandbox", resourceName: "source"}, {name: "application", arg: "application/target", resourceType: "application", resourceName: "target"}, + {name: "empty name", arg: "", wantErr: "resource name must not be empty"}, {name: "missing name", arg: "sbx/", wantErr: "missing name"}, {name: "unknown type", arg: "agent/source", wantErr: "unknown resource type"}, {name: "nested path", arg: "sbx/foo/bar", wantErr: "must not contain '/'"},