Skip to content

Commit

Permalink
Add testfile for pwrstat package
Browse files Browse the repository at this point in the history
  • Loading branch information
kerwenwwer committed Apr 10, 2024
1 parent 2feecff commit 163bc7d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ module github.com/kerwenwwer/pwrstat-exporter
go 1.21.4

require (
github.com/kerwenwwer/gopwrstat v0.0.0-20210706082034-1280720e1b75
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
38 changes: 38 additions & 0 deletions pwrstat/pwrstat_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pwrstat

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestConstruct(t *testing.T) {
assert := assert.New(t)

sample := `
The UPS information shows as following:
Properties:
Model Name................... CP1000PFCLCDa
Firmware Number.............. CR01803BBI11
Rating Voltage............... 120 V
Rating Power................. 600 Watt(1000 VA)
Current UPS status:
State........................ Normal
Power Supply by.............. Utility Power
Utility Voltage.............. 114 V
Output Voltage............... 114 V
Battery Capacity............. 100 %
Remaining Runtime............ 35 min.
Load......................... 114 Watt(19 %)
Line Interaction............. None
Test Result.................. Passed at 2022/09/21 20:44:29
Last Power Event............. None
`

actual := parseOutput(sample) // Make sure Construct is exported in pwrstat.go
assert.Len(actual.Status, 14, "Status should contain 14 entries")

actualBatteryCapacity, ok := actual.Status["Battery Capacity"]
assert.True(ok, "Battery Capacity key should exist")
assert.Equal("100 %", actualBatteryCapacity, "Battery Capacity should be 100 %")
}

0 comments on commit 163bc7d

Please sign in to comment.