2020-07-12 02:23:07 +08:00
|
|
|
## This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
## License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2019-04-19 09:10:42 +08:00
|
|
|
##
|
2020-03-10 22:39:56 +08:00
|
|
|
## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
|
2019-04-19 09:10:42 +08:00
|
|
|
|
|
|
|
defmodule JSONFormattingTest do
|
|
|
|
use ExUnit.Case, async: false
|
|
|
|
import ExUnit.CaptureIO
|
|
|
|
import RabbitMQ.CLI.Core.ExitCodes
|
|
|
|
import TestHelper
|
|
|
|
|
|
|
|
setup_all do
|
|
|
|
RabbitMQ.CLI.Core.Distribution.start()
|
|
|
|
|
|
|
|
set_scope(:all)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2019-04-19 09:10:42 +08:00
|
|
|
test "JSON output of status" do
|
|
|
|
set_scope(:ctl)
|
|
|
|
|
|
|
|
node = to_string(get_rabbit_hostname())
|
|
|
|
command = ["status", "-n", node, "--formatter=json"]
|
2022-10-03 01:54:11 +08:00
|
|
|
|
|
|
|
output =
|
|
|
|
capture_io(:stdio, fn ->
|
|
|
|
error_check(command, exit_ok())
|
|
|
|
end)
|
|
|
|
|
2019-04-19 09:10:42 +08:00
|
|
|
{:ok, doc} = JSON.decode(output)
|
|
|
|
|
|
|
|
assert Map.has_key?(doc, "memory")
|
|
|
|
assert Map.has_key?(doc, "file_descriptors")
|
|
|
|
assert Map.has_key?(doc, "listeners")
|
|
|
|
assert Map.has_key?(doc, "processes")
|
|
|
|
assert Map.has_key?(doc, "os")
|
|
|
|
assert Map.has_key?(doc, "pid")
|
|
|
|
assert Map.has_key?(doc, "rabbitmq_version")
|
|
|
|
|
|
|
|
assert doc["alarms"] == []
|
|
|
|
end
|
|
|
|
|
2019-04-19 09:10:42 +08:00
|
|
|
test "JSON output of cluster_status" do
|
|
|
|
set_scope(:ctl)
|
|
|
|
|
|
|
|
node = to_string(get_rabbit_hostname())
|
|
|
|
command = ["cluster_status", "-n", node, "--formatter=json"]
|
2022-10-03 01:54:11 +08:00
|
|
|
|
|
|
|
output =
|
|
|
|
capture_io(:stdio, fn ->
|
|
|
|
error_check(command, exit_ok())
|
|
|
|
end)
|
|
|
|
|
2019-04-19 09:10:42 +08:00
|
|
|
{:ok, doc} = JSON.decode(output)
|
|
|
|
|
|
|
|
assert Enum.member?(doc["disk_nodes"], node)
|
|
|
|
assert Map.has_key?(doc["listeners"], node)
|
|
|
|
assert Map.has_key?(doc["versions"], node)
|
|
|
|
assert doc["alarms"] == []
|
|
|
|
assert doc["partitions"] == %{}
|
|
|
|
end
|
|
|
|
end
|