52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package scriptorium_test
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func TestReleaseKitLauncher(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("POSIX shell launcher")
|
|
}
|
|
dir := t.TempDir()
|
|
fake := `#!/bin/sh
|
|
case "$1 $2" in
|
|
'env GOHOSTOS') printf '%s\n' hostos ;;
|
|
'env GOHOSTARCH') printf '%s\n' hostarch ;;
|
|
*) printf '%s\n' "$GOOS" "$GOARCH" "$@"; exit "$FAKE_STATUS" ;;
|
|
esac
|
|
`
|
|
if err := os.WriteFile(filepath.Join(dir, "go"), []byte(fake), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, tc := range []struct {
|
|
name string
|
|
status string
|
|
code int
|
|
}{{"success", "0", 0}, {"failure", "23", 23}} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
cmd := exec.Command("sh", "./releasekit", "publish", "value with spaces")
|
|
cmd.Env = append(os.Environ(), "PATH="+dir, "GOOS=otheros", "GOARCH=otherarch", "FAKE_STATUS="+tc.status)
|
|
output, err := cmd.Output()
|
|
if tc.code == 0 && err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if tc.code != 0 {
|
|
var exit *exec.ExitError
|
|
if !errors.As(err, &exit) || exit.ExitCode() != tc.code {
|
|
t.Fatalf("exit: %v", err)
|
|
}
|
|
}
|
|
want := "hostos\nhostarch\ntool\ngo.maximumdirect.net/releasekit/cmd/releasekit\npublish\nvalue with spaces\n"
|
|
if string(output) != want {
|
|
t.Fatalf("output = %q, want %q", output, want)
|
|
}
|
|
})
|
|
}
|
|
}
|