Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Adds some extra test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
errm committed Apr 9, 2019
1 parent d42e402 commit 9b88d65
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion pkg/system/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (f *fakeDbusConn) RestartUnit(name string, mode string, ch chan<- string) (
}

func (f *fakeDbusConn) ListUnits() ([]dbus.UnitStatus, error) {
return f.unitStatuses, nil
return f.unitStatuses, f.errors["list"]
}

func TestEnsureRunning(t *testing.T) {
Expand Down Expand Up @@ -193,3 +193,48 @@ func TestContainerRuntime(t *testing.T) {
})
}
}

func TestContainerRuntimeErrors(t *testing.T) {
testCases := []struct {
desc string
unitStatuses []dbus.UnitStatus
expected error
error error
}{
{
desc: "When there is a systemd error",
unitStatuses: []dbus.UnitStatus{
{
Name: "docker.service",
LoadState: "loaded",
},
},
expected: errors.New("a systemd error"),
error: errors.New("a systemd error"),
},
{
desc: "When no container runtime is loaded",
unitStatuses: []dbus.UnitStatus{
{
Name: "containerd.service",
LoadState: "Not found",
},
},
expected: errors.New("couldn't work out what container runtime is installed"),
},
}
for _, tC := range testCases {
tC := tC
t.Run(tC.desc, func(t *testing.T) {
d := &fakeDbusConn{unitStatuses: tC.unitStatuses, errors: map[string]error{"list": tC.error}}
s := &system.Systemd{Conn: d}
_, err := s.ContainerRuntime()
if err == nil {
t.Errorf("Expected an error!")
}
if err.Error() != tC.expected.Error() {
t.Errorf("Expected error to be %v but was: %v", tC.expected, err)
}
})
}
}

0 comments on commit 9b88d65

Please sign in to comment.