Skip to content

Commit

Permalink
Improve tests of start-stop-daemon and initctl backup/restore
Browse files Browse the repository at this point in the history
  • Loading branch information
upils committed Feb 23, 2024
1 parent 746f76c commit f2750a0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/statemachine/classic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3105,6 +3105,8 @@ func TestSuccessfulClassicRun(t *testing.T) {
filepath.Join(mountDir, "etc", "ssh", "ssh_host_ecdsa_key"),
filepath.Join(mountDir, "etc", "ssh", "ssh_host_ecdsa_key.pub"),
filepath.Join(mountDir, "usr", "sbin", "policy-rc.d"),
filepath.Join(mountDir, "sbin", "start-stop-daemon.REAL"),
filepath.Join(mountDir, "sbin", "initctl.REAL"),
}
for _, file := range cleaned {
_, err := os.Stat(file)
Expand Down Expand Up @@ -4048,6 +4050,16 @@ func TestStateMachine_installPackages_checkcmds(t *testing.T) {
_, err = os.Create(filepath.Join(stateMachine.tempDirs.chroot, "usr", "sbin", "policy-rc.d"))
asserter.AssertErrNil(err, true)

// create an /sbin/start-stop-daemon in the chroot
err = os.MkdirAll(filepath.Join(stateMachine.tempDirs.chroot, "sbin"), 0755)
asserter.AssertErrNil(err, true)
_, err = os.Create(filepath.Join(stateMachine.tempDirs.chroot, "sbin", "start-stop-daemon"))
asserter.AssertErrNil(err, true)

// create an /sbin/initctl in the chroot
_, err = os.Create(filepath.Join(stateMachine.tempDirs.chroot, "sbin", "initctl"))
asserter.AssertErrNil(err, true)

mockCmder := NewMockExecCommand()

execCommand = mockCmder.Command
Expand Down Expand Up @@ -4246,6 +4258,14 @@ func TestStateMachine_installPackages_fail(t *testing.T) {
asserter.AssertErrContains(err, "Error writing to policy-rc.d")
osWriteFile = os.WriteFile

osRename = mockRename
t.Cleanup(func() {
osRename = os.Rename
})
err = stateMachine.installPackages()
asserter.AssertErrContains(err, "Error moving file ")
osRename = os.Rename

}

// TestCustomizeFstab tests functionality of the customizeFstab function
Expand Down

0 comments on commit f2750a0

Please sign in to comment.