Skip to content

Commit 1da3ff0

Browse files
committed
removed json, added relative path to tests
1 parent 2d8da98 commit 1da3ff0

File tree

3 files changed

+42
-57
lines changed

3 files changed

+42
-57
lines changed

acceptance/dlt/install-dlt/output.txt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11

22
=== install dlt
3-
>>> errcode [CLI] install-dlt -o json
4-
dlt successfully installed in directory "[BUILD_DIR]"
3+
>>> errcode [CLI] install-dlt -d ./subdir
4+
dlt successfully installed in directory "./subdir"
55

6-
>>> [BUILD_DIR]/dlt
7-
DLT command verified
6+
>>> errcode ./subdir/dlt
7+
DLT CLI (stub, to be filled in)
88

99
=== dlt already installed
10-
>>> errcode [CLI] install-dlt
11-
dlt already installed in directory "[BUILD_DIR]"
10+
>>> errcode [CLI] install-dlt -d ./subdir
11+
dlt already installed in directory "./subdir"
1212

1313
=== dlt file exists, should not overwrite
14-
>>> errcode [CLI] install-dlt -d tmpdir -o json
15-
cannot install dlt CLI: "tmpdir/dlt" already exists
16-
Error: installation failed
14+
>>> errcode [CLI] install-dlt -d ./subdir
15+
Error: cannot install dlt CLI: "subdir/dlt" already exists
1716

1817
Exit code: 1
1918

20-
=== Executable not called as databricks
21-
>>> errcode ./notdatabricks install-dlt -o json
22-
dlt successfully installed in directory "[TEST_TMP_DIR]"
19+
=== databricks executable called with alias
20+
>>> errcode ./subdir/notdatabricks install-dlt -d ./subdir
21+
dlt successfully installed in directory "./subdir"
2322

24-
>>> [TEST_TMP_DIR]/dlt
25-
DLT command verified
23+
>>> errcode ./subdir/dlt
24+
DLT CLI (stub, to be filled in)

acceptance/dlt/install-dlt/script

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
tmpdir="./subdir"
2+
dlt="$tmpdir/dlt"
3+
mkdir -p $tmpdir
4+
15
title "install dlt"
2-
dlt=$(trace errcode $CLI install-dlt -o json | jq -r .symlink_path)
3-
trace $dlt | head -n1 | grep -q "DLT CLI" && echo "DLT command verified" || echo "DLT command failed"
6+
trace errcode $CLI install-dlt -d $tmpdir
7+
trace errcode $dlt | head -n1
48

59
title "dlt already installed"
6-
trace errcode $CLI install-dlt
7-
rm -f "$(dirname $CLI)/dlt"
10+
trace errcode $CLI install-dlt -d $tmpdir
11+
rm -f $dlt
812

913
title "dlt file exists, should not overwrite"
10-
mkdir -p tmpdir
11-
touch tmpdir/dlt
12-
trace errcode $CLI install-dlt -d tmpdir -o json | jq -r .symlink_path
13-
rm -rf tmpdir
14+
touch $dlt
15+
trace errcode $CLI install-dlt -d $tmpdir
16+
rm -f $dlt
17+
18+
title "databricks executable called with alias"
19+
cp $CLI $tmpdir/notdatabricks
20+
trace errcode $tmpdir/notdatabricks install-dlt -d $tmpdir
21+
trace errcode $dlt | head -n1
1422

15-
title "Executable not called as databricks"
16-
cp $CLI notdatabricks
17-
dlt=$(trace errcode ./notdatabricks install-dlt -o json | jq -r .symlink_path)
18-
trace $dlt | head -n1 | grep -q "DLT CLI" && echo "DLT command verified" || echo "DLT command failed"
19-
rm -f notdatabricks
20-
rm -f dlt
23+
# Cleanup
24+
rm -f $tmpdir/notdatabricks $dlt
25+
rm -rf $tmpdir

cmd/dlt/install_dlt.go

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@ import (
77
"os"
88
"path/filepath"
99

10-
"github.com/databricks/cli/cmd/root"
1110
"github.com/databricks/cli/libs/cmdio"
12-
"github.com/databricks/cli/libs/flags"
1311
"github.com/spf13/cobra"
1412
)
1513

16-
type installDLTResponse struct {
17-
SymlinkPath string `json:"symlink_path"`
18-
}
19-
20-
func installDLTSymlink(directory string) (string, error) {
14+
func installDLTSymlink(directory string) error {
2115
path, err := os.Executable()
2216
if err != nil {
23-
return "", err
17+
return err
2418
}
2519
realPath, err := filepath.EvalSymlinks(path)
2620
if err != nil {
27-
return "", err
21+
return err
2822
}
2923

3024
dir := directory
@@ -36,26 +30,25 @@ func installDLTSymlink(directory string) (string, error) {
3630
_, err = os.Lstat(dltPath)
3731
if err != nil {
3832
if !errors.Is(err, os.ErrNotExist) {
39-
return "", err
33+
return err
4034
}
4135
err = os.Symlink(realPath, dltPath)
4236
if err != nil {
43-
return "", err
37+
return err
4438
}
4539
cmdio.LogString(context.Background(), fmt.Sprintf("dlt successfully installed in directory %q", dir))
46-
return dltPath, nil
40+
return nil
4741
}
4842

4943
target, err := filepath.EvalSymlinks(dltPath)
5044
if err != nil {
51-
return "", err
45+
return err
5246
}
5347
if realPath == target {
5448
cmdio.LogString(context.Background(), fmt.Sprintf("dlt already installed in directory %q", dir))
55-
return dltPath, nil
49+
return nil
5650
}
57-
cmdio.LogString(context.Background(), fmt.Sprintf("cannot install dlt CLI: %q already exists", dltPath))
58-
return "", errors.New("installation failed")
51+
return fmt.Errorf("cannot install dlt CLI: %q already exists", dltPath)
5952
}
6053

6154
func InstallDLT() *cobra.Command {
@@ -65,19 +58,7 @@ func InstallDLT() *cobra.Command {
6558
Short: "Install DLT",
6659
Hidden: true,
6760
RunE: func(cmd *cobra.Command, args []string) error {
68-
dltPath, err := installDLTSymlink(directory)
69-
if err != nil {
70-
return err
71-
}
72-
response := installDLTResponse{
73-
SymlinkPath: dltPath,
74-
}
75-
switch root.OutputType(cmd) {
76-
case flags.OutputJSON:
77-
return cmdio.Render(cmd.Context(), response)
78-
default:
79-
return nil
80-
}
61+
return installDLTSymlink(directory)
8162
},
8263
}
8364
cmd.Flags().StringVarP(&directory, "directory", "d", "", "Directory in which to install dlt CLI (defaults to databricks CLI's directory)")

0 commit comments

Comments
 (0)