From f770f9b9d75fc064da9bd5f6cd2e4072322f247c Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Tue, 2 Feb 2021 13:14:09 +0800 Subject: [PATCH] Add test cases for disabling repo downloads --- .../shell/bazel/starlark_repository_test.sh | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/test/shell/bazel/starlark_repository_test.sh b/src/test/shell/bazel/starlark_repository_test.sh index 06da53d3246f44..904a9c25b01d28 100755 --- a/src/test/shell/bazel/starlark_repository_test.sh +++ b/src/test/shell/bazel/starlark_repository_test.sh @@ -2061,4 +2061,92 @@ EOF || fail "Expected success despite needing a file behind basic auth" } +function test_disable_download_should_prevent_downloading() { + mkdir x + echo 'exports_files(["file.txt"])' > x/BUILD + echo 'Hello World' > x/file.txt + tar cvf x.tar x + sha256=$(sha256sum x.tar | head -c 64) + serve_file x.tar + + mkdir main + cd main + cat > WORKSPACE < BUILD <<'EOF' +genrule( + name = "it", + srcs = ["@ext//x:file.txt"], + outs = ["it.txt"], + cmd = "cp $< $@", +) +EOF + + bazel build --experimental_repository_disable_download //:it > "${TEST_log}" 2>&1 \ + && fail "Expected failure" || : + expect_log "Failed to download repo ext: download is disabled" +} + +function test_disable_download_should_allow_distdir() { + mkdir x + echo 'exports_files(["file.txt"])' > x/BUILD + echo 'Hello World' > x/file.txt + tar cvf x.tar x + sha256=$(sha256sum x.tar | head -c 64) + serve_file x.tar + + mkdir main + cd main + cat > WORKSPACE < BUILD <<'EOF' +genrule( + name = "it", + srcs = ["@ext//x:file.txt"], + outs = ["it.txt"], + cmd = "cp $< $@", +) +EOF + + bazel build --distdir="$(pwd)/.." --experimental_repository_disable_download //:it || fail "Failed to build" +} + +function test_disable_download_should_allow_local_repository() { + mkdir x + echo 'exports_files(["file.txt"])' > x/BUILD + echo 'Hello World' > x/file.txt + touch x/WORKSPACE + + mkdir main + cd main + cat > WORKSPACE < BUILD <<'EOF' +genrule( + name = "it", + srcs = ["@ext//:file.txt"], + outs = ["it.txt"], + cmd = "cp $< $@", +) +EOF + + bazel build --experimental_repository_disable_download //:it || fail "Failed to build" +} + run_suite "local repository tests"