-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Support for github enterprise urls added (custom domains) #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,19 +7,67 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||
| "github.com/stretchr/testify/assert" | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func TestNewClient_Success(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||
| func TestNewClient_Success_GitHubCom(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||
| key, err := os.ReadFile("testdata/test.key") | ||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key)) | ||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key), "", false) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client.Client) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client.transport) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Should default to GitHub.com | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Contains(t, client.Client.BaseURL.String(), "https://api.github.com/") | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func TestNewClient_Success_GitHubCom_TLS(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||
| key, err := os.ReadFile("testdata/test.key") | ||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key), "", true) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func TestNewClient_Success_Enterprise(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||
| key, err := os.ReadFile("testdata/test.key") | ||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| fakeEnterpriseURL := "https://api.githubenterprise.example.com/" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key), fakeEnterpriseURL, false) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client.transport) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Ensure the Enterprise base URL was applied | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Contains(t, client.Client.BaseURL.String(), fakeEnterpriseURL) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Equal(t, client.transport.BaseURL, fakeEnterpriseURL) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the API base, not host root, and assert normalized URL. Tests pass a host root ( Apply: - fakeEnterpriseURL := "https://api.githubenterprise.example.com/"
+ fakeEnterpriseURL := "https://api.githubenterprise.example.com/api/v3/"Then assert exact equality (with trailing slash) on 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func TestNewClient_Success_Enterprise_TLS(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||
| key, err := os.ReadFile("testdata/test.key") | ||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| fakeEnterpriseURL := "https://api.githubenterprise.example.com/" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key), fakeEnterpriseURL, true) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Contains(t, client.Client.BaseURL.String(), fakeEnterpriseURL) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func TestNewClient_Failure(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, "") | ||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, "", "", false) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Error(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Nil(t, client) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -30,9 +78,32 @@ func TestClientInstallation(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key)) | ||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key), "", false) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| installation := client.Installation(12345) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, installation) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // The installation client should still have a valid BaseURL | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Contains(t, installation.BaseURL.String(), "https://api.github.com/") | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func TestClientInstallation_Enterprise(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||
| key, err := os.ReadFile("testdata/test.key") | ||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| fakeEnterpriseURL := "https://api.githubenterprise.example.com/" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| client, err := NewClient(12345, string(key), fakeEnterpriseURL, true) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, client) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| installation := client.Installation(12345) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotNil(t, installation) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Should retain enterprise base URL | ||||||||||||||||||||||||||||||||||||||||||||||
| assert.Contains(t, installation.BaseURL.String(), fakeEnterpriseURL) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize enterprise URLs and set upload base.
WithEnterpriseURLsexpects the API base (.../api/v3/) and an upload base (.../api/uploads/). Empty upload URL may break asset uploads; lack of trailing slash can break path joins.Apply:
And add helpers/imports: