Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend tests #88

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading