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