blob: b992c488e2eec9c949671a89c7da2832e73994e3 [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/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)"
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"
# `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 "$fx" setup-go -d
files_that_should_be_deleted=( "${files[@]}" "${symlinks[@]}" )
for file in "${files_that_should_be_deleted[@]}"; do
BT_EXPECT_FILE_DOES_NOT_EXIST "$FUCHSIA_DIR/$file"
done
}
BT_RUN_TESTS "$@"