blob: f449c9ddb041ce48a015f84196f7acc511563f83 [file] [log] [blame]
#!/bin/bash
# Copyright 2021 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 setup-go
BT_FILE_DEPS=(
"scripts/fx"
"tools/devshell/contrib/setup-go"
"tools/devshell/go"
"tools/devshell/lib/fx-cmd-locator.sh"
"tools/devshell/lib/fx-optional-features.sh"
"tools/devshell/lib/generate-ssh-config.sh"
"tools/devshell/lib/platform.sh"
"tools/devshell/lib/vars.sh"
)
declare fx
declare go
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)"
# Ensures $FUCHSIA_BUILD_DIR is defined.
fx-config-read
mkdir -p "$FUCHSIA_DIR/vendor"
mkdir -p "$FUCHSIA_DIR/out"
mkdir -p "$FUCHSIA_DIR/third_party/golibs/vendor/golang.org"
touch "$FUCHSIA_DIR/third_party/golibs/go.mod"
touch "$FUCHSIA_DIR/third_party/golibs/go.sum"
go="${PREBUILT_GO_DIR}/bin/go"
btf::make_mock "$go"
}
TEST_go-setup() {
BT_ASSERT "$fx" setup-go
BT_EXPECT_FILE_EXISTS "$FUCHSIA_DIR/go.mod"
BT_EXPECT_FILE_EXISTS "$FUCHSIA_DIR/go.sum"
BT_EXPECT_FILE_EXISTS "$FUCHSIA_DIR/vendor/golang.org"
BT_EXPECT_SYMLINK "$FUCHSIA_DIR/vendor/fidl" \
"$FUCHSIA_BUILD_DIR/gopher/gen/fidl_for_ide/fidl"
# `go mod init` should have been called. This assumes that `out` is the first
# of several directories that the script runs `go mod init` in.
btf::expect-mock-args "${go}.mock_state.1" mod init go.fuchsia.dev/fuchsia/out
}
TEST_go-teardown() {
files=(
go.mod
go.sum
out/go.mod
third_party/go.mod
)
for file in "${files[@]}"; do
BT_ASSERT touch "$FUCHSIA_DIR/$file"
done
symlinks=(
vendor/golang.org
)
for file in "${symlinks[@]}"; do
BT_ASSERT ln -s "../third_party/golibs/$file" "$FUCHSIA_DIR/$file"
done
BT_ASSERT ln -s "$FUCHSIA_BUILD_DIR/gopher/gen/fidl_for_ide/fidl" "$FUCHSIA_DIR/vendor/fidl"
BT_ASSERT "$fx" setup-go -d
files_that_should_be_deleted=( "${files[@]}" "${symlinks[@]}" "vendor/fidl" )
for file in "${files_that_should_be_deleted[@]}"; do
BT_EXPECT_FILE_DOES_NOT_EXIST "$FUCHSIA_DIR/$file"
BT_EXPECT_FILE_IS_NOT_SYMLINK "$FUCHSIA_DIR/$file"
done
}
BT_RUN_TESTS "$@"