From 9821a17d6c280d6d78a18d09e33202a05db0f9da Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 13 Jul 2019 13:52:28 +0100 Subject: [PATCH] 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 | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) 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) }