MCPcopy Index your code
hub / github.com/coder/coder / TestGitHubEnterpriseURLs

Function TestGitHubEnterpriseURLs

coderd/externalauth/gitprovider/github_test.go:360–422  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

358}
359
360func TestGitHubEnterpriseURLs(t *testing.T) {
361 t.Parallel()
362 gp, err := gitprovider.New("github", "https://ghes.corp.com/api/v3", nil)
363 require.NoError(t, err)
364 require.NotNil(t, gp)
365
366 t.Run("ParseRepositoryOrigin HTTPS", func(t *testing.T) {
367 t.Parallel()
368 owner, repo, normalized, ok := gp.ParseRepositoryOrigin("https://ghes.corp.com/org/repo.git")
369 assert.True(t, ok)
370 assert.Equal(t, "org", owner)
371 assert.Equal(t, "repo", repo)
372 assert.Equal(t, "https://ghes.corp.com/org/repo", normalized)
373 })
374
375 t.Run("ParseRepositoryOrigin SSH", func(t *testing.T) {
376 t.Parallel()
377 owner, repo, normalized, ok := gp.ParseRepositoryOrigin("git@ghes.corp.com:org/repo.git")
378 assert.True(t, ok)
379 assert.Equal(t, "org", owner)
380 assert.Equal(t, "repo", repo)
381 assert.Equal(t, "https://ghes.corp.com/org/repo", normalized)
382 })
383
384 t.Run("ParsePullRequestURL", func(t *testing.T) {
385 t.Parallel()
386 ref, ok := gp.ParsePullRequestURL("https://ghes.corp.com/org/repo/pull/42")
387 assert.True(t, ok)
388 assert.Equal(t, "org", ref.Owner)
389 assert.Equal(t, "repo", ref.Repo)
390 assert.Equal(t, 42, ref.Number)
391 })
392
393 t.Run("NormalizePullRequestURL", func(t *testing.T) {
394 t.Parallel()
395 result := gp.NormalizePullRequestURL("https://ghes.corp.com/org/repo/pull/42?x=y")
396 assert.Equal(t, "https://ghes.corp.com/org/repo/pull/42", result)
397 })
398
399 t.Run("BuildBranchURL", func(t *testing.T) {
400 t.Parallel()
401 result := gp.BuildBranchURL("org", "repo", "main")
402 assert.Equal(t, "https://ghes.corp.com/org/repo/tree/main", result)
403 })
404
405 t.Run("BuildPullRequestURL", func(t *testing.T) {
406 t.Parallel()
407 result := gp.BuildPullRequestURL(gitprovider.PRRef{Owner: "org", Repo: "repo", Number: 42})
408 assert.Equal(t, "https://ghes.corp.com/org/repo/pull/42", result)
409 })
410
411 t.Run("github.com URLs do not match GHE instance", func(t *testing.T) {
412 t.Parallel()
413 _, _, _, ok := gp.ParseRepositoryOrigin("https://github.com/coder/coder")
414 assert.False(t, ok, "github.com HTTPS URL should not match GHE instance")
415
416 _, _, _, ok = gp.ParseRepositoryOrigin("git@github.com:coder/coder.git")
417 assert.False(t, ok, "github.com SSH URL should not match GHE instance")

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
RunMethod · 0.65
ParseRepositoryOriginMethod · 0.65
ParsePullRequestURLMethod · 0.65
BuildBranchURLMethod · 0.65
BuildPullRequestURLMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected