1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-11-29 21:48:14 +02:00

local backend test shells if unknown (#5570)

currently if we don't know the shell we just assume posix.
this adds a small test, to ensure it is and fail gracefully before doing weird stuff.

## Test Conf

```yaml
skip_clone: true
steps:
  build:
    image: "true"
    commands:
      - echo "building..."
```
This commit is contained in:
6543
2025-10-01 12:29:48 +02:00
committed by GitHub
parent 22ffe93734
commit 9edaa1e0c3
3 changed files with 108 additions and 9 deletions

View File

@@ -16,6 +16,7 @@ package local
import (
"os"
"runtime"
"strings"
"testing"
@@ -137,3 +138,35 @@ echo new line
assert.Equal(t, "-e", args[0])
})
}
func TestProbeShellIsPosix(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("skipping posix shell tests on non-linux system")
}
t.Run("valid posix shells", func(t *testing.T) {
err := probeShellIsPosix("sh")
assert.NoError(t, err)
})
t.Run("invalid shell", func(t *testing.T) {
err := probeShellIsPosix("nonexistentshell12345")
if assert.ErrorIs(t, err, &ErrNoPosixShell{}) {
assert.Equal(t,
`Shell "nonexistentshell12345" was assumed to be a Posix shell, but test failed: exec: "nonexistentshell12345": executable file not found in $PATH
(if you want support for it, please open an issue)`,
err.Error())
}
})
t.Run("non-posix shell", func(t *testing.T) {
// nologin won't understand posix syntax
err := probeShellIsPosix("true")
if assert.ErrorIs(t, err, &ErrNoPosixShell{}) {
assert.Equal(t,
`Shell "true" was assumed to be a Posix shell, but test failed: unexpected output returned: ""
(if you want support for it, please open an issue)`,
err.Error())
}
})
}