From 4cfd3a617b671bed6e8a85eb3c1c2b342511f424 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 16 Feb 2024 12:35:41 +0100 Subject: test just-mr and serve: Check git repository root creation Extends test coverage for the interaction between 'just-mr setup' and the serve endpoint for git repositories. --- test/end-to-end/serve-service/TARGETS | 5 +- .../serve-service/serve-git-root/TARGETS | 32 ++++++ .../serve-service/serve-git-root/absent-upload.sh | 106 +++++++++++++++++ .../serve-service/serve-git-root/absent.sh | 113 ++++++++++++++++++ .../serve-service/serve-git-root/present.sh | 128 +++++++++++++++++++++ 5 files changed, 383 insertions(+), 1 deletion(-) create mode 100644 test/end-to-end/serve-service/serve-git-root/TARGETS create mode 100644 test/end-to-end/serve-service/serve-git-root/absent-upload.sh create mode 100644 test/end-to-end/serve-service/serve-git-root/absent.sh create mode 100644 test/end-to-end/serve-service/serve-git-root/present.sh (limited to 'test') diff --git a/test/end-to-end/serve-service/TARGETS b/test/end-to-end/serve-service/TARGETS index 9ad5128c..9b0325cb 100644 --- a/test/end-to-end/serve-service/TARGETS +++ b/test/end-to-end/serve-service/TARGETS @@ -136,6 +136,9 @@ } ] } - , "dirs": [[["./", "serve-archive-root", "TESTS"], "serve-archive-root"]] + , "dirs": + [ [["./", "serve-archive-root", "TESTS"], "serve-archive-root"] + , [["./", "serve-git-root", "TESTS"], "serve-git-root"] + ] } } diff --git a/test/end-to-end/serve-service/serve-git-root/TARGETS b/test/end-to-end/serve-service/serve-git-root/TARGETS new file mode 100644 index 00000000..db390833 --- /dev/null +++ b/test/end-to-end/serve-service/serve-git-root/TARGETS @@ -0,0 +1,32 @@ +{ "present": + { "type": ["end-to-end", "with serve"] + , "name": ["present"] + , "test": ["present.sh"] + , "deps": + [["end-to-end", "mr-tool-under-test"], ["end-to-end", "tool-under-test"]] + , "repos": [["end-to-end/serve-service", "serve-tree (data)"]] + } +, "absent": + { "type": ["end-to-end", "with serve"] + , "name": ["absent"] + , "test": ["absent.sh"] + , "deps": + [["end-to-end", "mr-tool-under-test"], ["end-to-end", "tool-under-test"]] + , "repos": [["end-to-end/serve-service", "serve-tree (data)"]] + } +, "absent-upload": + { "type": ["end-to-end", "with serve"] + , "name": ["absent-upload"] + , "test": ["absent-upload.sh"] + , "deps": + [ ["end-to-end", "mr-tool-under-test"] + , ["end-to-end", "tool-under-test"] + , ["end-to-end/serve-service", "serve-tree (archive)"] + ] + } +, "TESTS": + { "type": "install" + , "tainted": ["test"] + , "deps": ["present", "absent", "absent-upload"] + } +} diff --git a/test/end-to-end/serve-service/serve-git-root/absent-upload.sh b/test/end-to-end/serve-service/serve-git-root/absent-upload.sh new file mode 100644 index 00000000..e41dccfd --- /dev/null +++ b/test/end-to-end/serve-service/serve-git-root/absent-upload.sh @@ -0,0 +1,106 @@ +#!/bin/sh +# Copyright 2024 Huawei Cloud Computing Technology Co., Ltd. +# +# 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. + + +### +# This test checks that an absent root known in a local checkout can be +# successfully uploaded to a serve endpoint. This can only succeed in native +# mode. +## + +set -eu + +readonly JUST="${PWD}/bin/tool-under-test" +readonly JUST_MR="${PWD}/bin/mr-tool-under-test" +readonly LOCAL_REPO="${TEST_TMPDIR}/repo_root" +readonly LBR="${TEST_TMPDIR}/local-build-root" + +COMPAT="" +if [ "${COMPATIBLE:-}" = "YES" ]; then + COMPAT="--compatible" +fi + +ENDPOINT_ARGS="-r ${REMOTE_EXECUTION_ADDRESS} -R ${SERVE} ${COMPAT}" + +### +# Setup sample repos config +## + +mkdir -p "${LOCAL_REPO}" +tar xf src.tar -C "${LOCAL_REPO}" + +cd "${LOCAL_REPO}" +git init -b trunk +git config user.name 'N.O.Body' +git config user.email 'nobody@example.org' +git add -f . +git commit -m 'Test repo' 2>&1 +COMMIT=$(git log -n 1 --format="%H") +SUBTREE=$(git ls-tree "$COMMIT" repo | awk '{print $3}') +cd - + +mkdir work +cd work + +touch ROOT +cat > repos.json <&1 && exit 1 || : + echo Failed as expected +fi + +echo OK diff --git a/test/end-to-end/serve-service/serve-git-root/absent.sh b/test/end-to-end/serve-service/serve-git-root/absent.sh new file mode 100644 index 00000000..81a50349 --- /dev/null +++ b/test/end-to-end/serve-service/serve-git-root/absent.sh @@ -0,0 +1,113 @@ +#!/bin/sh +# Copyright 2024 Huawei Cloud Computing Technology Co., Ltd. +# +# 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. + + +### +# This test checks that an absent root can successfully be made by asking +# the serve endpoint to set it up for us when we have no local knowledge. +## + +set -eu + +readonly JUST="${PWD}/bin/tool-under-test" +readonly JUST_MR="${PWD}/bin/mr-tool-under-test" +readonly LBR="${TEST_TMPDIR}/local-build-root" + +COMPAT="" +if [ "${COMPATIBLE:-}" = "YES" ]; then + COMPAT="--compatible" +fi + +ENDPOINT_ARGS="-r ${REMOTE_EXECUTION_ADDRESS} -R ${SERVE} ${COMPAT}" + +### +# Setup sample repos config with present and absent repos +## + +mkdir work +cd work + +touch ROOT +cat > repos.json <&1 && exit 1 || : + echo Failed as expected +fi + +echo OK diff --git a/test/end-to-end/serve-service/serve-git-root/present.sh b/test/end-to-end/serve-service/serve-git-root/present.sh new file mode 100644 index 00000000..2682a050 --- /dev/null +++ b/test/end-to-end/serve-service/serve-git-root/present.sh @@ -0,0 +1,128 @@ +#!/bin/sh +# Copyright 2024 Huawei Cloud Computing Technology Co., Ltd. +# +# 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. + + +### +# This test checks if we can make a present root for a Git repository using the +# serve endpoint. +## + +set -eu + +readonly JUST="${PWD}/bin/tool-under-test" +readonly JUST_MR="${PWD}/bin/mr-tool-under-test" +readonly LBR="${TEST_TMPDIR}/local-build-root" + +COMPAT="" +if [ "${COMPATIBLE:-}" = "YES" ]; then + COMPAT="--compatible" +fi + +ENDPOINT_ARGS="-r ${REMOTE_EXECUTION_ADDRESS} -R ${SERVE} ${COMPAT}" + +### +# Setup sample repos config +## + +mkdir work +cd work + +touch ROOT +cat > repos.json <&1 + ${JUST} gc --local-build-root ${LBR} 2>&1 + + CONF=$("${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + setup main) + cat "${CONF}" + echo + test $(jq -r '.repositories.main.workspace_root[1]' "${CONF}") = "${TREE_0}" + + # Check that the subdir is also working correctly + ${JUST} gc --local-build-root ${LBR} 2>&1 + ${JUST} gc --local-build-root ${LBR} 2>&1 + + cat > repos.json <&1 && exit 1 || : + echo Failed as expected +fi + +echo OK -- cgit v1.2.3