Skip to content

Commit

Permalink
Merge branch 'main' into 2110-use-node-name-instead-of-hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 authored Nov 4, 2023
2 parents 7f9e1e5 + 6c2157a commit bb8cd18
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/pkg/packager/composer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,14 @@ func (ic *ImportChain) MergeVariables(existing []types.ZarfPackageVariable) (mer
return v1.Name == v2.Name
}

merged = helpers.MergeSlices(existing, merged, exists)
node := ic.head
node := ic.tail
for node != nil {
// merge the vars
merged = helpers.MergeSlices(node.vars, merged, exists)
node = node.next
node = node.prev
}
merged = helpers.MergeSlices(existing, merged, exists)

return merged
}

Expand All @@ -272,13 +273,14 @@ func (ic *ImportChain) MergeConstants(existing []types.ZarfPackageConstant) (mer
return c1.Name == c2.Name
}

merged = helpers.MergeSlices(existing, merged, exists)
node := ic.head
node := ic.tail
for node != nil {
// merge the consts
merged = helpers.MergeSlices(node.consts, merged, exists)
node = node.next
node = node.prev
}
merged = helpers.MergeSlices(existing, merged, exists)

return merged
}

Expand Down
180 changes: 180 additions & 0 deletions src/pkg/packager/composer/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,186 @@ func TestCompose(t *testing.T) {
}
}

func TestMerging(t *testing.T) {
t.Parallel()

type testCase struct {
name string
ic *ImportChain
existingVars []types.ZarfPackageVariable
existingConsts []types.ZarfPackageConstant
expectedVars []types.ZarfPackageVariable
expectedConsts []types.ZarfPackageConstant
}

head := Node{
vars: []types.ZarfPackageVariable{
{
Name: "TEST",
Default: "head",
},
{
Name: "HEAD",
},
},
consts: []types.ZarfPackageConstant{
{
Name: "TEST",
Value: "head",
},
{
Name: "HEAD",
},
},
}
tail := Node{
vars: []types.ZarfPackageVariable{
{
Name: "TEST",
Default: "tail",
},
{
Name: "TAIL",
},
},
consts: []types.ZarfPackageConstant{
{
Name: "TEST",
Value: "tail",
},
{
Name: "TAIL",
},
},
}
head.next = &tail
tail.prev = &head
testIC := &ImportChain{head: &head, tail: &tail}

testCases := []testCase{
{
name: "empty-ic",
ic: &ImportChain{},
existingVars: []types.ZarfPackageVariable{
{
Name: "TEST",
},
},
existingConsts: []types.ZarfPackageConstant{
{
Name: "TEST",
},
},
expectedVars: []types.ZarfPackageVariable{
{
Name: "TEST",
},
},
expectedConsts: []types.ZarfPackageConstant{
{
Name: "TEST",
},
},
},
{
name: "no-existing",
ic: testIC,
existingVars: []types.ZarfPackageVariable{},
existingConsts: []types.ZarfPackageConstant{},
expectedVars: []types.ZarfPackageVariable{
{
Name: "TEST",
Default: "head",
},
{
Name: "HEAD",
},
{
Name: "TAIL",
},
},
expectedConsts: []types.ZarfPackageConstant{
{
Name: "TEST",
Value: "head",
},
{
Name: "HEAD",
},
{
Name: "TAIL",
},
},
},
{
name: "with-existing",
ic: testIC,
existingVars: []types.ZarfPackageVariable{
{
Name: "TEST",
Default: "existing",
},
{
Name: "EXISTING",
},
},
existingConsts: []types.ZarfPackageConstant{
{
Name: "TEST",
Value: "existing",
},
{
Name: "EXISTING",
},
},
expectedVars: []types.ZarfPackageVariable{
{
Name: "TEST",
Default: "existing",
},
{
Name: "EXISTING",
},
{
Name: "HEAD",
},
{
Name: "TAIL",
},
},
expectedConsts: []types.ZarfPackageConstant{
{
Name: "TEST",
Value: "existing",
},
{
Name: "EXISTING",
},
{
Name: "HEAD",
},
{
Name: "TAIL",
},
},
},
}

for _, testCase := range testCases {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

mergedVars := testCase.ic.MergeVariables(testCase.existingVars)
require.EqualValues(t, testCase.expectedVars, mergedVars)

mergedConsts := testCase.ic.MergeConstants(testCase.existingConsts)
require.EqualValues(t, testCase.expectedConsts, mergedConsts)
})
}
}

func createChainFromSlice(components []types.ZarfComponent) (ic *ImportChain) {
ic = &ImportChain{}

Expand Down

0 comments on commit bb8cd18

Please sign in to comment.