From b3de44bac6640df6878a989eaac2544d394d65fa Mon Sep 17 00:00:00 2001
From: Renan DelValle <commit@ridv.xyz>
Date: Sat, 4 Jan 2020 18:09:41 -0800
Subject: [PATCH] Change cap node to use a temporary setup.

---
 rapl-daemon/util_test.go | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/rapl-daemon/util_test.go b/rapl-daemon/util_test.go
index 010493e..61612b2 100644
--- a/rapl-daemon/util_test.go
+++ b/rapl-daemon/util_test.go
@@ -4,6 +4,7 @@ import (
 	"io/ioutil"
 	"math"
 	"os"
+	"path/filepath"
 	"strconv"
 	"strings"
 	"testing"
@@ -15,11 +16,20 @@ import (
 // that mimic the powercap subsystem and create test to operate on it.
 func TestCapNode(t *testing.T) {
 
-	err := capNode("/sys/devices/virtual/powercap/intel-rapl", 95)
+	RAPLdir, err := ioutil.TempDir("", "intel-rapl")
+	assert.NoError(t, err)
+	defer os.RemoveAll(RAPLdir)
 
-	if err != nil {
-		t.Fail()
-	}
+	zonePath := filepath.Join(RAPLdir, raplPrefixCPU+":0")
+	err = os.Mkdir(zonePath, 755)
+	assert.NoError(t, err)
+	err = ioutil.WriteFile(filepath.Join(zonePath, maxPowerFileShortWindow), []byte("1500000"), 0444)
+	assert.NoError(t, err)
+	err = ioutil.WriteFile(filepath.Join(zonePath, powerLimitFileShortWindow), []byte("1500000"), 0644)
+	assert.NoError(t, err)
+
+	err = capNode(RAPLdir, 95)
+	assert.NoError(t, err)
 }
 
 func TestMaxPower(t *testing.T) {
@@ -42,7 +52,6 @@ func TestMaxPower(t *testing.T) {
 }
 
 func TestCapZone(t *testing.T) {
-
 	const maxPower float64 = 1500000
 	const percentage float64 = .50