cleanup(shellx): do not directly depend on apex/log (#357)

This commit is contained in:
Simone Basso 2021-06-04 14:02:18 +02:00 committed by GitHub
commit 39aec6677d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 39 deletions

View file

@ -1,12 +1,16 @@
package shellx
import "testing"
import (
"testing"
"github.com/apex/log"
)
func TestRun(t *testing.T) {
if err := Run("whoami"); err != nil {
if err := Run(log.Log, "whoami"); err != nil {
t.Fatal(err)
}
if err := Run("./nonexistent/command"); err == nil {
if err := Run(log.Log, "./nonexistent/command"); err == nil {
t.Fatal("expected an error here")
}
}
@ -22,22 +26,22 @@ func TestRunQuiet(t *testing.T) {
func TestRunCommandline(t *testing.T) {
t.Run("when the command does not parse", func(t *testing.T) {
if err := RunCommandline(`"foobar`); err == nil {
if err := RunCommandline(log.Log, `"foobar`); err == nil {
t.Fatal("expected an error here")
}
})
t.Run("when we have no arguments", func(t *testing.T) {
if err := RunCommandline(""); err == nil {
if err := RunCommandline(log.Log, ""); err == nil {
t.Fatal("expected an error here")
}
})
t.Run("when we have a single argument", func(t *testing.T) {
if err := RunCommandline("ls"); err != nil {
if err := RunCommandline(log.Log, "ls"); err != nil {
t.Fatal(err)
}
})
t.Run("when we have more than one argument", func(t *testing.T) {
if err := RunCommandline("ls ."); err != nil {
if err := RunCommandline(log.Log, "ls ."); err != nil {
t.Fatal(err)
}
})