Skip to content

Commit

Permalink
fix: deflake ttl test
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Aug 8, 2023
1 parent a21e945 commit 6741a49
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions oauth2/oauth2_client_credentials_test.go
Expand Up @@ -6,7 +6,6 @@ package oauth2_test
import (
"context"
"encoding/json"
"math"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -238,11 +237,10 @@ func TestClientCredentials(t *testing.T) {
conf.Scopes = []string{}
token, err := getToken(t, conf)
require.NoError(t, err)

assert.True(t, math.Abs(float64(time.Now().Add(duration).Round(time.Minute).Unix())-float64(token.Expiry.Round(time.Minute).Unix())) < 5)

expected := time.Now().Add(duration)
assert.WithinDuration(t, expected, token.Expiry, 5*time.Second)
introspection := testhelpers.IntrospectToken(t, &goauth2.Config{ClientID: cl.GetID(), ClientSecret: conf.ClientSecret}, token.AccessToken, admin)
assert.EqualValues(t, time.Now().Add(duration).Round(time.Minute), time.Unix(introspection.Get("exp").Int(), 0).Round(time.Minute))
assert.WithinDuration(t, expected, time.Unix(introspection.Get("exp").Int(), 0), 5*time.Second)
}
}

Expand Down

0 comments on commit 6741a49

Please sign in to comment.