Skip to content

Commit e164137

Browse files
author
Massimiliano Pippi
authored
"lib list" now returns an empty json array when there are no libraries installed (#511)
* add test for #443 * return an empty json array when there are no libs
1 parent 6b047bb commit e164137

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: cli/lib/list.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ func runListCommand(cmd *cobra.Command, args []string) {
6565
}
6666

6767
libs := res.GetInstalledLibrary()
68-
feedback.PrintResult(installedResult{libs})
6968

69+
// To uniform the output to other commands, when there are no result
70+
// print out an empty slice.
71+
if libs == nil {
72+
libs = []*rpc.InstalledLibrary{}
73+
}
74+
75+
feedback.PrintResult(installedResult{libs})
7076
logrus.Info("Done")
7177
}
7278

Diff for: test/test_lib.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_list(run_command):
2727
result = run_command("lib list --format json")
2828
assert result.ok
2929
assert "" == result.stderr
30-
assert "null" == result.stdout
30+
assert 0 == len(json.loads(result.stdout))
3131

3232
# Install something we can list at a version older than latest
3333
result = run_command("lib install [email protected]")
@@ -70,13 +70,21 @@ def test_update_index(run_command):
7070
)
7171

7272

73-
def test_remove(run_command):
74-
libs = ['"AzureIoTProtocol_MQTT"', '"CMMC MQTT Connector"', '"WiFiNINA"']
73+
def test_uninstall(run_command):
74+
libs = ['"AzureIoTProtocol_MQTT"', '"WiFiNINA"']
7575
assert run_command("lib install {}".format(" ".join(libs)))
7676

7777
result = run_command("lib uninstall {}".format(" ".join(libs)))
7878
assert result.ok
7979

80+
def test_uninstall_spaces(run_command):
81+
key = '"LiquidCrystal I2C"'
82+
assert run_command("lib install {}".format(key))
83+
assert run_command("lib uninstall {}".format(key))
84+
result = run_command("lib list --format json")
85+
assert result.ok
86+
assert len(json.loads(result.stdout)) == 0
87+
8088

8189
def test_search(run_command):
8290
assert run_command("lib update-index")

0 commit comments

Comments
 (0)