github.com/shaardie/u-root@v4.0.1-0.20190127173353-f24a1c26aa2e+incompatible/integration/uinit_test.go (about) 1 // Copyright 2018 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package integration 6 7 import ( 8 "testing" 9 ) 10 11 // TestHelloWorld runs an init which prints the string "HELLO WORLD" and exits. 12 func TestHelloWorld(t *testing.T) { 13 q, cleanup := QEMUTest(t, &Options{ 14 Cmds: []string{ 15 "github.com/u-root/u-root/integration/testcmd/helloworld/uinit", 16 "github.com/u-root/u-root/cmds/init", 17 }, 18 }) 19 defer cleanup() 20 21 if err := q.Expect("HELLO WORLD"); err != nil { 22 t.Fatal(`expected "HELLO WORLD", got error: `, err) 23 } 24 } 25 26 // TestHelloWorldNegative runs an init which does not print the string "HELLO WORLD". 27 func TestHelloWorldNegative(t *testing.T) { 28 q, cleanup := QEMUTest(t, &Options{ 29 Cmds: []string{ 30 "github.com/u-root/u-root/integration/testcmd/helloworld/uinit", 31 "github.com/u-root/u-root/cmds/init", 32 }, 33 }) 34 defer cleanup() 35 36 if err := q.Expect("GOODBYE WORLD"); err == nil { 37 t.Fatal(`expected error, but matched "GOODBYE WORLD"`) 38 } 39 } 40 41 func TestScript(t *testing.T) { 42 q, cleanup := QEMUTest(t, &Options{ 43 Name: "ShellScript", 44 Cmds: []string{ 45 "github.com/u-root/u-root/cmds/init", 46 "github.com/u-root/u-root/cmds/shutdown", 47 "github.com/u-root/u-root/cmds/echo", 48 }, 49 Uinit: []string{ 50 "echo HELLO WORLD", 51 "shutdown -h", 52 }, 53 }) 54 defer cleanup() 55 56 if err := q.Expect("HELLO WORLD"); err != nil { 57 t.Fatal(`expected "HELLO WORLD", got error: `, err) 58 } 59 }