Skip to content

Commit

Permalink
"lib list" now returns an empty json array when there are no librarie…
Browse files Browse the repository at this point in the history
…s installed (#511)

* add test for #443

* return an empty json array when there are no libs
  • Loading branch information
Massimiliano Pippi committed Dec 13, 2019
1 parent 6b047bb commit e164137
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cli/lib/list.go
Expand Up @@ -65,8 +65,14 @@ func runListCommand(cmd *cobra.Command, args []string) {
}

libs := res.GetInstalledLibrary()
feedback.PrintResult(installedResult{libs})

// To uniform the output to other commands, when there are no result
// print out an empty slice.
if libs == nil {
libs = []*rpc.InstalledLibrary{}
}

feedback.PrintResult(installedResult{libs})
logrus.Info("Done")
}

Expand Down
14 changes: 11 additions & 3 deletions test/test_lib.py
Expand Up @@ -27,7 +27,7 @@ def test_list(run_command):
result = run_command("lib list --format json")
assert result.ok
assert "" == result.stderr
assert "null" == result.stdout
assert 0 == len(json.loads(result.stdout))

# Install something we can list at a version older than latest
result = run_command("lib install ArduinoJson@6.11.0")
Expand Down Expand Up @@ -70,13 +70,21 @@ def test_update_index(run_command):
)


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

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

def test_uninstall_spaces(run_command):
key = '"LiquidCrystal I2C"'
assert run_command("lib install {}".format(key))
assert run_command("lib uninstall {}".format(key))
result = run_command("lib list --format json")
assert result.ok
assert len(json.loads(result.stdout)) == 0


def test_search(run_command):
assert run_command("lib update-index")
Expand Down

0 comments on commit e164137

Please sign in to comment.