mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
9f0b3f5609
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package reexec // import "github.com/docker/docker/pkg/reexec"
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func init() {
|
|
Register("reexec", func() {
|
|
panic("Return Error")
|
|
})
|
|
Init()
|
|
}
|
|
|
|
func TestRegister(t *testing.T) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
assert.Equal(t, `reexec func already registered under name "reexec"`, r)
|
|
}
|
|
}()
|
|
Register("reexec", func() {})
|
|
}
|
|
|
|
func TestCommand(t *testing.T) {
|
|
cmd := Command("reexec")
|
|
w, err := cmd.StdinPipe()
|
|
assert.NilError(t, err, "Error on pipe creation: %v", err)
|
|
defer w.Close()
|
|
|
|
err = cmd.Start()
|
|
assert.NilError(t, err, "Error on re-exec cmd: %v", err)
|
|
err = cmd.Wait()
|
|
assert.Error(t, err, "exit status 2")
|
|
}
|
|
|
|
func TestNaiveSelf(t *testing.T) {
|
|
if os.Getenv("TEST_CHECK") == "1" {
|
|
os.Exit(2)
|
|
}
|
|
cmd := exec.Command(naiveSelf(), "-test.run=TestNaiveSelf")
|
|
cmd.Env = append(os.Environ(), "TEST_CHECK=1")
|
|
err := cmd.Start()
|
|
assert.NilError(t, err, "Unable to start command")
|
|
err = cmd.Wait()
|
|
assert.Error(t, err, "exit status 2")
|
|
|
|
os.Args[0] = "mkdir"
|
|
assert.Check(t, naiveSelf() != os.Args[0])
|
|
}
|