Add regression test for Cargo SCP-like Git submodule URLs
Add downstreamed version of upstream test git::dep_with_scp_like_submodule_url to verify that Cargo correctly handles SCP-like URLs (git@host:path format) in Git submodules and preserves them in error messages. This is a regression test for https://github.com/rust-lang/cargo/pull/16727 The test is enabled on distributions with Rust >= 1.96.0. Upstream reference: https://github.com/rust-lang/cargo/blob/master/tests/testsuite/git.rs
This commit is contained in:
parent
ff5a5aa591
commit
cca2ad09ef
3 changed files with 155 additions and 2 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
|
|
@ -10,6 +10,6 @@ repos:
|
|||
args: [--unsafe]
|
||||
- id: check-added-large-files
|
||||
- repo: https://github.com/teemtee/tmt.git
|
||||
rev: "1.31.0"
|
||||
rev: "1.75.0"
|
||||
hooks:
|
||||
- id: tmt-lint
|
||||
|
|
|
|||
31
tests/Regression/cargo-git-submodule-scp-url/main.fmf
Normal file
31
tests/Regression/cargo-git-submodule-scp-url/main.fmf
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
summary: Test cargo handles SCP-like Git submodule URLs
|
||||
description: |
|
||||
Downstreamed version of the upstream test git::dep_with_scp_like_submodule_url
|
||||
https://github.com/rust-lang/cargo/blob/master/tests/testsuite/git.rs
|
||||
|
||||
This test verifies that Cargo correctly handles Git submodules with SCP-like
|
||||
URLs (git@github.com:foo/bar.git format) and preserves the original URL format
|
||||
in error messages.
|
||||
|
||||
This is a regression test for https://github.com/rust-lang/cargo/pull/16727
|
||||
|
||||
The test uses git-fetch-with-cli to enable SSH support via /usr/bin/git, which
|
||||
works even on RHEL/CentOS where Cargo is built without libssh2 (rhbz#1732949).
|
||||
|
||||
The test is enabled on distributions with Rust >= 1.96.0.
|
||||
|
||||
tier: 1
|
||||
require+:
|
||||
- git
|
||||
adjust+:
|
||||
- enabled: false
|
||||
when: distro ~< rhel-8.10
|
||||
continue: false
|
||||
|
||||
- enabled: false
|
||||
when: distro ~< rhel-9.9
|
||||
continue: false
|
||||
|
||||
- enabled: false
|
||||
when: distro ~< rhel-10.3
|
||||
continue: false
|
||||
122
tests/Regression/cargo-git-submodule-scp-url/runtest.sh
Executable file
122
tests/Regression/cargo-git-submodule-scp-url/runtest.sh
Executable file
|
|
@ -0,0 +1,122 @@
|
|||
#!/bin/bash
|
||||
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
||||
#
|
||||
# Downstreamed adaptation of the upstream Cargo test:
|
||||
# git::dep_with_scp_like_submodule_url
|
||||
# https://github.com/rust-lang/cargo/blob/master/tests/testsuite/git.rs
|
||||
#
|
||||
# REGRESSION TEST for https://github.com/rust-lang/cargo/pull/16727
|
||||
#
|
||||
# This test verifies that Cargo correctly handles SCP-like URLs (git@host:path)
|
||||
# in git submodules and preserves them in error messages.
|
||||
#
|
||||
# The test uses --config net.git-fetch-with-cli=true to delegate Git operations
|
||||
# to /usr/bin/git, which has SSH support even on RHEL/CentOS where Cargo is built
|
||||
# without libssh2 (rhbz#1732949).
|
||||
#
|
||||
# Expected behavior WITH the PR #16727 fix (Rust >= 1.96.0):
|
||||
# - Cargo accepts SCP-like URLs in .gitmodules
|
||||
# - Attempts to fetch the submodule via /usr/bin/git (with SSH support)
|
||||
# - On failure, shows: "failed to fetch submodule `submod` from git@github.com:foo/bar.git"
|
||||
#
|
||||
# Expected behavior WITHOUT the fix (Rust < 1.96.0):
|
||||
# - Cargo rejects SCP-like URLs as invalid
|
||||
# - Shows: "invalid url `git@github.com:foo/bar.git`: relative URL without a base"
|
||||
# - This test will FAIL (expected for a regression test before the fix is applied)
|
||||
#
|
||||
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
||||
|
||||
CRATE_NAME="foo"
|
||||
CRATE_VER="0.5.0"
|
||||
DEP1_NAME="dep1"
|
||||
DEP2_NAME="dep2"
|
||||
SCP_URL="git@github.com:foo/bar.git"
|
||||
|
||||
rlJournalStart
|
||||
rlPhaseStartSetup
|
||||
declare tmp
|
||||
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
|
||||
rlRun "pushd $tmp"
|
||||
|
||||
# Create dep2 git repository (will be used as submodule)
|
||||
rlRun "mkdir $DEP2_NAME && cd $DEP2_NAME"
|
||||
rlRun "git init"
|
||||
rlRun "echo 'pub fn dep2() {}' > lib.rs"
|
||||
rlRun "git add lib.rs"
|
||||
rlRun "git -c user.name='Test' -c user.email='test@test' commit -m 'Initial commit'"
|
||||
rlRun "DEP2_PATH=\$(pwd)"
|
||||
rlRun "cd .."
|
||||
|
||||
# Create dep1 git repository with Cargo.toml
|
||||
rlRun "mkdir $DEP1_NAME && cd $DEP1_NAME"
|
||||
rlRun "git init"
|
||||
rlRun "mkdir src"
|
||||
rlRun "echo 'pub fn dep() {}' > src/lib.rs"
|
||||
cat > Cargo.toml <<EOF
|
||||
[package]
|
||||
name = "$DEP1_NAME"
|
||||
version = "$CRATE_VER"
|
||||
edition = "2015"
|
||||
EOF
|
||||
rlRun "git add ."
|
||||
rlRun "git -c user.name='Test' -c user.email='test@test' commit -m 'Initial commit'"
|
||||
|
||||
# Manually add dep2 as submodule to avoid file:// protocol restrictions
|
||||
# Use git -c to allow file:// protocol temporarily
|
||||
rlRun "git -c protocol.file.allow=always submodule add \$DEP2_PATH submod"
|
||||
rlRun "git -c user.name='Test' -c user.email='test@test' commit -m 'Add submodule'"
|
||||
|
||||
# Change .gitmodules to use SCP-like URL
|
||||
cat > .gitmodules <<EOF
|
||||
[submodule "submod"]
|
||||
path = submod
|
||||
url = $SCP_URL
|
||||
EOF
|
||||
rlRun "git add .gitmodules"
|
||||
rlRun "git -c user.name='Test' -c user.email='test@test' commit -m 'Change to SCP URL'"
|
||||
|
||||
rlRun "DEP1_PATH=\$(pwd)"
|
||||
rlRun "cd .."
|
||||
|
||||
# Create main project that depends on dep1
|
||||
rlRun "mkdir $CRATE_NAME && cd $CRATE_NAME"
|
||||
rlRun "mkdir src"
|
||||
rlRun "touch src/lib.rs"
|
||||
|
||||
# Create Cargo.toml with proper variable expansion
|
||||
rlRun "cat > Cargo.toml <<CARGO_EOF
|
||||
[package]
|
||||
name = \"$CRATE_NAME\"
|
||||
version = \"$CRATE_VER\"
|
||||
edition = \"2015\"
|
||||
|
||||
[dependencies.$DEP1_NAME]
|
||||
git = \"file://\$DEP1_PATH\"
|
||||
CARGO_EOF
|
||||
"
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest
|
||||
rlRun "set -o pipefail"
|
||||
|
||||
# Set GIT_SSH_COMMAND to match upstream test behavior
|
||||
# This ensures Git attempts SSH connection (even though it will fail)
|
||||
rlRun "export GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR'"
|
||||
|
||||
# Execute cargo fetch - should fail with exit code 101
|
||||
# Let cargo invoke git cli, as in RHEL it doesn't have libssh2 support
|
||||
rlRun "cargo --config net.git-fetch-with-cli=true fetch -v 2>&1 | tee output.log" 101
|
||||
|
||||
# Verify the exact error message that indicates PR #16727 is applied
|
||||
# The test expects Cargo to:
|
||||
# 1. Show it's updating the git submodule with the SCP URL
|
||||
# 2. Fail with a specific message that includes the SCP URL
|
||||
rlAssertGrep "git submodule.*$SCP_URL" output.log -Ei
|
||||
rlAssertGrep "failed to fetch submodule.*submod.*from.*$SCP_URL" output.log -Ei
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartCleanup
|
||||
rlRun "popd"
|
||||
rlRun "rm -rf $tmp" 0 "Remove tmp directory"
|
||||
rlPhaseEnd
|
||||
rlJournalEnd
|
||||
Loading…
Add table
Add a link
Reference in a new issue