Exemplo n.º 1
0
func TestTaskZombie(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("sleep", []string{"100"}, image)

	task.SetStdout(ioutil.Discard)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}
	assert.True(t, task.Alive())
	assert.False(t, task.Zombie())

	if err := task.Kill(); err != nil {
		t.Fatal("Could not kill task: ", err)
	}

	// Give the system a beat to kill the process
	time.Sleep(200 * time.Millisecond)

	assert.True(t, task.Alive())
	assert.True(t, task.Zombie())

	if err := task.Wait(); err != nil {
		t.Fatal("Could not wait task: ", err)
	}
	assert.False(t, task.Alive())
	assert.False(t, task.Zombie())
}
Exemplo n.º 2
0
func TestKillTask(t *testing.T) {
	// https://code.google.com/p/go/issues/detail?id=7938

	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("sleep", []string{"100"}, image)

	task.SetStdout(ioutil.Discard)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}
	if err := task.Kill(); err != nil {
		t.Fatal("Could not kill task: ", err)
	}
	if err := task.Wait(); err != nil {
		t.Fatal("Could not wait task: ", err)
	}

	signaled, err := task.Signaled()
	if err != nil {
		t.Fatal("Could not get signaled: ", err)
	}

	assert.True(t, signaled)
}
Exemplo n.º 3
0
func TestSignalWithSigterm(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("sleep", []string{"10"}, image)

	task.SetStdout(ioutil.Discard)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}

	if err := task.Command.Process.Signal(syscall.SIGTERM); err != nil {
		t.Fatal("Could not signal process: ", err)
	}

	if err := task.Wait(); err != nil {
		t.Fatal("Could not wait task: ", err)
	}

	signaled, err := task.Signaled()
	if err != nil {
		t.Fatal("Could not get signaled of task: ", err)
	}
	assert.True(t, signaled)

	signal, err := task.Signal()
	if err != nil {
		t.Fatal("Could not get signal of task: ", err)
	}
	assert.Equal(t, syscall.SIGTERM, signal)
}
Exemplo n.º 4
0
func TestTaskWaitStatusNoWait(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("uname", []string{}, image)

	waitstatus, err := task.WaitStatus()
	assert.Nil(t, waitstatus)
	assert.NotNil(t, err)
}
Exemplo n.º 5
0
func TestErrorProcessStateNoWait(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("uname", []string{}, image)

	task.SetStdout(ioutil.Discard)

	processstate, err := task.ProcessState()
	assert.Nil(t, processstate)
	assert.NotNil(t, err)
}
Exemplo n.º 6
0
func TestTaskWaitStatusSignaled(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("uname", []string{}, image)

	task.SetStdout(ioutil.Discard)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}
	if err := task.Wait(); err != nil {
		t.Fatal("Could not wait task: ", err)
	}

	waitStatus, _ := task.WaitStatus()
	assert.False(t, waitStatus.Signaled())
}
Exemplo n.º 7
0
func TestTaskProcessStateNoSuccess(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("ls", []string{"/notarealdir"}, image)

	task.SetStderr(ioutil.Discard)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}
	if err := task.Wait(); err == nil {
		t.Fatal("Task waited successfully: ", err)
	}

	processState, _ := task.ProcessState()
	assert.False(t, processState.Success())
}
Exemplo n.º 8
0
func TestTaskProcessState(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("uname", []string{}, image)

	task.SetStdout(ioutil.Discard)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}
	if err := task.Wait(); err != nil {
		t.Fatal("Could not wait task: ", err)
	}

	processState, _ := task.ProcessState()
	assert.True(t, processState.Success())
}
Exemplo n.º 9
0
func TestTaskAliveWithWait(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("sleep", []string{"3"}, image)

	task.SetStdout(ioutil.Discard)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}
	assert.True(t, task.Alive())

	if err := task.Wait(); err != nil {
		t.Fatal("Could not wait task: ", err)
	}
	assert.False(t, task.Alive())
}
Exemplo n.º 10
0
func TestTask(t *testing.T) {
	image, err := chrootly.NewImageFromLocal("test_image.tar")
	if err != nil {
		t.Fatal("Could not create image: ", err)
	}
	task := chrootly.NewTask("ls", []string{"-a", ".dockerenv"}, image)

	output := bytes.NewBuffer(nil)
	task.SetStdout(output)

	if err := task.Start(); err != nil {
		t.Fatal("Could not start task: ", err)
	}
	if err := task.Wait(); err != nil {
		t.Fatal("Could not wait task: ", err)
	}

	stdoutLine, err := output.ReadString('\n')
	if err != nil {
		t.Fatal("Could not read output: ", err)
	}

	assert.Equal(t, ".dockerenv\n", stdoutLine)
}
Exemplo n.º 11
0
func TestNewImageFromLocalErrorWithCrapPath(t *testing.T) {
	_, err := chrootly.NewImageFromLocal("/tmp/jabberwocky")

	assert.NotNil(t, err)
}
Exemplo n.º 12
0
func TestNewImageFromLocalErrorWithCrapName(t *testing.T) {
	_, err := chrootly.NewImageFromLocal("lknslnkef")

	assert.NotNil(t, err)
}
Exemplo n.º 13
0
func TestNewImageFromLocalErrorWithCrapFile(t *testing.T) {
	_, err := chrootly.NewImageFromLocal("crap_image.tar")

	assert.NotNil(t, err)
}
Exemplo n.º 14
0
func TestNewImageFromLocal(t *testing.T) {
	image, _ := chrootly.NewImageFromLocal("test_image.tar")

	assert.NotNil(t, image)
	assertImageSetup(t, image.Directory)
}