forked from osbuild/bootc-image-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit checks early if cross architecture building support via `qemu-user-static` (or similar tooling) is missing and errors in a more user friendly way. Note that there is no integration test right now because testing this for real requires mutating the very global state of `echo 0 > /proc/sys/fs/binfmt_misc/qemu-aarch64` which would make the test non-parallelizable and even risks failing other cross-arch tests running on the same host (because binfmt-misc is not namespaced (yet)).
- Loading branch information
1 parent
61ef43a
commit 795ef0c
Showing
7 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
func main() { | ||
println("ok") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package setup | ||
|
||
var ValidateCanRunTargetArch = validateCanRunTargetArch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package setup_test | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/osbuild/bootc-image-builder/bib/internal/setup" | ||
) | ||
|
||
func TestValidateCanRunTargetArchTrivial(t *testing.T) { | ||
for _, arch := range []string{runtime.GOARCH, ""} { | ||
err := setup.ValidateCanRunTargetArch(arch) | ||
assert.NoError(t, err) | ||
} | ||
} | ||
|
||
func TestValidateCanRunTargetArchUnsupportedCanary(t *testing.T) { | ||
var logbuf bytes.Buffer | ||
logrus.SetOutput(&logbuf) | ||
|
||
err := setup.ValidateCanRunTargetArch("unsupported-arch") | ||
assert.NoError(t, err) | ||
assert.Contains(t, logbuf.String(), `level=warning msg="cannot check architecture support for unsupported-arch: no canary binary found"`) | ||
} | ||
|
||
func makeFakeCanary(t *testing.T, content string) { | ||
tmpdir := t.TempDir() | ||
t.Setenv("PATH", os.Getenv("PATH")+":"+tmpdir) | ||
err := os.WriteFile(filepath.Join(tmpdir, "bib-canary-fakearch"), []byte(content), 0755) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestValidateCanRunTargetArchHappy(t *testing.T) { | ||
var logbuf bytes.Buffer | ||
logrus.SetOutput(&logbuf) | ||
|
||
makeFakeCanary(t, "#!/bin/sh\necho ok") | ||
|
||
err := setup.ValidateCanRunTargetArch("fakearch") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "", logbuf.String()) | ||
} | ||
|
||
func TestValidateCanRunTargetArchExecFormatError(t *testing.T) { | ||
makeFakeCanary(t, "") | ||
|
||
err := setup.ValidateCanRunTargetArch("fakearch") | ||
assert.ErrorContains(t, err, `cannot run canary binary for "fakearch", do you have 'qemu-user-static' installed?`) | ||
assert.ErrorContains(t, err, `: exec format error`) | ||
} | ||
|
||
func TestValidateCanRunTargetArchUnexpectedOutput(t *testing.T) { | ||
makeFakeCanary(t, "#!/bin/sh\necho xxx") | ||
|
||
err := setup.ValidateCanRunTargetArch("fakearch") | ||
assert.ErrorContains(t, err, `internal error: unexpected output`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters