Skip to content

Commit

Permalink
Include integration tests for the 'state' subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Sep 18, 2024
1 parent d635b6c commit f0a4c55
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
14 changes: 11 additions & 3 deletions tests/recovery/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package elemental_test
import (
"fmt"

"gopkg.in/yaml.v3"

sut "github.com/rancher/elemental-toolkit/v2/tests/vm"

comm "github.com/rancher/elemental-toolkit/v2/tests/common"
Expand Down Expand Up @@ -88,14 +90,20 @@ var _ = Describe("Elemental Recovery upgrade tests", func() {
Expect(err).ToNot(HaveOccurred())
Expect(out).Should(ContainSubstring("Recovery upgrade completed"))

// TODO: Check state.yaml changed
By("check state file incluldes the 'upgrade-recovery' action on the recovery image")
stateStr, err := s.Command(s.ElementalCmd("state"))
Expect(err).NotTo(HaveOccurred())

state := map[string]interface{}{}
Expect(yaml.Unmarshal([]byte(stateStr), state)).
To(Succeed())
Expect(state["recovery"].(map[string]interface{})["recovery"].(map[string]interface{})["fromAction"]).
To(Equal("upgrade-recovery"))

By("booting into recovery to check the OS version")
err = s.ChangeBootOnce(sut.Recovery)
Expect(err).ToNot(HaveOccurred())

// TODO: verify state.yaml matches expectations

s.Reboot()
s.EventuallyBootedFrom(sut.Recovery)

Expand Down
22 changes: 22 additions & 0 deletions tests/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package elemental_test
import (
"fmt"

"gopkg.in/yaml.v3"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -71,6 +73,16 @@ var _ = Describe("Elemental Feature tests", func() {
_, err = s.Command("cat /after-reset-chroot")
Expect(err).To(HaveOccurred())

By("check state file includes expected actions for the upgraded snapshot")
stateStr, err := s.Command(s.ElementalCmd("state"))
Expect(err).NotTo(HaveOccurred())

state := map[string]interface{}{}
Expect(yaml.Unmarshal([]byte(stateStr), state)).
To(Succeed())
Expect(state["state"].(map[string]interface{})["snapshots"].(map[interface{}]interface{})[2].(map[string]interface{})["fromAction"]).
To(Equal("upgrade"))

By("booting into recovery to check it is still functional")
Expect(s.ChangeBootOnce(sut.Recovery)).To(Succeed())

Expand All @@ -97,6 +109,16 @@ var _ = Describe("Elemental Feature tests", func() {
s.Reboot()
s.EventuallyBootedFrom(sut.Recovery)

By("check state file incluldes the 'upgrade-recovery' action on the recovery image")
stateStr, err = s.Command(s.ElementalCmd("state"))
Expect(err).NotTo(HaveOccurred())

state = map[string]interface{}{}
Expect(yaml.Unmarshal([]byte(stateStr), state)).
To(Succeed())
Expect(state["recovery"].(map[string]interface{})["recovery"].(map[string]interface{})["fromAction"]).
To(Equal("upgrade-recovery"))

Expect(currentVersion).To(Equal(s.GetOSRelease("TIMESTAMP")))

By("all done, back to active")
Expand Down
24 changes: 23 additions & 1 deletion tests/wait-active/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ limitations under the License.
package elemental_test

import (
"strings"
"time"

"gopkg.in/yaml.v3"

sut "github.com/rancher/elemental-toolkit/v2/tests/vm"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Elemental booting fallback tests", func() {
var _ = Describe("Elemental booting an expandable disk image", func() {
var s *sut.SUT

BeforeEach(func() {
Expand All @@ -38,6 +41,25 @@ var _ = Describe("Elemental booting fallback tests", func() {
out, _ := s.Command("cat /run/cos/active_mode")
return out
}, 15*time.Minute, 10*time.Second).Should(ContainSubstring("1"))

// Check the current elemental has 'state' command, upgrade test runs this code
// against and old image disk image
helpStr, err := s.Command(s.ElementalCmd("help"))
Expect(err).NotTo(HaveOccurred())
if strings.Contains(helpStr, "Shows the install state") {

By("check state file includes expected actions for the first snapshot and recovery image")
stateStr, err := s.Command(s.ElementalCmd("state"))
Expect(err).NotTo(HaveOccurred())

state := map[string]interface{}{}
Expect(yaml.Unmarshal([]byte(stateStr), state)).
To(Succeed())
Expect(state["state"].(map[string]interface{})["snapshots"].(map[interface{}]interface{})[1].(map[string]interface{})["fromAction"]).
To(Equal("reset"))
Expect(state["recovery"].(map[string]interface{})["recovery"].(map[string]interface{})["fromAction"]).
To(Equal("build-disk"))
}
})
})
})

0 comments on commit f0a4c55

Please sign in to comment.