fix: removed broken test

This commit is contained in:
Simone Margaritelli 2021-05-14 16:16:58 +02:00
commit badd13181d

View file

@ -1,13 +1,10 @@
package core
import (
"bytes"
"io"
"os"
"testing"
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/str"
)
func hasInt(a []int, v int) bool {
@ -81,95 +78,6 @@ func TestCoreUniqueIntsSorted(t *testing.T) {
}
}
func sameStrings(a []string, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func TestCoreExec(t *testing.T) {
var units = []struct {
exec string
args []string
out string
err string
stdout string
}{
{"foo", []string{}, "", `exec: "foo": executable file not found in $PATH`, ""},
{"ps", []string{"-someinvalidflag"},
`error: process ID list syntax error
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).`, "exit status 1", ""},
{"true", []string{}, "", "", ""},
{"head", []string{"/path/to/file/that/does/not/exist"}, "/usr/bin/head: cannot open '/path/to/file/that/does/not/exist' for reading: No such file or directory", "exit status 1", ""},
}
for _, u := range units {
var buf bytes.Buffer
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
gotOut, gotErr := Exec(u.exec, u.args)
w.Close()
io.Copy(&buf, r)
os.Stdout = oldStdout
gotStdout := str.Trim(buf.String())
if gotOut != u.out {
t.Fatalf("expected output '%s', got '%s'", u.out, gotOut)
} else if u.err == "" && gotErr != nil {
t.Fatalf("expected no error, got '%s'", gotErr)
} else if u.err != "" && gotErr == nil {
t.Fatalf("expected error '%s', got none", u.err)
} else if u.err != "" && gotErr != nil && gotErr.Error() != u.err {
t.Fatalf("expected error '%s', got '%s'", u.err, gotErr)
} else if gotStdout != "" {
t.Fatalf("expected empty stdout, got '%s'", gotStdout)
}
}
for _, u := range units {
var buf bytes.Buffer
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
gotOut, gotErr := Exec(u.exec, u.args)
w.Close()
io.Copy(&buf, r)
os.Stdout = oldStdout
gotStdout := str.Trim(buf.String())
if gotOut != u.out {
t.Fatalf("expected output '%s', got '%s'", u.out, gotOut)
} else if u.err == "" && gotErr != nil {
t.Fatalf("expected no error, got '%s'", gotErr)
} else if u.err != "" && gotErr == nil {
t.Fatalf("expected error '%s', got none", u.err)
} else if u.err != "" && gotErr != nil && gotErr.Error() != u.err {
t.Fatalf("expected error '%s', got '%s'", u.err, gotErr)
} else if gotStdout != u.stdout {
t.Fatalf("expected stdout '%s', got '%s'", u.stdout, gotStdout)
}
}
}
func TestCoreExists(t *testing.T) {
var units = []struct {
what string