blob: 7eab4acc7dc0c2557ee7eb1d1211488880e1923f [file] [log] [blame]
#!/bin/bash
# Copyright 2020 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 fx remote scripts
BT_FILE_DEPS=(
"scripts/fx"
"tools/devshell/serve-remote"
"tools/devshell/pave-remote"
"tools/devshell/lib/fvm.sh"
"tools/devshell/lib/fx-cmd-locator.sh"
"tools/devshell/lib/fx-optional-features.sh"
"tools/devshell/lib/fx-remote.sh"
"tools/devshell/lib/image_build_vars.sh"
"tools/devshell/lib/platform.sh"
"tools/devshell/lib/vars.sh"
"tools/devshell/lib/verify-default-keys.sh"
)
declare fx ssh_mock scp_mock local_gensshkeys_mock remote_gensshkeys_mock compare_remote_and_local_mock
BT_SET_UP() {
source "${BT_TEMP_DIR}/tools/devshell/lib/vars.sh"
source "${BT_TEMP_DIR}/tools/devshell/tests/lib/fuchsia-mock.sh"
fx="$(btf::setup_fx)"
ssh_mock=$(btf::make_mock_binary "ssh")
btf::add_binary_to_path "$ssh_mock"
scp_mock=$(btf::make_mock_binary "scp")
btf::add_binary_to_path "$scp_mock"
local_gensshkeys_mock="${BT_TEMP_DIR}/tools/ssh-keys/gen-ssh-keys.sh"
remote_gensshkeys_mock="${BT_TEMP_DIR}/tools/ssh-keys/remote-gen-ssh-keys.sh"
compare_remote_and_local_mock="${BT_TEMP_DIR}/tools/ssh-keys/compare_remote_and_local.sh"
btf::make_mock "${local_gensshkeys_mock}"
btf::make_mock "${remote_gensshkeys_mock}"
btf::make_mock "${compare_remote_and_local_mock}"
{
echo "function run_remote_gen_ssh_keys { ${remote_gensshkeys_mock} --description \"\$@\"; }"
echo "function run_remote_gen_ssh_keys_no_new_key { ${remote_gensshkeys_mock} --no-new-key; }"
echo "function compare_remote_and_local { ${compare_remote_and_local_mock} \"\$@\"; }"
} >> "${BT_TEMP_DIR}/tools/devshell/lib/verify-default-keys.sh"
ffx="$(btf::make_installed_hosttools_mock ffx)"
echo "127.0.0.1" > "${ffx}.mock_stdout"
}
# test if the host/dir info is correctly stored in the cache file
TEST_fx-remote-config-file() {
local testhost=myhostname.my.server.com
local testdir=~/myfuchsia/directory
local out="${BT_TEMP_DIR}/output.log"
BT_EXPECT ${fx} serve-remote "$testhost" "$testdir" >>${out} 2>&1
BT_EXPECT_FILE_CONTAINS "${BT_TEMP_DIR}/.fx-remote-config" "${testhost}:${testdir}"
}
# test if the cache file is used when no argument is given
TEST_fx-remote-default-args() {
local testhost=myhostname.my.server.com
local testdir=~/myfuchsia/directory
local out="${BT_TEMP_DIR}/output.log"
echo "${testhost}:${testdir}" > "${BT_TEMP_DIR}/.fx-remote-config"
BT_EXPECT ${fx} serve-remote >>${out} 2>&1
btf::does-mock-args-contain "${ssh_mock}.mock_state.1" "$testhost"
}
# test if the given host is used even when there's a cache file, and that the
# cache file is updated with the given host
TEST_fx-remote-args-given() {
local testhost=myhostname.my.server.com
local testdir=~/myfuchsia/directory
local anotherhost=myhostname.my.server.com
local out="${BT_TEMP_DIR}/output.log"
echo "${testhost}:${testdir}" > "${BT_TEMP_DIR}/.fx-remote-config"
BT_EXPECT ${fx} serve-remote "$anotherhost" "${testdir}" >>${out} 2>&1
BT_EXPECT_FILE_CONTAINS "${BT_TEMP_DIR}/.fx-remote-config" "${anotherhost}:${testdir}"
btf::does-mock-args-contain "${ssh_mock}.mock_state.1" "$anotherhost"
}
# keep in sync with //tools/ssh-keys/gen-ssh-keys.sh
readonly _ERROR_NO_KEY=112
readonly _ERROR_MISMATCHED_KEYS=113
# // keep in sync with //tools/ssh-keys/gen-ssh-keys.sh
# test pave-remote if the given host is used even when there's a cache file,
# and that the cache file is updated with the given host
TEST_fx-pave-remote-args-given() {
local testhost=myhostname.my.server.com
local testdir=~/myfuchsia/directory
local anotherhost=myhostname.my.server.com
local out="${BT_TEMP_DIR}/output.log"
{
echo "function fetch_remote_build_artifacts { :; }"
echo "function fetch_or_build_tool { :; }"
} >> "${BT_TEMP_DIR}/tools/devshell/lib/fx-remote.sh"
echo "${testhost}:${testdir}" > "${BT_TEMP_DIR}/.fx-remote-config"
BT_EXPECT ${fx} pave-remote --no-pave "$anotherhost" "${testdir}" >>${out} 2>&1
BT_EXPECT_FILE_CONTAINS "${BT_TEMP_DIR}/.fx-remote-config" "${anotherhost}:${testdir}"
btf::does-mock-args-contain "${ssh_mock}.mock_state" "$anotherhost"
}
BT_RUN_TESTS "$@"