diff --git a/project-clone/test/project-clone-test-basic.devworkspace.yaml b/project-clone/test/project-clone-test-basic.devworkspace.yaml index dd6187809..376bc9308 100644 --- a/project-clone/test/project-clone-test-basic.devworkspace.yaml +++ b/project-clone/test/project-clone-test-basic.devworkspace.yaml @@ -70,5 +70,5 @@ spec: fi echo "Project is on $branch_name, tracking $tracking_branch, with remotes configured" - echo "Test succeeded. Sleeping indefinitely" + echo "[SUCCESS] Test succeeded. Sleeping indefinitely" tail -f /dev/null diff --git a/project-clone/test/sparse-clone-test.devworkspace.yaml b/project-clone/test/sparse-clone-test.devworkspace.yaml new file mode 100644 index 000000000..7b57a972a --- /dev/null +++ b/project-clone/test/sparse-clone-test.devworkspace.yaml @@ -0,0 +1,106 @@ +apiVersion: workspace.devfile.io/v1alpha2 +kind: DevWorkspace +metadata: + name: sparse-clone-project-test + labels: + app.kubernetes.io/name: devworkspace-project-clone-tests + app.kubernetes.io/part-of: devworkspace-operator + annotations: + controller.devfile.io/debug-start: "true" +spec: + started: true + routingClass: 'basic' + template: + attributes: + controller.devfile.io/storage-type: ephemeral + variables: + test_runner_image: quay.io/devfile/project-clone:next # Requires git, bash + main_repo: https://github.com/devfile/devworkspace-operator.git + fork_repo: https://github.com/amisevsk/devworkspace-operator.git + checkout_branch: 0.21.x + project_subdir: project-clone + default_branch_name: main + projects: + - name: default-project-setup + git: + remotes: + main-origin: "{{main_repo}}" + - name: sparse-clone-project-1 + attributes: + sparseCheckout: "project-clone" # Can't use variable here as they are not replaced in attributes + git: + checkoutFrom: + remote: origin + revision: "{{checkout_branch}}" + remotes: + origin: "{{main_repo}}" + components: + - name: test-project-clone + container: + image: "{{test_runner_image}}" + memoryLimit: 512Mi + mountSources: true + command: + - "/bin/bash" + - "-c" + - | + set -e + + fail() { + echo "[ERROR] $1" + echo "[ERROR] See project-clone logs: " + echo "[ERROR] oc logs -n $DEVWORKSPACE_NAMESPACE deploy/$DEVWORKSPACE_ID -c project-clone" + exit 1 + } + + if [ -f "${PROJECTS_ROOT}/project-clone-errors.log" ]; then + echo "==== BEGIN PROJECT CLONE LOGS ====" + sed 's/^/ /g' "${PROJECTS_ROOT}/project-clone-errors.log" + echo "==== END PROJECT CLONE LOGS ====" + echo -e "\n\n" + fi + + for project_dir in "default-project-setup" "sparse-clone-project-1"; do + if [ ! -d "${PROJECTS_ROOT}/${project_dir}" ]; then + fail "Project $project_dir not cloned successfully" + fi + done + + echo "Testing default project set up" + cd "${PROJECTS_ROOT}/default-project-setup" + branch_name=$(git rev-parse --abbrev-ref HEAD) + if [ "$branch_name" != "{{default_branch_name}}" ]; then + fail "Project does not have default branch checked out" + fi + tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) + if [ "$tracking_branch" != "main-origin/{{default_branch_name}}" ]; then + fail "Default project's branch does not track remote branch" + fi + remote_url=$(git config remote.main-origin.url) + if [ "$remote_url" != "{{main_repo}}" ]; then + fail "Remote 'main-origin' not configured" + fi + echo "Project is on $branch_name, tracking $tracking_branch, with remotes configured" + + echo "Testing sparse-clone project is set up" + cd "${PROJECTS_ROOT}/sparse-clone-project-1" + branch_name=$(git rev-parse --abbrev-ref HEAD) + if [ "$branch_name" != "{{checkout_branch}}" ]; then + fail "Project does not have {{checkout_branch}} branch checked out" + fi + tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) + if [ "$tracking_branch" != "origin/{{checkout_branch}}" ]; then + fail "Checked out branch does not track remote branch origin/{{checkout_branch}}" + fi + remote_url=$(git config remote.origin.url) + if [ "$remote_url" != "{{main_repo}}" ]; then + fail "Remote 'origin' not configured" + fi + sparse_checkout_dirs=$(git sparse-checkout list) + if [ "$sparse_checkout_dirs" != "{{project_subdir}}" ]; then + fail "Sparse checkout is not configured" + fi + echo "Project is on $branch_name, tracking $tracking_branch, with remotes and sparse checkout configured" + + echo "[SUCCESS] Test succeeded. Sleeping indefinitely" + tail -f /dev/null diff --git a/project-clone/test/starter-project-test.devworkspace.yaml b/project-clone/test/starter-project-test.devworkspace.yaml index a89fdb7d1..7c71efc25 100644 --- a/project-clone/test/starter-project-test.devworkspace.yaml +++ b/project-clone/test/starter-project-test.devworkspace.yaml @@ -89,23 +89,12 @@ spec: echo "Testing starter project is set up" cd "${PROJECTS_ROOT}/starter-project-1" - branch_name=$(git rev-parse --abbrev-ref HEAD) - if [ "$branch_name" != "{{checkout_branch}}" ]; then - fail "Project does not have {{checkout_branch}} branch checked out" - fi - tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) - if [ "$tracking_branch" != "origin/{{checkout_branch}}" ]; then - fail "Checked out branch does not track remote branch origin/{{checkout_branch}}" - fi - remote_url=$(git config remote.origin.url) - if [ "$remote_url" != "{{main_repo}}" ]; then - fail "Remote 'origin' not configured" - fi - sparse_checkout_dirs=$(git sparse-checkout list) - if [ "$sparse_checkout_dirs" != "{{project_subdir}}" ]; then - fail "Sparse checkout is not configured" + if [ $(git rev-parse --is-inside-work-tree) == "true" ]; then + fail "Do not expect subDir starter project to be a git repository" fi - echo "Project is on $branch_name, tracking $tracking_branch, with remotes and sparse checkout configured" + echo "Files inside starter project directory:" + ls -l + echo "Project directory is present" echo "[SUCCESS] Test succeeded. Sleeping indefinitely" tail -f /dev/null