mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-07-21 15:32:45 +00:00
Fixed API changes based on new dependencies
The "github.com/google/go-github/v87/github" has API shape changes, therefore a mere go.mod dependency update was inadequate; this PR adds necessary changes for feature parity and tests. Co-authored-by: Ryan Richard <richardry@vmware.com> Signed-off-by: Volkan Özçelik <volkan.ozcelik@broadcom.com>
This commit is contained in:
committed by
Ryan Richard
parent
1ccfd13194
commit
d14722396a
@@ -71,8 +71,18 @@ func NewGitHubClient(httpClient *http.Client, apiBaseURL, token string) (GitHubI
|
||||
return nil, fmt.Errorf("%s: token cannot be empty string", errorPrefix)
|
||||
}
|
||||
|
||||
client := github.NewClient(httpClient).WithAuthToken(token)
|
||||
client.BaseURL = parsedURL
|
||||
// go-github's WithEnterpriseURLs requires a non-empty upload URL even though
|
||||
// Pinniped only calls read endpoints (Users.Get, Organizations.List,
|
||||
// Teams.ListUserTeams), all of which use the base URL. The upload URL is never
|
||||
// exercised today. It should be updated if an upload-style call is ever used.
|
||||
client, err := github.NewClient(
|
||||
github.WithHTTPClient(httpClient),
|
||||
github.WithAuthToken(token),
|
||||
github.WithEnterpriseURLs(parsedURL.String(), parsedURL.String()),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", errorPrefix, err)
|
||||
}
|
||||
|
||||
return &githubClient{
|
||||
client: client,
|
||||
|
||||
@@ -106,8 +106,8 @@ func TestNewGitHubClient(t *testing.T) {
|
||||
require.NotNil(t, actualI)
|
||||
actual, ok := actualI.(*githubClient)
|
||||
require.True(t, ok)
|
||||
require.NotNil(t, actual.client.BaseURL)
|
||||
require.Equal(t, test.wantBaseURL, actual.client.BaseURL.String())
|
||||
require.NotNil(t, actual.client)
|
||||
require.Equal(t, test.wantBaseURL, actual.client.BaseURL())
|
||||
|
||||
// Force the githubClient's httpClient roundTrippers to run and add the Authorization header
|
||||
|
||||
@@ -227,9 +227,9 @@ func TestGetUser(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
githubClient := &githubClient{
|
||||
client: github.NewClient(test.httpClient).WithAuthToken(test.token),
|
||||
}
|
||||
c, err := github.NewClient(github.WithHTTPClient(test.httpClient), github.WithAuthToken(test.token))
|
||||
require.NoError(t, err)
|
||||
githubClient := &githubClient{client: c}
|
||||
|
||||
ctx := context.Background()
|
||||
if test.ctx != nil {
|
||||
@@ -361,9 +361,9 @@ func TestGetOrgMembership(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
githubClient := &githubClient{
|
||||
client: github.NewClient(test.httpClient).WithAuthToken(test.token),
|
||||
}
|
||||
c, err := github.NewClient(github.WithHTTPClient(test.httpClient), github.WithAuthToken(test.token))
|
||||
require.NoError(t, err)
|
||||
githubClient := &githubClient{client: c}
|
||||
|
||||
ctx := context.Background()
|
||||
if test.ctx != nil {
|
||||
@@ -700,6 +700,7 @@ func TestGetTeamMembership(t *testing.T) {
|
||||
},
|
||||
),
|
||||
),
|
||||
token: "fake-token",
|
||||
wantErr: `error fetching team membership for authenticated user: missing the "organization" attribute for a team`,
|
||||
},
|
||||
{
|
||||
@@ -716,6 +717,7 @@ func TestGetTeamMembership(t *testing.T) {
|
||||
},
|
||||
),
|
||||
),
|
||||
token: "fake-token",
|
||||
wantErr: `error fetching team membership for authenticated user: missing the organization's "login" attribute for a team`,
|
||||
},
|
||||
{
|
||||
@@ -733,6 +735,7 @@ func TestGetTeamMembership(t *testing.T) {
|
||||
},
|
||||
),
|
||||
),
|
||||
token: "fake-token",
|
||||
wantErr: `error fetching team membership for authenticated user: the "name" attribute is missing for a team`,
|
||||
},
|
||||
{
|
||||
@@ -750,6 +753,7 @@ func TestGetTeamMembership(t *testing.T) {
|
||||
},
|
||||
),
|
||||
),
|
||||
token: "fake-token",
|
||||
wantErr: `error fetching team membership for authenticated user: the "slug" attribute is missing for a team`,
|
||||
},
|
||||
{
|
||||
@@ -808,9 +812,9 @@ func TestGetTeamMembership(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
githubClient := &githubClient{
|
||||
client: github.NewClient(test.httpClient).WithAuthToken(test.token),
|
||||
}
|
||||
c, err := github.NewClient(github.WithHTTPClient(test.httpClient), github.WithAuthToken(test.token))
|
||||
require.NoError(t, err)
|
||||
githubClient := &githubClient{client: c}
|
||||
|
||||
ctx := context.Background()
|
||||
if test.ctx != nil {
|
||||
|
||||
Reference in New Issue
Block a user