Skip to content

Commit

Permalink
e2e.contrasttest: allow patchManifest to execute different PatchManif…
Browse files Browse the repository at this point in the history
…estFunc for modification
  • Loading branch information
jmxnzo committed Dec 23, 2024
1 parent 35ab185 commit f5bf718
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions e2e/internal/contrasttest/contrasttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,28 @@ func (ct *ContrastTest) Generate(t *testing.T) {
require.NoError(err)
require.NotEmpty(hash, "expected apply to fill coordinator policy hash")

ct.patchReferenceValues(t, ct.Platform)
ct.PatchManifest(t, ct.Platform, patchReferenceValues)
}

// patchReferenceValues modifies the manifest to contain multiple reference values for testing
// cases with multiple validators, as well as filling in bare-metal SNP-specific values.
func (ct *ContrastTest) patchReferenceValues(t *testing.T, platform platforms.Platform) {
// PatchManifestFunc defines a variadic function type allowing the current manifest to be modified,
// based on the active platform and additional variadic arguments for extended customization.
type PatchManifestFunc func(*manifest.Manifest, platforms.Platform, ...interface{})

// PatchManifest modifies the current manifest by executing a provided PatchManifestFunc on it.
func (ct *ContrastTest) PatchManifest(t *testing.T, platform platforms.Platform, patchFn PatchManifestFunc, args ...interface{}) {
manifestBytes, err := os.ReadFile(ct.WorkDir + "/manifest.json")
require.NoError(t, err)
var m manifest.Manifest
require.NoError(t, json.Unmarshal(manifestBytes, &m))
patchFn(&m, platform, args...)
manifestBytes, err = json.Marshal(m)
require.NoError(t, err)
require.NoError(t, os.WriteFile(ct.WorkDir+"/manifest.json", manifestBytes, 0o644))
}

// patchReferenceValues modifies the manifest to contain multiple reference values for testing
// cases with multiple validators, as well as filling in bare-metal SNP-specific values.
func patchReferenceValues(m *manifest.Manifest, platform platforms.Platform, _ ...interface{}) {
switch platform {
case platforms.AKSCloudHypervisorSNP:
// Duplicate the reference values to test multiple validators by having at least 2.
Expand Down Expand Up @@ -221,10 +232,6 @@ func (ct *ContrastTest) patchReferenceValues(t *testing.T, platform platforms.Pl
m.ReferenceValues.TDX[i] = tdx
}
}

manifestBytes, err = json.Marshal(m)
require.NoError(t, err)
require.NoError(t, os.WriteFile(ct.WorkDir+"/manifest.json", manifestBytes, 0o644))
}

// Apply the generated resources to the Kubernetes test environment.
Expand Down

0 comments on commit f5bf718

Please sign in to comment.