Skip to content

Commit 51a5b08

Browse files
committed
work
1 parent 83e4141 commit 51a5b08

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

config/auth_u2m_test.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
1211
"github.com/databricks/databricks-sdk-go/credentials/u2m"
12+
"github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
1313
"github.com/databricks/databricks-sdk-go/httpclient/fixtures"
1414
"github.com/stretchr/testify/require"
1515
"golang.org/x/oauth2"
@@ -35,11 +35,18 @@ func (m MockOAuthClient) GetWorkspaceOAuthEndpoints(ctx context.Context, workspa
3535
return m.GetWorkspaceOAuthEndpointsFn(ctx, workspaceHost)
3636
}
3737

38+
func must[T any](c T, err error) T {
39+
if err != nil {
40+
panic(err)
41+
}
42+
return c
43+
}
44+
3845
func TestU2MCredentials(t *testing.T) {
3946
tests := []struct {
4047
name string
4148
cfg *Config
42-
auth func() (*u2m.PersistentAuth, error)
49+
auth *u2m.PersistentAuth
4350
expectErr string
4451
expectAuth string
4552
}{
@@ -48,8 +55,8 @@ func TestU2MCredentials(t *testing.T) {
4855
cfg: &Config{
4956
Host: "https://myworkspace.cloud.databricks.com",
5057
},
51-
auth: func() (*u2m.PersistentAuth, error) {
52-
return u2m.NewPersistentAuth(
58+
auth: must(
59+
u2m.NewPersistentAuth(
5360
context.Background(),
5461
u2m.WithTokenCache(&InMemoryTokenCache{
5562
Tokens: map[string]*oauth2.Token{
@@ -58,17 +65,19 @@ func TestU2MCredentials(t *testing.T) {
5865
Expiry: time.Now().Add(1 * time.Hour),
5966
},
6067
},
61-
}))
62-
},
68+
}),
69+
u2m.WithOAuthArgument(must(u2m.NewBasicWorkspaceOAuthArgument("https://myworkspace.cloud.databricks.com"))),
70+
),
71+
),
6372
expectAuth: "Bearer dummy_access_token",
6473
},
6574
{
6675
name: "expired token with invalid refresh token",
6776
cfg: &Config{
6877
Host: "https://myworkspace.cloud.databricks.com",
6978
},
70-
auth: func() (*u2m.PersistentAuth, error) {
71-
return u2m.NewPersistentAuth(
79+
auth: must(
80+
u2m.NewPersistentAuth(
7281
context.Background(),
7382
u2m.WithTokenCache(&InMemoryTokenCache{
7483
Tokens: map[string]*oauth2.Token{
@@ -95,19 +104,18 @@ func TestU2MCredentials(t *testing.T) {
95104
}, nil
96105
},
97106
}),
98-
)
99-
},
107+
u2m.WithOAuthArgument(must(u2m.NewBasicWorkspaceOAuthArgument("https://myworkspace.cloud.databricks.com"))),
108+
),
109+
),
100110
expectErr: "oidc: token refresh: oauth2: \"invalid_refresh_token\" \"Refresh token is invalid\"",
101111
},
102112
}
103113

104114
for _, tt := range tests {
105115
t.Run(tt.name, func(t *testing.T) {
106116
ctx := context.Background()
107-
auth, err := tt.auth()
108-
require.NoError(t, err)
109117
strat := u2mCredentials{
110-
auth: auth,
118+
auth: tt.auth,
111119
}
112120
provider, err := strat.Configure(ctx, tt.cfg)
113121
if tt.expectErr != "" {

0 commit comments

Comments
 (0)