added error for when CLI is not installed

This commit is contained in:
Shreyas Goenka 2023-06-29 19:08:02 +02:00
parent 3959ca1317
commit e6000db8c5
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
3 changed files with 33 additions and 1 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
)
// TODO: add assertion for error if git CLI is not found
func TestAccGitClonePublicRepository(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))

View File

@ -96,6 +96,9 @@ func clonePrivate(ctx context.Context, opts CloneOptions) error {
// start git clone
err := cmd.Start()
if errors.Is(err, exec.ErrNotFound) {
return fmt.Errorf("please install git CLI to download private templates: %w", err)
}
if err != nil {
return err
}

30
libs/git/clone_test.go Normal file
View File

@ -0,0 +1,30 @@
package git
import (
"context"
"os"
"os/exec"
"testing"
"github.com/databricks/cli/libs/cmdio"
"github.com/stretchr/testify/assert"
)
func TestGitCloneCLINotFound(t *testing.T) {
// Set PATH to "", so git CLI cannot be found
t.Setenv("PATH", "")
tmpDir := t.TempDir()
cmdIO := cmdio.NewIO("text", os.Stdin, os.Stdout, os.Stderr, "")
ctx := cmdio.InContext(context.Background(), cmdIO)
err := Clone(ctx, CloneOptions{
Provider: "github",
Organization: "databricks",
RepositoryName: "does-not-exist",
Reference: "main",
TargetDir: tmpDir,
})
assert.ErrorIs(t, err, exec.ErrNotFound)
assert.ErrorContains(t, err, "please install git CLI to download private templates")
}