1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

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.
This commit is contained in:
Alberto Bertogli
2019-07-13 13:52:28 +01:00
parent 2943f994e7
commit 9821a17d6c

View File

@@ -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)
}