functional tests: TestFailure: don't rely on systemd debug logs

Don't rely on systemd debug logs: this can change from one version to
another and this can be redirected to the journal.

Instead, use commands like "rkt list" and "rkt status" to find the
status of the pod. Moreover, this tests more rkt commands too.
This commit is contained in:
Alban Crequy
2015-05-28 12:18:52 +02:00
committed by Iago López Galeiras
parent 6b176f55f1
commit 76ed159048
+21 -52
View File
@@ -17,65 +17,34 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"testing" "testing"
"github.com/coreos/rkt/Godeps/_workspace/src/github.com/ThomasRooney/gexpect" "github.com/coreos/rkt/Godeps/_workspace/src/github.com/ThomasRooney/gexpect"
) )
func TestSuccess(t *testing.T) { func TestExitCode(t *testing.T) {
patchTestACI("rkt-inspect-exit0.aci", "--exec=/inspect --print-msg=Hello --exit-code=0") for i := 0; i < 3; i++ {
defer os.Remove("rkt-inspect-exit0.aci") t.Logf("%d\n", i)
ctx := newRktRunCtx() patchTestACI("rkt-inspect-exit.aci", fmt.Sprintf("--exec=/inspect --print-msg=Hello --exit-code=%d", i))
defer ctx.cleanup() defer os.Remove("rkt-inspect-exit.aci")
ctx := newRktRunCtx()
defer ctx.cleanup()
child, err := gexpect.Spawn(fmt.Sprintf("%s --debug --insecure-skip-verify run ./rkt-inspect-exit0.aci", ctx.cmd())) cmd := fmt.Sprintf(`/bin/sh -c "`+
if err != nil { `%s --debug --insecure-skip-verify run ./rkt-inspect-exit.aci ;`+
t.Fatalf("Cannot exec rkt") `UUID=$(%s list --full|grep exited|awk '{print $1}') ;`+
} `echo -n 'status=' ;`+
err = child.Expect("Hello") `%s status $UUID|grep '^sha512-.*=[0-9]*$'|cut -d= -f2"`,
if err != nil { ctx.cmd(), ctx.cmd(), ctx.cmd())
t.Fatalf("Missing hello: %v", err) t.Logf("%s\n", cmd)
} child, err := gexpect.Spawn(cmd)
forbidden := "main process exited, code=exited, status=" if err != nil {
_, receiver := child.AsyncInteractChannels() t.Fatalf("Cannot exec rkt")
for {
msg, open := <-receiver
if !open {
break
} }
if strings.Contains(msg, forbidden) {
t.Fatalf("Forbidden text received") err = child.Wait()
if err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
} }
} }
err = child.Wait()
if err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}
func TestFailure(t *testing.T) {
patchTestACI("rkt-inspect-exit20.aci", "--exec=/inspect --print-msg=Hello --exit-code=20")
defer os.Remove("rkt-inspect-exit20.aci")
ctx := newRktRunCtx()
defer ctx.cleanup()
child, err := gexpect.Spawn(fmt.Sprintf("%s --debug --insecure-skip-verify run ./rkt-inspect-exit20.aci", ctx.cmd()))
if err != nil {
t.Fatalf("Cannot exec rkt")
}
err = child.Expect("Hello")
if err != nil {
t.Fatalf("Missing hello: %v", err)
}
err = child.Expect("process exited, code=exited, status=20")
if err != nil {
t.Fatalf("Missing exit status: %v", err)
}
err = child.Wait()
if err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
} }