Skip to content

Commit

Permalink
GHES 3.11: Changes in generated code (#96)
Browse files Browse the repository at this point in the history
* New updates to generated code

* New updates to generated code

* New updates to generated code
  • Loading branch information
octokitbot authored Oct 10, 2024
1 parent 168e99f commit 8c1b2d3
Show file tree
Hide file tree
Showing 5 changed files with 2,149 additions and 2,327 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 8c1b2d3

Please sign in to comment.