Files
seaweedfs/test/testutil/helpers_test.go
T
Chris Lu a1b3131bf6 test: handle unsupported catalog clients in S3 Tables CI (#12023)
test: distinguish unsupported catalog clients from S3 Tables failures
2026-10-23 22:40:54 -07:00

40 lines
989 B
Go

package testutil
import (
"errors"
"fmt"
"os"
"os/exec"
"strconv"
"testing"
)
func TestIsIllegalInstruction(t *testing.T) {
if code := os.Getenv("SEAWEEDFS_TEST_EXIT_CODE"); code != "" {
status, _ := strconv.Atoi(code)
os.Exit(status)
}
for _, tc := range []struct {
name string
code string
want bool
}{
{"illegal instruction", "132", true},
{"ordinary failure", "1", false},
{"out of memory", "137", false},
} {
t.Run(tc.name, func(t *testing.T) {
cmd := exec.Command(os.Args[0], "-test.run=^TestIsIllegalInstruction$")
cmd.Env = append(os.Environ(), "SEAWEEDFS_TEST_EXIT_CODE="+tc.code)
err := cmd.Run()
if got := IsIllegalInstruction(fmt.Errorf("docker run: %w", err)); got != tc.want {
t.Fatalf("IsIllegalInstruction(%v) = %v, want %v", err, got, tc.want)
}
})
}
if IsIllegalInstruction(nil) || IsIllegalInstruction(errors.New("exit status 132")) {
t.Fatal("non-process errors must not be treated as illegal instructions")
}
}