Skip to content

Commit

Permalink
move uuid comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
amritakohli committed Dec 20, 2024
1 parent 9466234 commit 6bf49fc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions toolkit/tools/pkg/imagecustomizerlib/imagehistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,21 @@ func TestAddImageHistory(t *testing.T) {
err = addImageHistory(chroot, expectedUuid, testDir, expectedVersion, expectedDate, &config)
assert.NoError(t, err, "addImageHistory should not return an error")

verifyHistoryFile(t, 2, expectedUuid, expectedVersion, expectedDate, config, historyFilePath)
allHistory := verifyHistoryFile(t, 2, expectedUuid, expectedVersion, expectedDate, config, historyFilePath)

// Verify the imageUuid is unique for each entry
assert.NotEqual(t, allHistory[0].ImageUuid, allHistory[1].ImageUuid, "imageUuid should be different for each entry")

}

func verifyHistoryFile(t *testing.T, expectedEntries int, expectedUuid string, expectedVersion string, expectedDate string, config imagecustomizerapi.Config, historyFilePath string) {
func verifyHistoryFile(t *testing.T, expectedEntries int, expectedUuid string, expectedVersion string, expectedDate string, config imagecustomizerapi.Config, historyFilePath string) (allHistory []ImageHistory) {
exists, err := file.PathExists(historyFilePath)
assert.NoError(t, err, "error checking history file existence")
assert.True(t, exists, "history file should exist")

historyContent, err := os.ReadFile(historyFilePath)
assert.NoError(t, err, "error reading history file")

var allHistory []ImageHistory
err = json.Unmarshal(historyContent, &allHistory)
assert.NoError(t, err, "error unmarshalling history content")
assert.Len(t, allHistory, expectedEntries, "history file should contain the expected number of entries")
Expand All @@ -83,16 +86,13 @@ func verifyHistoryFile(t *testing.T, expectedEntries int, expectedUuid string, e
// Since the config is modified its entirety won't be an exact match; picking one consistent field to verify
assert.Equal(t, config.OS.BootLoader.ResetType, entry.Config.OS.BootLoader.ResetType, "config bootloader reset type should match")

// Verify the imageUuid is unique for each entry
if expectedEntries == 2 {
assert.NotEqual(t, allHistory[0].ImageUuid, allHistory[1].ImageUuid, "imageUuid should be different for each entry")
}

verifyAdditionalFilesHashes(entry.Config.OS.AdditionalFiles, t)
verifyAdditionalDirsHashes(entry.Config.OS.AdditionalDirs, t)
verifyScriptsHashes(entry.Config.Scripts.PostCustomization, t)
verifyScriptsHashes(entry.Config.Scripts.FinalizeCustomization, t)
verifySshPublicKeysRedacted(entry.Config.OS.Users, t)

return
}

func verifySshPublicKeysRedacted(users []imagecustomizerapi.User, t *testing.T) {
Expand Down

0 comments on commit 6bf49fc

Please sign in to comment.