github.com/drone/runner-go@v1.12.0/shell/powershell/powershell_test.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package powershell
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestCommands(t *testing.T) {
    13  	cmd, args := Command()
    14  	{
    15  		got, want := cmd, "powershell"
    16  		if !reflect.DeepEqual(got, want) {
    17  			t.Errorf("Want command %v, got %v", want, got)
    18  		}
    19  	}
    20  	{
    21  		got, want := args, []string{
    22  			"-noprofile",
    23  			"-noninteractive",
    24  			"-command",
    25  		}
    26  		if !reflect.DeepEqual(got, want) {
    27  			t.Errorf("Want args %v, got %v", want, got)
    28  		}
    29  	}
    30  }
    31  
    32  func TestScript(t *testing.T) {
    33  	got, want := Script([]string{"go build", "go test"}), exampleScript
    34  	if got != want {
    35  		t.Errorf("Want %q\ngot  %q", want, got)
    36  	}
    37  }
    38  
    39  func TestSilentScript(t *testing.T) {
    40  	got, want := SilentScript([]string{"go build", "go test"}), exampleSilentScript
    41  	if got != want {
    42  		t.Errorf("Want \n%q\ngot\n%q", want, got)
    43  	}
    44  }
    45  
    46  var exampleScript = `
    47  $erroractionpreference = "stop"
    48  
    49  echo "+ go build"
    50  go build
    51  if ($LastExitCode -gt 0) { exit $LastExitCode }
    52  
    53  echo "+ go test"
    54  go test
    55  if ($LastExitCode -gt 0) { exit $LastExitCode }
    56  `
    57  
    58  var exampleSilentScript = `
    59  $erroractionpreference = "stop"
    60  
    61  go build
    62  if ($LastExitCode -gt 0) { exit $LastExitCode }
    63  
    64  go test
    65  if ($LastExitCode -gt 0) { exit $LastExitCode }
    66  `