#!/bin/bash # # Copyright 2016 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Test //external mechanisms # set -euo pipefail # Load the test setup defined in the parent directory CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${CURRENT_DIR}/../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } source "${CURRENT_DIR}/remote_helpers.sh" \ || { echo "remote_helpers.sh not found!" >&2; exit 1; } function setup_zoo() { mkdir -p zoo cat > zoo/BUILD < zoo/BallPit.java < WORKSPACE <& $TEST_log || fail "Expected run to succeed" expect_log "Tra-la!" } function test_maven_jar_no_sha1_src() { setup_zoo serve_artifact com.example.carnivore carnivore 1.23 cat > WORKSPACE <& $TEST_log || fail "Expected run to succeed" expect_log "Tra-la!" } # Same as test_maven_jar, except omit sha1 implying "we don't care". function test_maven_jar_no_sha1() { serve_artifact com.example.carnivore carnivore 1.23 cat > WORKSPACE <& $TEST_log || fail "Expected run to succeed" expect_log "Tra-la!" } # makes sure both jar and srcjar are downloaded function test_maven_jar_downloads() { serve_artifact com.example.carnivore carnivore 1.23 cat > WORKSPACE <& $TEST_log || fail "Expected run to succeed" output_base="$(bazel info output_base)" test -e "${output_base}/external/endangered/jar/carnivore-1.23.jar" \ || fail "jar not downloaded to expected place" test -e "${output_base}/external/endangered/jar/carnivore-1.23-sources.jar" \ || fail "srcjar not downloaded to expected place" } function test_maven_jar_404() { setup_zoo serve_not_found cat > WORKSPACE <& $TEST_log && echo "Expected build to fail" kill_nc expect_log "Failed to fetch Maven dependency: Could not find artifact" } function test_maven_jar_mismatched_sha1() { setup_zoo serve_artifact com.example.carnivore carnivore 1.23 wrong_sha1="0123456789012345678901234567890123456789" cat > WORKSPACE <& $TEST_log && echo "Expected fetch to fail" expect_log "has SHA-1 of $sha1, does not match expected SHA-1 ($wrong_sha1)" } function test_default_repository() { serve_artifact thing amabop 1.9 cat > WORKSPACE < $TEST_log || fail "Building thing failed" expect_log "Target @thing_a_ma_bop//jar:jar up-to-date" } function test_settings() { serve_artifact thing amabop 1.9 cat > WORKSPACE < settings.xml < default EOF bazel build @thing_a_ma_bop//jar &> $TEST_log \ || fail "Building thing failed" expect_log "Target @thing_a_ma_bop//jar:jar up-to-date" # Create an invalid settings.xml (by using a tag that isn't allowed in # settings). cat > settings.xml < default EOF bazel clean --expunge bazel build @thing_a_ma_bop//jar &> $TEST_log \ && fail "Building thing succeeded" expect_log "Unrecognised tag: 'repositories'" } function test_maven_server_dep() { cat > WORKSPACE < BUILD < $TEST_log && fail "Building thing failed" expect_log "does not represent an actual repository" } function test_auth() { startup_auth_server create_artifact thing amabop 1.9 cat > WORKSPACE < settings.xml < x foo bar y foo baz EOF bazel build @good_auth//jar &> $TEST_log \ || fail "Expected correct password to work" expect_log "Target @good_auth//jar:jar up-to-date" bazel build @bad_auth//jar &> $TEST_log \ && fail "Expected incorrect password to fail" expect_log "Unauthorized (401)" } run_suite "maven tests"