summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-02-21 15:07:17 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-02-27 14:35:44 +0100
commitac3fc8b7ae3619703fd482718147423137df7399 (patch)
treed00f332d1a3339e6e40f7dac1d22cd4e86b8ba16 /test
parentad44470d3f2fa72bb36acf2eef9053920dd18ece (diff)
downloadjustbuild-ac3fc8b7ae3619703fd482718147423137df7399.tar.gz
test just-mr and serve: Check git-tree repository root creation
Extends test coverage for the interaction between 'just-mr setup' and the serve endpoint for git-tree repositories.
Diffstat (limited to 'test')
-rw-r--r--test/end-to-end/serve-service/TARGETS1
-rw-r--r--test/end-to-end/serve-service/serve-git-tree-root/TARGETS19
-rw-r--r--test/end-to-end/serve-service/serve-git-tree-root/absent.sh74
-rw-r--r--test/end-to-end/serve-service/serve-git-tree-root/present.sh99
4 files changed, 193 insertions, 0 deletions
diff --git a/test/end-to-end/serve-service/TARGETS b/test/end-to-end/serve-service/TARGETS
index 9d29a9ca..c8d519ef 100644
--- a/test/end-to-end/serve-service/TARGETS
+++ b/test/end-to-end/serve-service/TARGETS
@@ -140,6 +140,7 @@
[ [["./", "serve-archive-root", "TESTS"], "serve-archive-root"]
, [["./", "serve-git-root", "TESTS"], "serve-git-root"]
, [["./", "serve-file-root", "TESTS"], "serve-file-root"]
+ , [["./", "serve-git-tree-root", "TESTS"], "serve-git-tree-root"]
]
}
}
diff --git a/test/end-to-end/serve-service/serve-git-tree-root/TARGETS b/test/end-to-end/serve-service/serve-git-tree-root/TARGETS
new file mode 100644
index 00000000..664c08c4
--- /dev/null
+++ b/test/end-to-end/serve-service/serve-git-tree-root/TARGETS
@@ -0,0 +1,19 @@
+{ "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)"]]
+ }
+, "TESTS":
+ {"type": "install", "tainted": ["test"], "deps": ["present", "absent"]}
+}
diff --git a/test/end-to-end/serve-service/serve-git-tree-root/absent.sh b/test/end-to-end/serve-service/serve-git-tree-root/absent.sh
new file mode 100644
index 00000000..0eb6b444
--- /dev/null
+++ b/test/end-to-end/serve-service/serve-git-tree-root/absent.sh
@@ -0,0 +1,74 @@
+#!/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":
+ { "main":
+ { "repository":
+ { "type": "git tree"
+ , "id": "$TREE_0"
+ , "cmd": ["non_existent_script.sh"]
+ , "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 main)
+cat "${CONF}"
+echo
+test $(jq -r '.repositories.main.workspace_root[1]' "${CONF}") = "${TREE_0}"
+
+echo OK
diff --git a/test/end-to-end/serve-service/serve-git-tree-root/present.sh b/test/end-to-end/serve-service/serve-git-tree-root/present.sh
new file mode 100644
index 00000000..91f0982b
--- /dev/null
+++ b/test/end-to-end/serve-service/serve-git-tree-root/present.sh
@@ -0,0 +1,99 @@
+#!/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-tree repository
+# using the 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 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":
+ { "main":
+ { "repository":
+ { "type": "git tree"
+ , "id": "$TREE_0"
+ , "cmd": ["non_existent_script.sh"]
+ }
+ }
+ }
+}
+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}"
+
+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