Skip to content

Commit

Permalink
integration: fix panic on platforms without embedded DB support
Browse files Browse the repository at this point in the history
This is an embarrassing one that I should have thought through. Now,
nothing should be panicking from the package block or an init function.

Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Apr 12, 2024
1 parent 1a31ebd commit b28ae8c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
7 changes: 7 additions & 0 deletions test/integration/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ func startEmbedded(t testing.TB) func() {
// the logs.
t.Log("⚠️ PostgreSQL refuses to start as root; this will almost certainly not work ⚠️")
}
if embedDB.Arch == "" {
t.Logf(`⚠️ unsupported platform "%s/%s"; see https://mvnrepository.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom`,
runtime.GOOS, runtime.GOARCH,
)
t.Log("See the test/integration documentation for how to specify an external database.")
t.FailNow()
}
return func() {
pkgDB = &Engine{}
if err := pkgDB.Start(t); err != nil {
Expand Down
24 changes: 14 additions & 10 deletions test/integration/fixup_linux.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package integration

import (
"fmt"
"os"
"runtime"
"strings"
"syscall"
)

// the zonkyio/embedded-postgres-binaries project produces
// arm binaries with the following name schema:
// 32bit: arm32v6 / arm32v7
// 64bit (aarch64): arm64v8
// The zonkyio/embedded-postgres-binaries project produces ARM binaries with the
// following name schema:
//
// - 32bit : arm32v6 / arm32v7
// - 64bit (aarch64): arm64v8

func findArch() (arch string) {
arch = runtime.GOARCH
Expand All @@ -23,7 +23,10 @@ func findArch() (arch string) {
case "arm":
var u syscall.Utsname
if err := syscall.Uname(&u); err != nil {
panic(err)
// Not sure why this would happen? Try to use the lowest revision
// and let it crash otherwise.
arch += "32v6"
break
}
t := make([]byte, 0, len(u.Machine[:]))
for _, b := range u.Machine[:] {
Expand All @@ -38,14 +41,15 @@ func findArch() (arch string) {
arch += "32v7"
case strings.HasPrefix(mach, "armv6"):
arch += "32v6"
default:
return ""
}
case "ppc64le": // OK
case "amd64": // OK
default:
panic(fmt.Sprintf(
`unsupported platform "%s/%s"; see https://mvnrepository.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom`,
runtime.GOOS, runtime.GOARCH,
))
// Will cause the [startEmbedded] function to print a warning and fail
// the test if the environment requires an embedded database.
return ""
}
// If on alpine:
if _, err := os.Stat("/etc/alpine-release"); err == nil {
Expand Down
8 changes: 3 additions & 5 deletions test/integration/fixup_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package integration

import (
"fmt"
"runtime"
)

Expand All @@ -29,10 +28,9 @@ func findArch() (arch string) {
default:
}
if !ok {
panic(fmt.Sprintf(
`unsupported platform "%s/%s"; see https://mvnrepository.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom`,
runtime.GOOS, runtime.GOARCH,
))
// Will cause the [startEmbedded] function to print a warning and fail
// the test if the environment requires an embedded database.
return ""
}
return arch
}

0 comments on commit b28ae8c

Please sign in to comment.