blob: f1a05ef87afd092387634f19e17409784045807c [file] [log] [blame]
#!/bin/bash
# Copyright 2025 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
### Test expected behavior of 'fx get-device'
BT_FILE_DEPS=(
"scripts/fx"
"tools/devshell/lib/vars.sh"
"tools/devshell/get-device"
"tools/devshell/lib/fx-cmd-locator.sh"
"tools/devshell/lib/fx-optional-features.sh"
"tools/devshell/lib/platform.sh"
"tools/devshell/lib/generate-ssh-config.sh"
)
declare fx ffx
BT_MKDIR_DEPS=(
"out/default"
)
BT_SET_UP() {
source "${BT_TEMP_DIR}/tools/devshell/tests/lib/fuchsia-mock.sh"
fx="$(btf::setup_fx)"
ffx="$(btf::make_installed_hosttools_mock ffx)"
FUCHSIA_DIR="${BT_TEMP_DIR}"
}
# Check that the ffx default target is returned from fx get-device.
TEST_fx-get-device-default-target-set() {
local out="${BT_TEMP_DIR}/_fx_get_device_output"
echo "foo" > "${FUCHSIA_DIR}/out/default.device"
cat >"${ffx}.mock_side_effects" <<INPUT
echo "<\$FUCHSIA_DEVICE_ADDR,\$FUCHSIA_NODENAME>"
INPUT
BT_EXPECT "${fx}" get-device >"$out" 2>&1
# Check that the output has the right message
BT_EXPECT_FILE_CONTAINS "${out}" "<,foo>"
}
# Check that the stderr from ffx default target is propagated.
TEST_fx-get-device-default-target-forwards-stderr() {
local out="${BT_TEMP_DIR}/_fx_get_device_output"
echo "No default target set." > "${ffx}.mock_stderr"
BT_EXPECT "${fx}" get-device >"$out" 2>&1
# Check that the output has the right message
BT_EXPECT_FILE_CONTAINS "${out}" "No default target set."
}
BT_RUN_TESTS "$@"