From 5536f2d4bd53179ea29761c8924621a54feb4afc Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 30 Oct 2025 08:12:36 +0100 Subject: [PATCH] chore: add test --- plugin/auth/oauth_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 plugin/auth/oauth_test.go diff --git a/plugin/auth/oauth_test.go b/plugin/auth/oauth_test.go new file mode 100644 index 000000000..1660fa708 --- /dev/null +++ b/plugin/auth/oauth_test.go @@ -0,0 +1,35 @@ +package auth + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "golang.org/x/oauth2" +) + +func TestOAuth(t *testing.T) { + var storerCalled int + storer := func(t *oauth2.Token) any { + storerCalled++ + return t + } + + ts, err := NewOauth(context.TODO(), "foo", "bar", &oauth2.Config{ + ClientID: "baz", + }, WithTokenStorerOption(storer)) + require.NoError(t, err) + + token, err := ts.Token() + require.ErrorContains(t, err, "missing token credentials") + require.False(t, token.Valid()) + require.Equal(t, 0, storerCalled) + + ts.updateToken(&oauth2.Token{AccessToken: "at"}) + require.Equal(t, 1, storerCalled) + + token, err = ts.Token() + require.NoError(t, err) + require.True(t, token.Valid()) + require.Equal(t, 1, storerCalled) +}