github.com/docker-library/go-dockerlibrary@v0.0.0-20200821205225-669fbe5c1d52/pkg/execpipe/execpipe_test.go (about)

     1  package execpipe_test
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"testing"
     7  
     8  	"github.com/docker-library/go-dockerlibrary/pkg/execpipe"
     9  )
    10  
    11  func TestStdoutPipeError(t *testing.T) {
    12  	cmd := exec.Command("nothing", "really", "matters", "in", "the", "end")
    13  
    14  	// set "Stdout" so that "cmd.StdoutPipe" fails
    15  	// https://golang.org/src/os/exec/exec.go?s=16834:16883#L587
    16  	cmd.Stdout = os.Stdout
    17  
    18  	_, err := execpipe.Run(cmd)
    19  	if err == nil {
    20  		t.Errorf("Expected execpipe.Run to fail -- it did not")
    21  	}
    22  }
    23  
    24  func TestStartError(t *testing.T) {
    25  	// craft a definitely-invalid command so that "cmd.Start" fails
    26  	// https://golang.org/src/os/exec/exec.go?s=8739:8766#L303
    27  	_, err := execpipe.RunCommand("nothing-really-matters-in-the-end--bogus-command")
    28  	if err == nil {
    29  		t.Errorf("Expected execpipe.RunCommand to fail -- it did not")
    30  	}
    31  }