Skip to content

Commit

Permalink
Improve test coverage and fix recovery image label setting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcassany committed Sep 26, 2023
1 parent 541c970 commit 2717827
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/types/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c Config) LoadInstallState() (*InstallState, error) {
installState.Partitions[constants.RecoveryPartName].FSLabel = constants.RecoveryLabel
recovery := installState.Partitions[constants.RecoveryPartName]
if recovery.Images[constants.RecoveryImgName] != nil && recovery.Images[constants.RecoveryImgName].Label == "" {
recovery.Images[constants.RecoveryImgName].Label = constants.RecoveryLabel
recovery.Images[constants.RecoveryImgName].Label = constants.SystemLabel
}
}
if installState.Partitions[constants.StatePartName] != nil && installState.Partitions[constants.StatePartName].FSLabel == "" {
Expand Down
26 changes: 22 additions & 4 deletions pkg/types/v1/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,41 @@ var _ = Describe("Types", Label("types", "config"), func() {
Expect(err).Should(HaveOccurred())
})
It("Loads a state file with missing fields", func() {
incompleteState := "# Autogenerated file by elemental client, do not edit\n\n"
incompleteState += "date: \"2023-09-22T16:02:07Z\"\n"
incompleteState += "state:\n"
incompleteState := "state:\n"
incompleteState += " active:\n"
incompleteState += " source: dir:///tmp/new_root\n"
incompleteState += " fs: ext2\n"
incompleteState += " passive: null\n"
incompleteState += "recovery:\n"
incompleteState += " recovery:\n"
incompleteState += " source: dir:///tmp/new_root\n"
Expect(fs.WriteFile(statePath, []byte(incompleteState), constants.FilePerm)).To(Succeed())

loadedInstallState, err := config.LoadInstallState()
Expect(err).ShouldNot(HaveOccurred())

Expect(loadedInstallState.Partitions[constants.RecoveryPartName]).To(BeNil())
Expect(loadedInstallState.Partitions[constants.RecoveryPartName].FSLabel).To(Equal(constants.RecoveryLabel))
Expect(loadedInstallState.Partitions[constants.RecoveryPartName].Images[constants.RecoveryImgName].Label).To(Equal(constants.SystemLabel))
Expect(loadedInstallState.Partitions[constants.StatePartName].FSLabel).To(Equal(constants.StateLabel))
Expect(loadedInstallState.Partitions[constants.StatePartName].Images[constants.PassiveImgName]).To(BeNil())
Expect(loadedInstallState.Partitions[constants.StatePartName].Images[constants.ActiveImgName].Label).To(Equal(constants.ActiveLabel))
})
It("Loads a state file with other missing fields", func() {
incompleteState := "state:\n"
incompleteState += " passive:\n"
incompleteState += " source: dir:///tmp/new_root\n"
incompleteState += " fs: ext2\n"
incompleteState += " active: null\n"
Expect(fs.WriteFile(statePath, []byte(incompleteState), constants.FilePerm)).To(Succeed())

loadedInstallState, err := config.LoadInstallState()
Expect(err).ShouldNot(HaveOccurred())

Expect(loadedInstallState.Partitions[constants.RecoveryPartName]).To(BeNil())
Expect(loadedInstallState.Partitions[constants.StatePartName].FSLabel).To(Equal(constants.StateLabel))
Expect(loadedInstallState.Partitions[constants.StatePartName].Images[constants.ActiveImgName]).To(BeNil())
Expect(loadedInstallState.Partitions[constants.StatePartName].Images[constants.PassiveImgName].Label).To(Equal(constants.PassiveLabel))
})
})
Describe("ElementalPartitions", func() {
var p v1.PartitionList
Expand Down

0 comments on commit 2717827

Please sign in to comment.