Skip to content

Commit

Permalink
cogito: don't hardcode Github domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
aliculPix4D committed Oct 26, 2023
1 parent 9558fa3 commit 66a8977
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cmd/cogito/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRunPutSuccess(t *testing.T) {
var out bytes.Buffer
var logOut bytes.Buffer
inputDir := testhelp.MakeGitRepoFromTestdata(t, "../../cogito/testdata/one-repo/a-repo",
testhelp.HttpsRemote("the-owner", "the-repo"), "dummySHA", wantGitRef)
testhelp.HttpsRemote("github.com", "the-owner", "the-repo"), "dummySHA", wantGitRef)
t.Setenv("COGITO_GITHUB_API", gitHubSpy.URL)

err := mainErr(in, &out, &logOut, []string{"out", inputDir})
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestRunPutSuccessIntegration(t *testing.T) {
var out bytes.Buffer
var logOut bytes.Buffer
inputDir := testhelp.MakeGitRepoFromTestdata(t, "../../cogito/testdata/one-repo/a-repo",
testhelp.HttpsRemote(gitHubCfg.Owner, gitHubCfg.Repo), gitHubCfg.SHA,
testhelp.HttpsRemote("github.com", gitHubCfg.Owner, gitHubCfg.Repo), gitHubCfg.SHA,
"ref: refs/heads/a-branch-FIXME")
t.Setenv("BUILD_JOB_NAME", "TestRunPutSuccessIntegration")
t.Setenv("ATC_EXTERNAL_URL", "https://cogito.invalid")
Expand Down
6 changes: 3 additions & 3 deletions cogito/putter.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ func checkGitRepoDir(dir, owner, repo string) error {
return fmt.Errorf(`the received git repository is incompatible with the Cogito configuration.
Git repository configuration (received as 'inputs:' in this PUT step):
url: %s
url: %s
owner: %s
repo: %s
repo: %s
Cogito SOURCE configuration:
owner: %s
repo: %s`,
repo: %s`,
gitUrl, gu.Owner, gu.Repo,
owner, repo)
}
Expand Down
22 changes: 11 additions & 11 deletions cogito/putter_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ func TestCheckGitRepoDirSuccess(t *testing.T) {
{
name: "repo with good SSH remote",
dir: "testdata/one-repo/a-repo",
repoURL: testhelp.SshRemote(wantOwner, wantRepo),
repoURL: testhelp.SshRemote("github.com", wantOwner, wantRepo),
},
{
name: "repo with good HTTPS remote",
dir: "testdata/one-repo/a-repo",
repoURL: testhelp.HttpsRemote(wantOwner, wantRepo),
repoURL: testhelp.HttpsRemote("github.com", wantOwner, wantRepo),
},
{
name: "repo with good HTTP remote",
dir: "testdata/one-repo/a-repo",
repoURL: testhelp.HttpRemote(wantOwner, wantRepo),
repoURL: testhelp.HttpRemote("github.com", wantOwner, wantRepo),
},
{
name: "PR resource but with basic auth in URL (see PR #46)",
Expand Down Expand Up @@ -143,32 +143,32 @@ func TestCheckGitRepoDirFailure(t *testing.T) {
{
name: "repo with unrelated HTTPS remote",
dir: "testdata/one-repo/a-repo",
repoURL: testhelp.HttpsRemote("owner-a", "repo-a"),
repoURL: testhelp.HttpsRemote("github.com", "owner-a", "repo-a"),
wantErrWild: `the received git repository is incompatible with the Cogito configuration.
Git repository configuration (received as 'inputs:' in this PUT step):
url: https://github.com/owner-a/repo-a.git
url: https://github.com/owner-a/repo-a.git
owner: owner-a
repo: repo-a
repo: repo-a
Cogito SOURCE configuration:
owner: smiling
repo: butterfly`,
repo: butterfly`,
},
{
name: "repo with unrelated SSH remote or wrong source config",
dir: "testdata/one-repo/a-repo",
repoURL: testhelp.SshRemote("owner-a", "repo-a"),
repoURL: testhelp.SshRemote("github.com", "owner-a", "repo-a"),
wantErrWild: `the received git repository is incompatible with the Cogito configuration.
Git repository configuration (received as 'inputs:' in this PUT step):
url: git@github.com:owner-a/repo-a.git
url: git@github.com:owner-a/repo-a.git
owner: owner-a
repo: repo-a
repo: repo-a
Cogito SOURCE configuration:
owner: smiling
repo: butterfly`,
repo: butterfly`,
},
{
name: "invalid git pseudo URL in .git/config",
Expand Down
12 changes: 6 additions & 6 deletions testhelp/testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,18 @@ func MakeGitRepoFromTestdata(
}

// SshRemote returns a GitHub SSH URL
func SshRemote(owner, repo string) string {
return fmt.Sprintf("git@github.com:%s/%s.git", owner, repo)
func SshRemote(domain, owner, repo string) string {
return fmt.Sprintf("git@%s:%s/%s.git", domain, owner, repo)
}

// HttpsRemote returns a GitHub HTTPS URL
func HttpsRemote(owner, repo string) string {
return fmt.Sprintf("https://github.com/%s/%s.git", owner, repo)
func HttpsRemote(domain, owner, repo string) string {
return fmt.Sprintf("https://%s/%s/%s.git", domain, owner, repo)
}

// HttpRemote returns a GitHub HTTP URL
func HttpRemote(owner, repo string) string {
return fmt.Sprintf("http://github.com/%s/%s.git", owner, repo)
func HttpRemote(domain, owner, repo string) string {
return fmt.Sprintf("http://%s/%s/%s.git", domain, owner, repo)
}

// ToJSON returns the JSON encoding of thing.
Expand Down

0 comments on commit 66a8977

Please sign in to comment.