|
1 | 1 | package github |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/diggerhq/digger/libs/ci/generic" |
| 4 | + "os" |
5 | 5 | "testing" |
6 | 6 |
|
| 7 | + "github.com/diggerhq/digger/libs/ci/generic" |
7 | 8 | "github.com/diggerhq/digger/libs/digger_config" |
8 | 9 | "github.com/stretchr/testify/assert" |
9 | 10 | ) |
@@ -121,3 +122,66 @@ func TestFindAllChangedFilesOfPR(t *testing.T) { |
121 | 122 | // 45 changed files including 1 renamed file so the previous filename is included |
122 | 123 | assert.Equal(t, 46, len(files)) |
123 | 124 | } |
| 125 | + |
| 126 | +func TestConfigureEnterpriseClient_WithDiggerHostname(t *testing.T) { |
| 127 | + // Set up |
| 128 | + os.Setenv("DIGGER_GITHUB_HOSTNAME", "github.example.com") |
| 129 | + defer os.Unsetenv("DIGGER_GITHUB_HOSTNAME") |
| 130 | + |
| 131 | + svc, err := GithubServiceProviderBasic{}.NewService("test-token", "repo", "owner") |
| 132 | + |
| 133 | + assert.NoError(t, err) |
| 134 | + assert.NotNil(t, svc.Client) |
| 135 | + assert.Equal(t, "https://github.example.com/api/v3/", svc.Client.BaseURL.String()) |
| 136 | + assert.Equal(t, "https://github.example.com/api/uploads/", svc.Client.UploadURL.String()) |
| 137 | +} |
| 138 | + |
| 139 | +func TestConfigureEnterpriseClient_WithGitHubApiUrl(t *testing.T) { |
| 140 | + // Set up - this simulates GitHub Actions environment on Enterprise |
| 141 | + os.Setenv("GITHUB_API_URL", "https://github.example.com/api/v3") |
| 142 | + defer os.Unsetenv("GITHUB_API_URL") |
| 143 | + |
| 144 | + svc, err := GithubServiceProviderBasic{}.NewService("test-token", "repo", "owner") |
| 145 | + |
| 146 | + assert.NoError(t, err) |
| 147 | + assert.NotNil(t, svc.Client) |
| 148 | + assert.Equal(t, "https://github.example.com/api/v3/", svc.Client.BaseURL.String()) |
| 149 | + assert.Equal(t, "https://github.example.com/api/uploads/", svc.Client.UploadURL.String()) |
| 150 | +} |
| 151 | + |
| 152 | +func TestConfigureEnterpriseClient_PublicGitHub(t *testing.T) { |
| 153 | + // Ensure no enterprise env vars are set |
| 154 | + os.Unsetenv("DIGGER_GITHUB_HOSTNAME") |
| 155 | + os.Unsetenv("GITHUB_API_URL") |
| 156 | + |
| 157 | + svc, err := GithubServiceProviderBasic{}.NewService("test-token", "repo", "owner") |
| 158 | + |
| 159 | + assert.NoError(t, err) |
| 160 | + assert.NotNil(t, svc.Client) |
| 161 | + assert.Equal(t, "https://api.github.com/", svc.Client.BaseURL.String()) |
| 162 | +} |
| 163 | + |
| 164 | +func TestConfigureEnterpriseClient_PublicGitHubApiUrl(t *testing.T) { |
| 165 | + // GITHUB_API_URL set to public GitHub should not trigger enterprise config |
| 166 | + os.Setenv("GITHUB_API_URL", "https://api.github.com") |
| 167 | + defer os.Unsetenv("GITHUB_API_URL") |
| 168 | + |
| 169 | + svc, err := GithubServiceProviderBasic{}.NewService("test-token", "repo", "owner") |
| 170 | + |
| 171 | + assert.NoError(t, err) |
| 172 | + assert.NotNil(t, svc.Client) |
| 173 | + assert.Equal(t, "https://api.github.com/", svc.Client.BaseURL.String()) |
| 174 | +} |
| 175 | + |
| 176 | +func TestConfigureEnterpriseClient_DiggerHostnameTakesPrecedence(t *testing.T) { |
| 177 | + // Both set - DIGGER_GITHUB_HOSTNAME should take precedence |
| 178 | + os.Setenv("DIGGER_GITHUB_HOSTNAME", "digger-enterprise.example.com") |
| 179 | + os.Setenv("GITHUB_API_URL", "https://actions-enterprise.example.com/api/v3") |
| 180 | + defer os.Unsetenv("DIGGER_GITHUB_HOSTNAME") |
| 181 | + defer os.Unsetenv("GITHUB_API_URL") |
| 182 | + |
| 183 | + svc, err := GithubServiceProviderBasic{}.NewService("test-token", "repo", "owner") |
| 184 | + |
| 185 | + assert.NoError(t, err) |
| 186 | + assert.Equal(t, "https://digger-enterprise.example.com/api/v3/", svc.Client.BaseURL.String()) |
| 187 | +} |
0 commit comments