git » chasquid » commit 9821a17

sts: Use expvar.Int.Value in tests

author Alberto Bertogli
2019-07-13 12:52:28 UTC
committer Alberto Bertogli
2019-07-13 12:52:28 UTC
parent 2943f994e7d6d8154814db6344d9714a41806186

sts: Use expvar.Int.Value in tests

Now that we raised the minimum Go version to 1.9, we can make use of
expvar's .Value methods to simplify some of the STS tests.

This patch makes those simplifications, which do not change the logic of
the tests themselves.

internal/sts/sts_test.go +4 -9

diff --git a/internal/sts/sts_test.go b/internal/sts/sts_test.go
index 7e9da5e..f44fddf 100644
--- a/internal/sts/sts_test.go
+++ b/internal/sts/sts_test.go
@@ -7,7 +7,6 @@ import (
 	"net/http"
 	"net/http/httptest"
 	"os"
-	"strconv"
 	"strings"
 	"testing"
 	"time"
@@ -241,11 +240,9 @@ func TestPolicyTooBig(t *testing.T) {
 
 // Tests for the policy cache.
 
-func expvarMustEq(t *testing.T, name string, v *expvar.Int, expected int) {
-	// TODO: Use v.Value once we drop support of Go 1.7.
-	value, _ := strconv.Atoi(v.String())
-	if value != expected {
-		t.Errorf("%s is %d, expected %d", name, value, expected)
+func expvarMustEq(t *testing.T, name string, v *expvar.Int, expected int64) {
+	if v.Value() != expected {
+		t.Errorf("%s is %d, expected %d", name, v.Value(), expected)
 	}
 }
 
@@ -439,13 +436,11 @@ func TestCacheRefresh(t *testing.T) {
 	}
 
 	// Launch background refreshes, and wait for one to complete.
-	// TODO: change to cacheRefreshCycles.Value once we drop support for Go
-	// 1.7.
 	cacheRefreshCycles.Set(0)
 	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
 	defer cancel()
 	go c.PeriodicallyRefresh(ctx)
-	for cacheRefreshCycles.String() == "0" {
+	for cacheRefreshCycles.Value() == 0 {
 		time.Sleep(5 * time.Millisecond)
 	}