Respect directory option for steps again (#4319)

This commit is contained in:
6543
2024-11-06 23:21:56 +01:00
committed by GitHub
parent c9752bb735
commit bf5405b6cc
10 changed files with 96 additions and 61 deletions

View File

@@ -16,6 +16,7 @@ package common
import (
"testing"
"text/template"
"github.com/stretchr/testify/assert"
)
@@ -29,7 +30,7 @@ func TestGenerateScriptWin(t *testing.T) {
from: []string{"echo %PATH%", "go build", "go test"},
want: `
$ErrorActionPreference = 'Stop';
if ([Environment]::GetEnvironmentVariable('CI_WORKSPACE')) { if (-not (Test-Path "$env:CI_WORKSPACE")) { New-Item -Path "$env:CI_WORKSPACE" -ItemType Directory -Force }};
if (-not (Test-Path "/woodpecker/some")) { New-Item -Path "/woodpecker/some" -ItemType Directory -Force };
if (-not [Environment]::GetEnvironmentVariable('HOME')) { [Environment]::SetEnvironmentVariable('HOME', 'c:\root') };
if (-not (Test-Path "$env:HOME")) { New-Item -Path "$env:HOME" -ItemType Directory -Force };
if ($Env:CI_NETRC_MACHINE) {
@@ -40,7 +41,7 @@ $netrc=[string]::Format("{0}\_netrc",$Env:HOME);
};
[Environment]::SetEnvironmentVariable("CI_NETRC_PASSWORD",$null);
[Environment]::SetEnvironmentVariable("CI_SCRIPT",$null);
if ([Environment]::GetEnvironmentVariable('CI_WORKSPACE')) { cd "$env:CI_WORKSPACE" };
cd "/woodpecker/some";
Write-Output ('+ "echo %PATH%"');
& echo %PATH%; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE}
@@ -50,12 +51,17 @@ Write-Output ('+ "go build"');
Write-Output ('+ "go test"');
& go test; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE}
`,
},
}
for _, test := range testdata {
script := generateScriptWindows(test.from)
script := generateScriptWindows(test.from, "/woodpecker/some")
assert.EqualValues(t, test.want, script, "Want encoded script for %s", test.from)
}
}
func TestSetupScriptWinProtoParse(t *testing.T) {
// just ensure that we have a working `setupScriptWinTmpl` on runntime
_, err := template.New("").Parse(setupScriptWinProto)
assert.NoError(t, err)
}