Skip to content

Commit

Permalink
Add snapper backend unit test
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <[email protected]>
  • Loading branch information
davidcassany committed Dec 17, 2024
1 parent 60d41d4 commit b9fde7a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
5 changes: 0 additions & 5 deletions pkg/snapshotter/snapper-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ func (s snapperBackend) CommitSnapshot(rootDir string, snapshot *types.Snapshot)
return err
}

/*if s.activeID == 0 && s.currentID == 0 {
// Snapper does not support modifying a snapshot from a host not having a configured snapper
// and this is the case for the installation media
return s.btrfs.CommitSnapshot(rootDir, snapshot)
}*/
args := []string{
"modify", "--read-only", "--default", "--userdata",
fmt.Sprintf("%s=,%s=", installProgress, updateProgress), strconv.Itoa(snapshot.ID),
Expand Down
68 changes: 65 additions & 3 deletions pkg/snapshotter/snapper-backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,71 @@ var _ = Describe("snapperBackend", Label("snapshotter", " btrfs"), func() {
})

Describe("in a not initiated environment", func() {
// Probe and InitBtrfsPartition methods are just borrowed from the btrfs
// backend hence those are not nested here as this would be the same exact
// test as in btrfs-backend.go
It("probes a non initiated environment, missing subvolumes", func() {
backend := snapshotter.NewSubvolumeBackend(cfg, btrfsCfg, 4)
stat, err := backend.Probe(statePart.Path, statePart.MountPoint)
Expect(err).NotTo(HaveOccurred())
Expect(stat.ActiveID).To(Equal(0))
Expect(len(runner.GetCmds())).To(Equal(0))
runner.ClearCmds()
})

It("initalizes the btrfs partition", func() {
backend := snapshotter.NewSubvolumeBackend(cfg, btrfsCfg, 4)
Expect(backend.InitBrfsPartition(rootDir)).To(Succeed())
Expect(runner.MatchMilestones([][]string{
{"btrfs", "quota", "enable"},
{"btrfs", "subvolume", "create"},
{"btrfs", "qgroup", "create"},
{"/usr/lib/snapper/installation-helper", "--root-prefix"},
})).To(Succeed())
})

It("partition initialization fails enabling quota", func() {
errMsg := "btrfs quota failed"
sEffects = append(sEffects, &sideEffect{cmd: "btrfs quota enable", errorMsg: errMsg})
backend := snapshotter.NewSubvolumeBackend(cfg, btrfsCfg, 4)
Expect(backend.InitBrfsPartition(rootDir)).NotTo(Succeed())
Expect(runner.MatchMilestones([][]string{
{"btrfs", "quota", "enable"},
})).To(Succeed())
})

It("partition initialization fails creating subvolume", func() {
errMsg := "subvolume create failed"
sEffects = append(sEffects, &sideEffect{cmd: "btrfs subvolume create", errorMsg: errMsg})
backend := snapshotter.NewSubvolumeBackend(cfg, btrfsCfg, 4)
Expect(backend.InitBrfsPartition(rootDir)).NotTo(Succeed())
Expect(runner.MatchMilestones([][]string{
{"btrfs", "quota", "enable"},
{"btrfs", "subvolume", "create"},
})).To(Succeed())
})

It("partition initialization fails setting quota group", func() {
errMsg := "qgroup create failed"
sEffects = append(sEffects, &sideEffect{cmd: "btrfs qgroup create", errorMsg: errMsg})
backend := snapshotter.NewSubvolumeBackend(cfg, btrfsCfg, 4)
Expect(backend.InitBrfsPartition(rootDir)).NotTo(Succeed())
Expect(runner.MatchMilestones([][]string{
{"btrfs", "quota", "enable"},
{"btrfs", "subvolume", "create"},
{"btrfs", "qgroup", "create"},
})).To(Succeed())
})

It("partition initialization fails running snapper's installation helper", func() {
errMsg := "/usr/lib/snapper/installation-helper failed"
sEffects = append(sEffects, &sideEffect{cmd: "/usr/lib/snapper/installation-helper --root-prefix", errorMsg: errMsg})
backend := snapshotter.NewSubvolumeBackend(cfg, btrfsCfg, 4)
Expect(backend.InitBrfsPartition(rootDir)).NotTo(Succeed())
Expect(runner.MatchMilestones([][]string{
{"btrfs", "quota", "enable"},
{"btrfs", "subvolume", "create"},
{"btrfs", "qgroup", "create"},
{"/usr/lib/snapper/installation-helper", "--root-prefix"},
})).To(Succeed())
})

Describe("snapshot created", func() {
var err error
Expand Down

0 comments on commit b9fde7a

Please sign in to comment.