Adding test for happy path retrieving max power.

This commit is contained in:
Renan DelValle 2020-01-04 17:15:16 -08:00
parent 2955c5d27f
commit 78f533fe21
No known key found for this signature in database
GPG key ID: 3895800E03F17676
2 changed files with 31 additions and 2 deletions

View file

@ -1,10 +1,18 @@
package main
import "testing"
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
// TODO(rdelvalle): Add more thourough testing. Generate mock files
// that mimic the powercap subsystem and create test to operate on it.
func TestCap(t *testing.T) {
func TestCapNode(t *testing.T) {
err := capNode("/sys/devices/virtual/powercap/intel-rapl", 95)
@ -12,3 +20,23 @@ func TestCap(t *testing.T) {
t.Fail()
}
}
func TestMaxPower(t *testing.T) {
const maxWattage uint64 = 1500000
tmpfile, err := ioutil.TempFile("", maxPowerFileShortWindow)
assert.NoError(t, err)
defer os.Remove(tmpfile.Name())
fmt.Println(tmpfile.Name())
_, err = tmpfile.Write([]byte(strconv.FormatUint(maxWattage, 10)))
assert.NoError(t, err)
maxWatts, err := maxPower(tmpfile.Name())
assert.NoError(t, err)
assert.Equal(t, maxWattage, maxWatts)
err = tmpfile.Close()
assert.NoError(t, err)
}