aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar Jingwen Chen <jingwen@google.com>2016-11-03 15:20:48 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-11-03 16:12:22 +0000
commit38e54ac14e69113e9790ce9a526784e0f18e4b6e (patch)
tree345bec2131dd53d2496e95b9c26b1309c413c081 /src/test/shell
parent614fdc3c7fbcc2656e48d6ea9e0c0749cf5c57ce (diff)
Implemented repository caching for native maven_jar rules.
GITHUB: #1752 -- MOS_MIGRATED_REVID=138072464
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/bazel/bazel_repository_cache_test.sh86
1 files changed, 84 insertions, 2 deletions
diff --git a/src/test/shell/bazel/bazel_repository_cache_test.sh b/src/test/shell/bazel/bazel_repository_cache_test.sh
index dc563220f6..e503d683a8 100755
--- a/src/test/shell/bazel/bazel_repository_cache_test.sh
+++ b/src/test/shell/bazel/bazel_repository_cache_test.sh
@@ -71,6 +71,40 @@ EOF
touch BUILD
}
+function setup_maven_repository() {
+ mkdir -p zoo
+ cat > zoo/BUILD <<EOF
+java_binary(
+ name = "ball-pit",
+ srcs = ["BallPit.java"],
+ main_class = "BallPit",
+ deps = ["//external:mongoose"],
+)
+EOF
+
+ cat > zoo/BallPit.java <<EOF
+import carnivore.Mongoose;
+
+public class BallPit {
+ public static void main(String args[]) {
+ Mongoose.frolic();
+ }
+}
+EOF
+
+ serve_artifact com.example.carnivore carnivore 1.23
+
+ cat > WORKSPACE <<EOF
+maven_jar(
+ name = 'endangered',
+ artifact = "com.example.carnivore:carnivore:1.23",
+ repository = 'http://localhost:$fileserver_port/',
+ sha1 = '$sha1',
+)
+bind(name = 'mongoose', actual = '@endangered//jar')
+EOF
+}
+
# Test downloading a file from a repository.
# This creates a simple repository containing:
#
@@ -326,7 +360,7 @@ EOF
expect_log "All external dependencies fetched successfully"
}
-function test_load_skylark_download_fail_without_cache() {
+function test_skylark_download_fail_without_cache() {
setup_skylark_repository
cat >test.bzl <<EOF
@@ -379,7 +413,7 @@ EOF
expect_log "All external dependencies fetched successfully"
}
-function test_load_skylark_download_and_extract_fail_without_cache() {
+function test_skylark_download_and_extract_fail_without_cache() {
setup_skylark_repository
cat >test.bzl <<EOF
@@ -407,4 +441,52 @@ EOF
expect_log "Error downloading"
}
+function test_maven_jar_exists_in_cache() {
+ setup_maven_repository
+
+ bazel fetch --experimental_repository_cache="$repo_cache_dir" //zoo:ball-pit >& $TEST_log \
+ || echo "Expected fetch to succeed"
+
+ if [ ! -f $repo_cache_dir/content_addressable/sha1/$sha1/file ]; then
+ fail "the file was not cached successfully"
+ fi
+}
+
+function test_load_cached_value_maven_jar() {
+ setup_maven_repository
+
+ bazel fetch --experimental_repository_cache="$repo_cache_dir" //zoo:ball-pit >& $TEST_log \
+ || echo "Expected fetch to succeed"
+
+ # Kill the server
+ shutdown_server
+ bazel clean --expunge
+
+ # Fetch again
+ bazel fetch --experimental_repository_cache="$repo_cache_dir" //zoo:ball-pit >& $TEST_log \
+ || echo "Expected fetch to succeed"
+
+ expect_log "All external dependencies fetched successfully"
+}
+
+function test_maven_jar_fail_without_cache() {
+ setup_maven_repository
+
+ bazel fetch --experimental_repository_cache="$repo_cache_dir" //zoo:ball-pit >& $TEST_log \
+ || echo "Expected fetch to succeed"
+
+ # Kill the server
+ shutdown_server
+ bazel clean --expunge
+
+ # Clean the repository cache
+ rm -rf "$repo_cache_dir"
+
+ # Fetch again
+ bazel fetch --experimental_repository_cache="$repo_cache_dir" //zoo:ball-pit >& $TEST_log \
+ && echo "Expected fetch to fail"
+
+ expect_log "Failed to fetch Maven dependency"
+}
+
run_suite "repository cache tests"