github.com/thriqon/involucro@v1.1.3/integrationtest/expectations_test.go (about)

     1  package integrationtest
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/involucro/involucro/app"
     7  )
     8  
     9  func TestExpectationMatchStdout(t *testing.T) {
    10  	if testing.Short() {
    11  		t.SkipNow()
    12  	}
    13  	if err := app.Main([]string{
    14  		"involucro", "-e",
    15  		"inv.task('test').using('busybox').withExpectation({stdout = 'Hello, World!'}).run('echo', 'Hello, World!')",
    16  		"test",
    17  	}); err != nil {
    18  		t.Error(err)
    19  	}
    20  }
    21  
    22  func TestExpectationsCrashesWhenStdoutNotMet(t *testing.T) {
    23  	if testing.Short() {
    24  		t.SkipNow()
    25  	}
    26  
    27  	if err := app.Main([]string{
    28  		"involucro", "-e",
    29  		"inv.task('test').using('busybox').withExpectation({stdout = 'Hello, World!'}).run('echo', 'Hello, Moon')",
    30  		"test",
    31  	}); err == nil {
    32  		t.Error("Expected error")
    33  	}
    34  
    35  }
    36  
    37  func TestExpectationMatchStderr(t *testing.T) {
    38  	if testing.Short() {
    39  		t.SkipNow()
    40  	}
    41  	if err := app.Main([]string{
    42  		"involucro", "-e",
    43  		"inv.task('test').using('busybox').withExpectation({stderr = 'Hello, World'}).run('/bin/sh', '-c', 'echo Hello, World 1>&2')",
    44  		"test",
    45  	}); err != nil {
    46  		t.Error(err)
    47  	}
    48  }
    49  
    50  func TestExpectationsCrashesWhenStderrNotMet(t *testing.T) {
    51  	if testing.Short() {
    52  		t.SkipNow()
    53  	}
    54  
    55  	if err := app.Main([]string{
    56  		"involucro", "-e",
    57  		"inv.task('test').using('busybox').withExpectation({stderr = 'Hello, World'}).run('/bin/sh', '-c', 'echo Hello, Moon 1>&2')",
    58  		"test",
    59  	}); err == nil {
    60  		t.Error("Expected error")
    61  	}
    62  }
    63  
    64  func TestExpectationMatchExitCode(t *testing.T) {
    65  	if testing.Short() {
    66  		t.SkipNow()
    67  	}
    68  	if err := app.Main([]string{
    69  		"involucro", "-e",
    70  		"inv.task('test').using('busybox').withExpectation({code = 1}).run('false')",
    71  		"test",
    72  	}); err != nil {
    73  		t.Error(err)
    74  	}
    75  }
    76  
    77  func TestExpectationsCrashesWhenExitCodeNotMet(t *testing.T) {
    78  	if testing.Short() {
    79  		t.SkipNow()
    80  	}
    81  
    82  	if err := app.Main([]string{
    83  		"involucro", "-e",
    84  		"inv.task('test').using('busybox').withExpectation({code = 1}).run('true')",
    85  		"test",
    86  	}); err == nil {
    87  		t.Error("Expected error")
    88  	}
    89  }