added more tests to cmdrunner (reproduce another ?? cmdrunner bug...)
This commit is contained in:
@@ -12,6 +12,12 @@ func TestStdout(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if res1.CommandTimedOut {
|
||||
t.Errorf("Timeout")
|
||||
}
|
||||
if res1.ExitCode != 0 {
|
||||
t.Errorf("res1.ExitCode == %v", res1.ExitCode)
|
||||
}
|
||||
if res1.StdErr != "" {
|
||||
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
||||
}
|
||||
@@ -30,6 +36,12 @@ func TestStderr(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if res1.CommandTimedOut {
|
||||
t.Errorf("Timeout")
|
||||
}
|
||||
if res1.ExitCode != 0 {
|
||||
t.Errorf("res1.ExitCode == %v", res1.ExitCode)
|
||||
}
|
||||
if res1.StdErr != "error" {
|
||||
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
||||
}
|
||||
@@ -50,6 +62,12 @@ func TestStdcombined(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if res1.CommandTimedOut {
|
||||
t.Errorf("Timeout")
|
||||
}
|
||||
if res1.ExitCode != 0 {
|
||||
t.Errorf("res1.ExitCode == %v", res1.ExitCode)
|
||||
}
|
||||
if res1.StdErr != "1\n3\n" {
|
||||
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
||||
}
|
||||
@@ -116,6 +134,12 @@ func TestReadUnflushedStdout(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if res1.CommandTimedOut {
|
||||
t.Errorf("Timeout")
|
||||
}
|
||||
if res1.ExitCode != 0 {
|
||||
t.Errorf("res1.ExitCode == %v", res1.ExitCode)
|
||||
}
|
||||
if res1.StdErr != "" {
|
||||
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
||||
}
|
||||
@@ -134,6 +158,12 @@ func TestReadUnflushedStderr(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if res1.CommandTimedOut {
|
||||
t.Errorf("Timeout")
|
||||
}
|
||||
if res1.ExitCode != 0 {
|
||||
t.Errorf("res1.ExitCode == %v", res1.ExitCode)
|
||||
}
|
||||
if res1.StdErr != "message101" {
|
||||
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
||||
}
|
||||
@@ -200,7 +230,7 @@ func TestPartialReadUnflushedStderr(t *testing.T) {
|
||||
|
||||
func TestListener(t *testing.T) {
|
||||
|
||||
_, err := Runner("python").
|
||||
res1, err := Runner("python").
|
||||
Arg("-c").
|
||||
Arg("import sys;" +
|
||||
"import time;" +
|
||||
@@ -223,23 +253,71 @@ func TestListener(t *testing.T) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if res1.CommandTimedOut {
|
||||
t.Errorf("Timeout")
|
||||
}
|
||||
if res1.ExitCode != 0 {
|
||||
t.Errorf("res1.ExitCode == %v", res1.ExitCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLongStdout(t *testing.T) {
|
||||
|
||||
res1, err := Runner("python").
|
||||
Arg("-c").
|
||||
Arg("import sys; import time; print(\"1234\" * 10000 + \"\\n\"); print(\"1234\" * 10000 + \"\\n\"); print(\"1234\" * 10000 + \"\\n\");").
|
||||
Timeout(100 * time.Millisecond).
|
||||
Arg("import sys; import time; print(\"X\" * 125001 + \"\\n\"); print(\"Y\" * 125001 + \"\\n\"); print(\"Z\" * 125001 + \"\\n\");").
|
||||
Timeout(5000 * time.Millisecond).
|
||||
Run()
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if res1.CommandTimedOut {
|
||||
t.Errorf("Timeout")
|
||||
}
|
||||
if res1.ExitCode != 0 {
|
||||
t.Errorf("res1.ExitCode == %v", res1.ExitCode)
|
||||
}
|
||||
if res1.StdErr != "" {
|
||||
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
||||
}
|
||||
if len(res1.StdOut) != 120006 {
|
||||
if len(res1.StdOut) != 375006 {
|
||||
t.Errorf("len(res1.StdOut) == '%v'", len(res1.StdOut))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFailOnTimeout(t *testing.T) {
|
||||
|
||||
_, err := Runner("sleep").Arg("2").Timeout(200 * time.Millisecond).FailOnTimeout().Run()
|
||||
if err != ErrTimeout {
|
||||
t.Errorf("wrong err := %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFailOnExitcode(t *testing.T) {
|
||||
|
||||
_, err := Runner("false").Timeout(200 * time.Millisecond).FailOnExitCode().Run()
|
||||
if err != ErrExitCode {
|
||||
t.Errorf("wrong err := %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEnsureExitcode1(t *testing.T) {
|
||||
|
||||
_, err := Runner("false").Timeout(200 * time.Millisecond).EnsureExitcode(1).Run()
|
||||
if err != nil {
|
||||
t.Errorf("wrong err := %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEnsureExitcode2(t *testing.T) {
|
||||
|
||||
_, err := Runner("false").Timeout(200*time.Millisecond).EnsureExitcode(0, 2, 3).Run()
|
||||
if err != ErrExitCode {
|
||||
t.Errorf("wrong err := %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user