Skip to content

Commit

Permalink
Extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martialblog committed Feb 22, 2024
1 parent d23bdb3 commit 594ed85
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hp/cntlr/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func GetControllersFromTable(t *CpqDaCntlrTable) ([]*Controller, error) {
return controllers, nil
}

// GetNagiosStatus validates the Controller's data against the known models
// in this plugin.
func (d *Controller) GetNagiosStatus() (int, string) {
description := fmt.Sprintf("controller (%s) model=%s serial=%s firmware=%s",
d.ID, d.Model, strings.TrimSpace(d.Serial), d.FwRev)
Expand Down
58 changes: 58 additions & 0 deletions hp/cntlr/controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cntlr

import (
"testing"

"github.com/NETWAYS/go-check"
"github.com/stretchr/testify/assert"
)

func TestIlo_GetNagiosStatus(t *testing.T) {
testcases := map[string]struct {
controller Controller
expectedState int
expectedOutput string
}{
"status-ok": {
controller: Controller{
ID: "id123",
Model: "model",
FwRev: "revision",
Serial: "12345",
Status: "ok",
},
expectedState: check.OK,
expectedOutput: "controller (id123) model=model serial=12345 firmware=revision",
},
"status-not-ok-not-affected": {
controller: Controller{
ID: "id123",
Model: "model",
FwRev: "revision",
Serial: "12345",
Status: "not-ok",
},
expectedState: check.Critical,
expectedOutput: "controller (id123) model=model serial=12345 firmware=revision",
},
"status-not-ok-affected": {
controller: Controller{
ID: "id123",
Model: "e208i-p",
FwRev: "1.98",
Serial: "12345",
Status: "ok",
},
expectedState: check.Critical,
expectedOutput: "controller (id123) model=e208i-p serial=12345 firmware=1.98 - if you have RAID 5/6/50/60 - update immediately!",
},
}

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
state, output := tc.controller.GetNagiosStatus()
assert.Equal(t, state, tc.expectedState)
assert.Contains(t, output, tc.expectedOutput)
})
}
}
1 change: 1 addition & 0 deletions hp/cntlr/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func init() {
}
}

// IsAffected validates the given version against known affected versions.
// Note: we can't validate against existing logical drives at the moment
func IsAffected(firmware string) (int, string) {
firmwareVersion, _ := version.NewVersion(firmware)
Expand Down
2 changes: 2 additions & 0 deletions hp/drive/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func GetPhysicalDrivesFromTable(t *CpqDaPhyDrvTable) ([]*PhysicalDrive, error) {
return drives, nil
}

// GetNagiosStatus validates the drive's data against the known models
// in this plugin.
func (d *PhysicalDrive) GetNagiosStatus() (int, string) {
description := fmt.Sprintf("physical drive (%-4s) model=%s serial=%s firmware=%s hours=%d",
d.ID, d.Model, d.Serial, d.FwRev, d.Hours)
Expand Down
1 change: 0 additions & 1 deletion hp/ilo/firmware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestIlo_GetNagiosStatus(t *testing.T) {
assert.Contains(t, output, tc.expectedOutput)
})
}

}

func TestIsNewerVersion(t *testing.T) {
Expand Down

0 comments on commit 594ed85

Please sign in to comment.