From 41e049339b6c1a38dd0f287c25641faf1deaec47 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Thu, 4 Mar 2021 19:32:18 +0100 Subject: [PATCH] Fix --extract option in ledger api test tool (#9029) This broke in #8894 changelog_begin changelog_end windows is great changelog_begin changelog_end --- ledger/ledger-api-test-tool/BUILD.bazel | 21 +++++++++ .../api/testtool/LedgerApiTestTool.scala | 2 +- ledger/ledger-api-test-tool/test-extract.sh | 47 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 ledger/ledger-api-test-tool/test-extract.sh diff --git a/ledger/ledger-api-test-tool/BUILD.bazel b/ledger/ledger-api-test-tool/BUILD.bazel index 0e520094ca7..21824f0b350 100644 --- a/ledger/ledger-api-test-tool/BUILD.bazel +++ b/ledger/ledger-api-test-tool/BUILD.bazel @@ -30,6 +30,7 @@ load( ":conformance.bzl", "conformance_test", ) +load("@os_info//:os_info.bzl", "is_windows") # we release ledger-api-test-tool-stable as ledger-api-test-tool da_scala_binary( @@ -270,3 +271,23 @@ conformance_test( ], test_tool_args = ["--verbose"], ) + +# This deliberately uses the deploy.jar since that’s what we ship +# and we want to test that the extract option works there. +# Given subleties in classpaths, it could potentially work +# in the non-deploy jar. +sh_test( + name = "test-extract", + srcs = ["test-extract.sh"], + args = [ + "$(location @local_jdk//:bin/java.exe)" if is_windows else "$(location @local_jdk//:bin/java)", + "$(location :ledger-api-test-tool_deploy.jar)", + ], + data = [ + ":ledger-api-test-tool_deploy.jar", + "@local_jdk//:bin/java.exe" if is_windows else "@local_jdk//:bin/java", + ], + deps = [ + "@bazel_tools//tools/bash/runfiles", + ], +) diff --git a/ledger/ledger-api-test-tool/src/main/scala/com/daml/ledger/api/testtool/LedgerApiTestTool.scala b/ledger/ledger-api-test-tool/src/main/scala/com/daml/ledger/api/testtool/LedgerApiTestTool.scala index 4cad6c0f46b..16681204f56 100644 --- a/ledger/ledger-api-test-tool/src/main/scala/com/daml/ledger/api/testtool/LedgerApiTestTool.scala +++ b/ledger/ledger-api-test-tool/src/main/scala/com/daml/ledger/api/testtool/LedgerApiTestTool.scala @@ -70,7 +70,7 @@ object LedgerApiTestTool { val pwd = Paths.get(".").toAbsolutePath println(s"Extracting all DAML resources necessary to run the tests into $pwd.") for (resource <- resources) { - val is = getClass.getResourceAsStream(resource) + val is = getClass.getClassLoader.getResourceAsStream(resource) if (is == null) sys.error(s"Could not find $resource in classpath") val targetFile = new File(new File(resource).getName) Files.copy(is, targetFile.toPath, StandardCopyOption.REPLACE_EXISTING) diff --git a/ledger/ledger-api-test-tool/test-extract.sh b/ledger/ledger-api-test-tool/test-extract.sh new file mode 100755 index 00000000000..f7391864b19 --- /dev/null +++ b/ledger/ledger-api-test-tool/test-extract.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# +# Golden scenario tests +# + +set -eu + +export LC_ALL="en_US.UTF-8" + +# --- begin runfiles.bash initialization --- +# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). +if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ -f "$0.runfiles_manifest" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" + elif [[ -f "$0.runfiles/MANIFEST" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" + elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + export RUNFILES_DIR="$0.runfiles" + fi +fi +if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" +elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ + "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" +else + echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" + exit 1 +fi +# --- end runfiles.bash initialization --- + +JAVA=$(rlocation "$TEST_WORKSPACE/$1") +TEST_TOOL=$(rlocation "$TEST_WORKSPACE/$2") + +DIR=$(mktemp -d) +trap "rm -rf $$DIR" EXIT + +cd $DIR +$JAVA -jar $TEST_TOOL --extract +if [[ $(ls | wc -l) != 4 ]]; then + echo "Expected 4 DARs but got:" + ls + exit 1 +fi