Skip to content

Commit e48a44f

Browse files
committed
no panic
1 parent 1ea0af3 commit e48a44f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

coderd/promoauth/oauth2_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package promoauth_test
22

33
import (
44
"net/http"
5+
"net/url"
56
"testing"
67
"time"
78

@@ -30,7 +31,7 @@ func TestInstrument(t *testing.T) {
3031
cfg := externalauth.Config{
3132
InstrumentedOAuth2Config: factory.New(id, idp.OIDCConfig(t, []string{})),
3233
ID: "test",
33-
ValidateURL: must(idp.IssuerURL().Parse("/oauth2/userinfo")).String(),
34+
ValidateURL: must[*url.URL](t)(idp.IssuerURL().Parse("/oauth2/userinfo")).String(),
3435
}
3536

3637
// 0 Requests before we start
@@ -60,7 +61,7 @@ func TestInstrument(t *testing.T) {
6061
// extend the http.DefaultTransport. If a `.Clone()` is not done, this can be
6162
// mis-used. It is cheap to run this quick check.
6263
req, err := http.NewRequestWithContext(ctx, http.MethodGet,
63-
must(idp.IssuerURL().Parse("/.well-known/openid-configuration")).String(), nil)
64+
must[*url.URL](t)(idp.IssuerURL().Parse("/.well-known/openid-configuration")).String(), nil)
6465
require.NoError(t, err)
6566

6667
resp, err := http.DefaultClient.Do(req)
@@ -70,9 +71,10 @@ func TestInstrument(t *testing.T) {
7071
require.Equal(t, count(), 3)
7172
}
7273

73-
func must[V any](v V, err error) V {
74-
if err != nil {
75-
panic(err)
74+
func must[V any](t *testing.T) func(v V, err error) V {
75+
return func(v V, err error) V {
76+
t.Helper()
77+
require.NoError(t, err)
78+
return v
7679
}
77-
return v
7880
}

0 commit comments

Comments
 (0)