-
Notifications
You must be signed in to change notification settings - Fork 275
feat: Add ability to run commands at given path #536
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
58c0e6a
f3b80ef
09bc785
eca9c1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package sh | |
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
| ) | ||
|
|
@@ -18,6 +19,18 @@ func TestOutCmd(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestOutAtCmd(t *testing.T) { | ||
| cmd := OutAtCmd("sh", "-c") | ||
| out, err := cmd("/", "pwd") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| expected := "/" | ||
| if out != expected { | ||
| t.Fatalf("expected %q but got %q", expected, out) | ||
| } | ||
| } | ||
|
|
||
| func TestExitCode(t *testing.T) { | ||
| ran, err := Exec(nil, nil, nil, os.Args[0], "-helper", "-exit", "99") | ||
| if err == nil { | ||
|
|
@@ -68,5 +81,46 @@ func TestAutoExpand(t *testing.T) { | |
| if s != "baz" { | ||
| t.Fatalf(`Expected "baz" but got %q`, s) | ||
| } | ||
| } | ||
|
|
||
| func TestSettingPwd(t *testing.T) { | ||
| pwd := "/" | ||
| out := &bytes.Buffer{} | ||
| ran, err := ExecAt(nil, out, nil, pwd, "pwd") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error from runner: %#v", err) | ||
| } | ||
| if !ran { | ||
| t.Errorf("expected ran to be true but was false.") | ||
| } | ||
| if out.String() != fmt.Sprintf("%s\n", pwd) { | ||
| t.Errorf("expected %s, got %q", fmt.Sprintf("%s\n", pwd), out) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because we are running the command "pwd" which should result in the correct pwd, which is set to be "/". So that is what we expect to get in return. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use |
||
| } | ||
| } | ||
|
|
||
| func TestSettingNoPwd(t *testing.T) { | ||
| currentWd, err := os.Getwd() | ||
| if err != nil { | ||
| t.Errorf("Failed getting current working directory") | ||
|
AtzeDeVries marked this conversation as resolved.
Outdated
|
||
| } | ||
| out := &bytes.Buffer{} | ||
| ran, err := ExecAt(nil, out, nil, "", "pwd") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error from runner: %#v", err) | ||
| } | ||
| if !ran { | ||
| t.Errorf("expected ran to be true but was false.") | ||
| } | ||
| if out.String() != fmt.Sprintf("%s\n", currentWd) { | ||
| t.Errorf("expected %s, got %q", fmt.Sprintf("%s\n", currentWd), out) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we run ExecAt with pwd "", we should test that this returns the actuall current path. |
||
| } | ||
| } | ||
|
|
||
| func TestSettingInvalidPwd(t *testing.T) { | ||
| pwd := "/i-am-expected-to-not-exist" | ||
| out := &bytes.Buffer{} | ||
| _, err := ExecAt(nil, out, nil, pwd, "pwd") | ||
| if err == nil { | ||
| t.Fatalf("I am expected to fail because path %s does not exist", pwd) | ||
|
AtzeDeVries marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.