diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-02-16 12:35:41 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-02-27 14:35:44 +0100 |
commit | 4cfd3a617b671bed6e8a85eb3c1c2b342511f424 (patch) | |
tree | b7f36a609b75ee8f1a76af6c2a36e73feac46503 /test/end-to-end/serve-service | |
parent | bd15e736cf720df2748629c91a2ac58f7aa0fec6 (diff) | |
download | justbuild-4cfd3a617b671bed6e8a85eb3c1c2b342511f424.tar.gz |
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.
Diffstat (limited to 'test/end-to-end/serve-service')
-rw-r--r-- | test/end-to-end/serve-service/TARGETS | 5 | ||||
-rw-r--r-- | test/end-to-end/serve-service/serve-git-root/TARGETS | 32 | ||||
-rw-r--r-- | test/end-to-end/serve-service/serve-git-root/absent-upload.sh | 106 | ||||
-rw-r--r-- | test/end-to-end/serve-service/serve-git-root/absent.sh | 113 | ||||
-rw-r--r-- | test/end-to-end/serve-service/serve-git-root/present.sh | 128 |
5 files changed, 383 insertions, 1 deletions
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 <<EOF +{ "repositories": + { "main": + { "repository": + { "type": "git" + , "commit": "$COMMIT" + , "repository": "${LOCAL_REPO}" + , "branch": "trunk" + , "subdir": "repo" + , "pragma": {"absent": true} + } + } + } +} +EOF + +### +# Run the checks +## + +# Setup an absent root from a local checkout. For a serve endpoint that does +# not have the commit available, this will upload the locally-known root tree +# to remote CAS, from where the serve endpoint will pick it up. This requires +# that the remotes are in native mode. +if [ -z "${COMPAT}" ]; then + + CONF=$("${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + ${ENDPOINT_ARGS} setup main) + cat "${CONF}" + echo + test $(jq -r '.repositories.main.workspace_root[1]' "${CONF}") = "${SUBTREE}" + +else + + echo --- + echo Checking expected failures + + "${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + ${ENDPOINT_ARGS} setup main 2>&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 <<EOF +{ "repositories": + { "present": + { "repository": + { "type": "git" + , "commit": "$COMMIT_0" + , "repository": "http://non-existent.example.org/data.git" + , "branch": "master" + , "subdir": "repo" + } + } + , "absent": + { "repository": + { "type": "git" + , "commit": "$COMMIT_0" + , "repository": "http://non-existent.example.org/data.git" + , "branch": "master" + , "subdir": "." + , "pragma": {"absent": true} + } + } + } +} +EOF + +### +# Run the checks +## + +# Compute absent root by asking serve to set it up from scratch. This works also +# in compatible mode. +rm -rf "${LBR}" + +CONF=$("${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + ${ENDPOINT_ARGS} setup absent) +cat "${CONF}" +echo +test $(jq -r '.repositories.absent.workspace_root[1]' "${CONF}") = "${TREE_0}" + +# Check that serve can provide also a subtree of this tree as present in a clean +# build root. This can only happen if remotes are in native mode. +if [ -z "${COMPAT}" ]; then + + rm -rf "${LBR}" + + CONF=$("${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + ${ENDPOINT_ARGS} setup present) + cat "${CONF}" + echo + +else + + echo --- + echo Checking expected failures + + rm -rf "${LBR}" + "${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + ${ENDPOINT_ARGS} setup present 2>&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 <<EOF +{ "repositories": + { "main": + { "repository": + { "type": "git" + , "commit": "$COMMIT_0" + , "repository": "http://non-existent.example.org/data.git" + , "branch": "master" + , "subdir": "." + } + } + } +} +EOF + +### +# Run the checks +## + +# Compute present root by asking the serve endpoint to set it up for us. This +# requires remotes in native mode. +if [ -z "${COMPAT}" ]; then + + CONF=$("${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + ${ENDPOINT_ARGS} setup main) + cat "${CONF}" + echo + test $(jq -r '.repositories.main.workspace_root[1]' "${CONF}") = "${TREE_0}" + + # Compute present root locally from now populated Git cache + ${JUST} gc --local-build-root ${LBR} 2>&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 <<EOF +{ "repositories": + { "main": + { "repository": + { "type": "git" + , "commit": "$COMMIT_0" + , "repository": "http://non-existent.example.org/data.git" + , "branch": "master" + , "subdir": "repo" + } + } + } +} +EOF + + CONF=$("${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + setup main) + cat "${CONF}" + echo + +else + + echo --- + echo Checking expected failures + + "${JUST_MR}" --norc -C repos.json \ + --just "${JUST}" \ + --local-build-root "${LBR}" \ + --log-limit 6 \ + ${ENDPOINT_ARGS} setup main 2>&1 && exit 1 || : + echo Failed as expected +fi + +echo OK |