Skip to content

Commit

Permalink
Merge pull request #74 from kairos-io/allow-running-tests-locally
Browse files Browse the repository at this point in the history
Fix persmissions of the build directory after creating it
  • Loading branch information
jimmykarily authored Oct 23, 2024
2 parents a6ae7c9 + 159f8ad commit 076e3d9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
10 changes: 4 additions & 6 deletions tests/e2e/arm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import (

var _ = Describe("ARM image generation", Label("arm"), func() {
Context("build", func() {

tempDir := ""
var tempDir string
var err error

BeforeEach(func() {
t, err := os.MkdirTemp("", "")
tempDir, err = os.MkdirTemp("", "auroraboot-test-")
Expect(err).ToNot(HaveOccurred())

tempDir = t

err = WriteConfig("test", t)
err = WriteConfig("test", tempDir)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
25 changes: 11 additions & 14 deletions tests/e2e/disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import (
var _ = Describe("Disk image generation", Label("raw-disks"), func() {

Context("build from an ISO", func() {

tempDir := ""
var tempDir string
var err error

BeforeEach(func() {
t, err := os.MkdirTemp("", "")
tempDir, err = os.MkdirTemp("", "auroraboot-test-")
Expect(err).ToNot(HaveOccurred())

tempDir = t

err = WriteConfig("test", t)
err = WriteConfig("test", tempDir)
Expect(err).ToNot(HaveOccurred())
})

Expand Down Expand Up @@ -119,10 +117,12 @@ var _ = Describe("Disk image generation", Label("raw-disks"), func() {
})

Context("build from a container image", func() {
var tempDir string
var err error
var config string

tempDir := ""

config := `#cloud-config
BeforeEach(func() {
config = `#cloud-config
hostname: kairos-{{ trunc 4 .MachineID }}
Expand Down Expand Up @@ -157,13 +157,10 @@ stages:
- |
[[ "$(echo "$(df -h | grep COS_PERSISTENT)" | awk '{print $5}' | tr -d '%')" -ne 100 ]] && resize2fs /dev/disk/by-label/COS_PERSISTENT`

BeforeEach(func() {
t, err := os.MkdirTemp("", "")
tempDir, err = os.MkdirTemp("", "auroraboot-test-")
Expect(err).ToNot(HaveOccurred())

tempDir = t

err = WriteConfig(config, t)
err = WriteConfig(config, tempDir)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
11 changes: 6 additions & 5 deletions tests/e2e/iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (

var _ = Describe("ISO image generation", Label("iso"), func() {
Context("build", func() {
var tempDir string
var err error

tempDir := ""
BeforeEach(func() {
t, err := os.MkdirTemp("", "")
tempDir, err = os.MkdirTemp("", "auroraboot-test-")
Expect(err).ToNot(HaveOccurred())

tempDir = t

err = WriteConfig("test", t)
err = WriteConfig("test", tempDir)
Expect(err).ToNot(HaveOccurred())
})

Expand All @@ -44,6 +43,7 @@ var _ = Describe("ISO image generation", Label("iso"), func() {
_, err = os.Stat(filepath.Join(tempDir, "build/build/kairos.iso"))
Expect(err).ToNot(HaveOccurred())
})

It("fails if cloud config is empty", func() {
err := WriteConfig("", tempDir)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -54,6 +54,7 @@ var _ = Describe("ISO image generation", Label("iso"), func() {
--cloud-config /config.yaml \
--set "state_dir=/tmp/auroraboot"`), tempDir)
Expect(err).To(HaveOccurred(), out)
Expect(out).To(MatchRegexp("cloud config set but contents are empty"))
})

It("generate an iso image from a release", func() {
Expand Down
12 changes: 11 additions & 1 deletion tests/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ func TestSuite(t *testing.T) {

func RunAurora(cmd, dir string) (string, error) {
runCmd := fmt.Sprintf(`cd %s && docker run --privileged -v "$PWD"/config.yaml:/config.yaml -v "$PWD"/build:/tmp/auroraboot -v /var/run/docker.sock:/var/run/docker.sock --rm %s --debug %s`, dir, auroraBootImage, cmd)
return utils.SH(runCmd)
cmdOut, cmdErr := utils.SH(runCmd)
if cmdErr != nil {
return cmdOut, cmdErr
}

// Fix permissions of build directory to allow running tests locally rootless
permCmd := fmt.Sprintf(`cd %s && docker run --privileged -e USERID=$(id -u) -e GROUPID=$(id -g) --entrypoint /usr/bin/sh -v "$PWD"/build:/tmp/auroraboot --rm %s -c 'chown -R $USERID:$GROUPID /tmp/auroraboot'`, dir, auroraBootImage)
permOut, permErr := utils.SH(permCmd)
Expect(permErr).ToNot(HaveOccurred(), permOut)

return cmdOut, cmdErr
}

func PullImage(image string) (string, error) {
Expand Down

0 comments on commit 076e3d9

Please sign in to comment.