Skip to content

Commit

Permalink
test: separate image creation and verification
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomanski committed Jun 24, 2023
1 parent 4962b64 commit 93bbe72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jobs:

- name: Integration test
# The test need sudo to be able to mount/umount
run: sudo go test -v --tags=integration -coverprofile=coverage_integration.txt -covermode=atomic .
run: sudo -E go test -v --tags=integration -coverprofile=coverage_integration.txt -covermode=atomic .
env:
ISO_WRITER_TEST_IMAGE: /tmp/writer_test

- name: Upload coverage to Codecov
if: matrix.go == '1.20'
Expand Down
27 changes: 18 additions & 9 deletions image_writer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"github.com/stretchr/testify/assert"
)

// Identical to TestWriterAndMountWithAddLocal, except it uses
// AddFile to add files with a constant string in them.
func TestWriterAndMount(t *testing.T) {
//
// Image creation
//
var writerTestImagePath = os.Getenv("ISO_WRITER_TEST_IMAGE")

func FooWriterCreate(t *testing.T) {
if !assert.NotEmpty(t, writerTestImagePath) {
t.FailNow()
}

// create a new image writer and prepare for cleanup
w, err := NewWriter()
Expand All @@ -38,12 +38,21 @@ func TestWriterAndMount(t *testing.T) {
}

// write test image
f, err := os.CreateTemp(os.TempDir(), "iso9660_golang_test")
f, err := os.Create(writerTestImagePath)
assert.NoError(t, err)
defer os.Remove(f.Name())

err = w.WriteTo(f, "testvolume")
assert.NoError(t, err)
}

// Identical to TestWriterAndMountWithAddLocal, except it uses
// AddFile to add files with a constant string in them.
func TestWriterVerify(t *testing.T) {
FooWriterCreate(t)

if !assert.NotEmpty(t, writerTestImagePath) {
t.FailNow()
}

//
// Image mounting
Expand All @@ -59,7 +68,7 @@ func TestWriterAndMount(t *testing.T) {
}()

// execute mount
mountCmd := exec.Command("mount", "-t", "iso9660", f.Name(), mountDir)
mountCmd := exec.Command("mount", "-t", "iso9660", writerTestImagePath, mountDir)
output, err := mountCmd.CombinedOutput()
assert.NoError(t, err, "failed to mount the ISO image: %v\n%s", err, string(output))

Expand Down

0 comments on commit 93bbe72

Please sign in to comment.