Skip to content

Commit

Permalink
Sort combustion scripts before appending them to the combustion scrip…
Browse files Browse the repository at this point in the history
…t file
  • Loading branch information
jdob committed Nov 2, 2023
1 parent 142ad00 commit a34b873
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"text/template"

"github.com/suse-edge/edge-image-builder/pkg/config"
Expand Down Expand Up @@ -133,6 +134,9 @@ func (b *Builder) generateCombustionScript() error {
}

// Add a call to each script that was added to the combustion directory
// We may need a better way of specifying the order, but for now use alphabetical
// so we have at least some determinism
slices.Sort(b.combustionScripts)
for _, filename := range b.combustionScripts {
_, err = fmt.Fprintln(scriptFile, "./"+filename)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,17 @@ func TestGenerateCombustionScript(t *testing.T) {
// Verify
require.NoError(t, err)

// - check the script contents itself
scriptBytes, err := os.ReadFile(filepath.Join(builder.combustionDir, "script"))
require.NoError(t, err)
scriptData := string(scriptBytes)
assert.Contains(t, scriptData, "#!/bin/bash")
assert.Contains(t, scriptData, "foo.sh")
assert.Contains(t, scriptData, "bar.sh")

// - ensure the order of the scripts is alphabetical
assert.Equal(t, "bar.sh", builder.combustionScripts[0])
assert.Equal(t, "foo.sh", builder.combustionScripts[1])
}

func TestWriteCombustionFile(t *testing.T) {
Expand Down

0 comments on commit a34b873

Please sign in to comment.