github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/integration/generic-tests/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  // +build !race
     6  
     7  package integration
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/u-root/u-root/pkg/vmtest"
    13  )
    14  
    15  // TestHelloWorld runs an init which prints the string "HELLO WORLD" and exits.
    16  func TestHelloWorld(t *testing.T) {
    17  	q, cleanup := vmtest.QEMUTest(t, &vmtest.Options{
    18  		Uinit: "github.com/u-root/u-root/integration/testcmd/helloworld/uinit",
    19  	})
    20  	defer cleanup()
    21  
    22  	if err := q.Expect("HELLO WORLD"); err != nil {
    23  		t.Fatal(`expected "HELLO WORLD", got error: `, err)
    24  	}
    25  }
    26  
    27  // TestHelloWorldNegative runs an init which does not print the string "HELLO WORLD".
    28  func TestHelloWorldNegative(t *testing.T) {
    29  	q, cleanup := vmtest.QEMUTest(t, &vmtest.Options{
    30  		Uinit: "github.com/u-root/u-root/integration/testcmd/helloworld/uinit",
    31  	})
    32  	defer cleanup()
    33  
    34  	if err := q.Expect("GOODBYE WORLD"); err == nil {
    35  		t.Fatal(`expected error, but matched "GOODBYE WORLD"`)
    36  	}
    37  }