Skip to content

Commit

Permalink
New updates to generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
octokitbot committed Oct 8, 2024
1 parent 168e99f commit a904015
Show file tree
Hide file tree
Showing 5 changed files with 1,990 additions and 2,331 deletions.
4 changes: 4 additions & 0 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func NewApiClient(optionFuncs ...ClientOptionFunc) (*Client, error) {
return nil, fmt.Errorf("failed to create transport from GitHub App: %v", err)
}

if options.BaseURL != "" {
appTransport.BaseURL = options.BaseURL
}

netHttpClient.Transport = appTransport
}

Expand Down
49 changes: 49 additions & 0 deletions pkg/client_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package pkg

import (
"context"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

abs "github.com/microsoft/kiota-abstractions-go"
"github.com/octokit/go-sdk-enterprise-server/pkg/github/installation"
"github.com/octokit/go-sdk-enterprise-server/pkg/headers"
)

Expand Down Expand Up @@ -91,6 +97,49 @@ func TestNewApiClientAppAuthHappyPath(t *testing.T) {
}
}

func TestNewApiClientAppAuthBaseUrl(t *testing.T) {
tmpfile, err := os.CreateTemp("", pemFileName)
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())

if _, err := tmpfile.Write(key); err != nil {
t.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
t.Fatal(err)
}

expectedCall := false
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.Path, "/app/installations") {
expectedCall = true
}
}))

client, err := NewApiClient(
WithGitHubAppAuthentication(tmpfile.Name(), clientID, installationID),
WithBaseUrl(server.URL),
)
if err != nil {
t.Fatalf("error creating client: %v", err)
}
if client == nil {
t.Fatalf("client is nil")
}
queryParams := &installation.RepositoriesRequestBuilderGetQueryParameters{}
requestConfig := &abs.RequestConfiguration[installation.RepositoriesRequestBuilderGetQueryParameters]{
QueryParameters: queryParams,
}

// trigger a refresh of the installation token to the expected url
_, _ = client.Installation().Repositories().Get(context.Background(), requestConfig)
if !expectedCall {
t.Errorf("installation token endpoint not called")
}
}

func TestNewApiClientAppAuthErrorGettingKeyFromFile(t *testing.T) {
client, err := NewApiClient(WithGitHubAppAuthentication("pem/file/does/not/exist.pem", clientID, installationID))
if err == nil {
Expand Down
Loading

0 comments on commit a904015

Please sign in to comment.