From 2f4bf844fc2465e2f3ca64ddcc6e4588dd2319fd Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Thu, 27 Jul 2023 15:51:57 +0200 Subject: [PATCH] Fix git clone integration test for non-existing repo (#610) ## Changes This PR changes the integration test to just check an error is returned rather than asserting specific text is present in the error. This is required because the error returned can be different based on whether git ssh keys have been setup. --- internal/git_clone_test.go | 7 ++++--- libs/git/clone.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/git_clone_test.go b/internal/git_clone_test.go index b280ebc7..3fb69b92 100644 --- a/internal/git_clone_test.go +++ b/internal/git_clone_test.go @@ -53,11 +53,12 @@ func TestAccGitCloneWithOnlyRepoNameOnAlternateBranch(t *testing.T) { assert.Contains(t, string(b), "dais-2022") } -func TestAccGitCloneRepositoryDoesNotExist(t *testing.T) { +func TestAccGitCloneErrorsWhenRepositoryDoesNotExist(t *testing.T) { t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) tmpDir := t.TempDir() - err := git.Clone(context.Background(), "doesnot-exist", "", tmpDir) - assert.Contains(t, err.Error(), `repository 'https://github.com/databricks/doesnot-exist/' not found`) + err := git.Clone(context.Background(), "https://github.com/monalisa/doesnot-exist.git", "", tmpDir) + // Expect the error to originate from shelling out to `git clone` + assert.ErrorContains(t, err, "git clone failed:") } diff --git a/libs/git/clone.go b/libs/git/clone.go index ec663272..8b075cde 100644 --- a/libs/git/clone.go +++ b/libs/git/clone.go @@ -60,7 +60,7 @@ func Clone(ctx context.Context, url, reference, targetPath string) error { return fmt.Errorf("please install git CLI to clone a repository: %w", err) } if err != nil { - return err + return fmt.Errorf("git clone failed: %w", err) } // wait for git clone to complete