Add happy path test for cap zone
This commit is contained in:
parent
3d9f92a9c0
commit
78d1a11583
1 changed files with 28 additions and 2 deletions
|
@ -1,10 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -29,7 +30,6 @@ func TestMaxPower(t *testing.T) {
|
|||
|
||||
defer os.Remove(tmpfile.Name())
|
||||
|
||||
fmt.Println(tmpfile.Name())
|
||||
_, err = tmpfile.Write([]byte(strconv.FormatUint(maxWattage, 10)))
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -40,3 +40,29 @@ func TestMaxPower(t *testing.T) {
|
|||
err = tmpfile.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestCapZone(t *testing.T) {
|
||||
|
||||
const maxPower float64 = 1500000
|
||||
const percentage float64 = .50
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", powerLimitFileShortWindow)
|
||||
assert.NoError(t, err)
|
||||
|
||||
defer os.Remove(tmpfile.Name())
|
||||
|
||||
powercap := uint64(math.Ceil(maxPower * percentage))
|
||||
|
||||
err = capZone(tmpfile.Name(), powercap)
|
||||
assert.NoError(t, err)
|
||||
|
||||
newCapBytes, err := ioutil.ReadFile(tmpfile.Name())
|
||||
assert.NoError(t, err)
|
||||
|
||||
newCap, err := strconv.ParseUint(strings.TrimSpace(string(newCapBytes)), 10, 64)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, powercap, newCap)
|
||||
|
||||
err = tmpfile.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
Reference in a new issue