[aur-dev] [PATCH 1/3] t0003: Make tests more strict
Instead of testing the exit code only, also check the error output. This reveals two bugs. The corresponding tests are marked as known breakages. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/test/t0003-update.sh | 91 ++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/git-interface/test/t0003-update.sh b/git-interface/test/t0003-update.sh index aeb223e..ec830ba 100755 --- a/git-interface/test/t0003-update.sh +++ b/git-interface/test/t0003-update.sh @@ -104,22 +104,34 @@ test_expect_success 'Test restore mode.' ' ' test_expect_success 'Test restore mode on a non-existent repository.' ' + cat >expected <<-EOD && + error: restore: repository not found: foobar3 + EOD AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" restore 2>&1 + test_must_fail "$GIT_UPDATE" restore >actual 2>&1 && + test_cmp expected actual ' test_expect_success 'Pushing to a branch other than master.' ' old=0000000000000000000000000000000000000000 && new=$(git -C aur.git rev-parse HEAD) && + cat >expected <<-EOD && + error: pushing to a branch other than master is restricted + EOD AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/pu "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/pu "$old" "$new" >actual 2>&1 && + test_cmp expected actual ' test_expect_success 'Performing a non-fast-forward ref update.' ' old=$(git -C aur.git rev-parse HEAD) && new=$(git -C aur.git rev-parse HEAD^) && + cat >expected <<-EOD && + error: denying non-fast-forward (you should pull first) + EOD AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual ' test_expect_success 'Performing a non-fast-forward ref update as Trusted User.' ' @@ -136,7 +148,8 @@ test_expect_success 'Removing .SRCINFO.' ' git -C aur.git commit -q -m "Remove .SRCINFO" && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing .SRCINFO$" actual ' test_expect_success 'Removing .SRCINFO with a follow-up fix.' ' @@ -147,7 +160,8 @@ test_expect_success 'Removing .SRCINFO with a follow-up fix.' ' git -C aur.git revert --no-edit HEAD && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing .SRCINFO$" actual ' test_expect_success 'Removing PKGBUILD.' ' @@ -157,7 +171,8 @@ test_expect_success 'Removing PKGBUILD.' ' git -C aur.git commit -q -m "Remove PKGBUILD" && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing PKGBUILD$" actual ' test_expect_success 'Pushing a tree with a subdirectory.' ' @@ -169,7 +184,8 @@ test_expect_success 'Pushing a tree with a subdirectory.' ' git -C aur.git commit -q -m "Add subdirectory" && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: the repository must not contain subdirectories$" actual ' test_expect_success 'Pushing a tree with a large blob.' ' @@ -180,7 +196,8 @@ test_expect_success 'Pushing a tree with a large blob.' ' git -C aur.git commit -q -m "Add large blob" && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: maximum blob size (250.00KiB) exceeded$" actual ' test_expect_success 'Pushing .SRCINFO with a non-matching package base.' ' @@ -194,7 +211,8 @@ test_expect_success 'Pushing .SRCINFO with a non-matching package base.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: invalid pkgbase: foobar2, expected foobar$" actual ' test_expect_success 'Pushing .SRCINFO with invalid syntax.' ' @@ -222,7 +240,8 @@ test_expect_success 'Pushing .SRCINFO without pkgver.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing mandatory field: pkgver$" actual ' test_expect_success 'Pushing .SRCINFO without pkgrel.' ' @@ -236,7 +255,8 @@ test_expect_success 'Pushing .SRCINFO without pkgrel.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing mandatory field: pkgrel$" actual ' test_expect_success 'Pushing .SRCINFO with epoch.' ' @@ -270,7 +290,8 @@ test_expect_success 'Pushing .SRCINFO with invalid pkgname.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: invalid package name: !$" actual ' test_expect_success 'Pushing .SRCINFO with invalid epoch.' ' @@ -284,7 +305,8 @@ test_expect_success 'Pushing .SRCINFO with invalid epoch.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: invalid epoch: !$" actual ' test_expect_success 'Missing install file.' ' @@ -298,7 +320,8 @@ test_expect_success 'Missing install file.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing install file: install$" actual ' test_expect_success 'Missing changelog file.' ' @@ -312,7 +335,8 @@ test_expect_success 'Missing changelog file.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing changelog file: changelog$" actual ' test_expect_success 'Missing source file.' ' @@ -326,7 +350,8 @@ test_expect_success 'Missing source file.' ' ) && new=$(git -C aur.git rev-parse HEAD) && AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing source file: file$" actual ' test_expect_success 'Pushing a blacklisted package.' ' @@ -335,18 +360,26 @@ test_expect_success 'Pushing a blacklisted package.' ' echo "pkgname = forbidden" >>aur.git/.SRCINFO && git -C aur.git commit -q -am "Add blacklisted package" && new=$(git -C aur.git rev-parse HEAD) && + cat >expected <<-EOD && + error: package is blacklisted: forbidden + EOD AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual ' -test_expect_success 'Pushing a blacklisted package as Trusted User.' ' +test_expect_failure 'Pushing a blacklisted package as Trusted User.' ' old=$(git -C aur.git rev-parse HEAD) && test_when_finished "git -C aur.git reset --hard $old" && echo "pkgname = forbidden" >>aur.git/.SRCINFO && git -C aur.git commit -q -am "Add blacklisted package" && new=$(git -C aur.git rev-parse HEAD) && + cat >expected <<-EOD && + warning: package is blacklisted: forbidden + EOD AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 | grep ^warning: + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual ' test_expect_success 'Pushing a package already in the official repositories.' ' @@ -355,18 +388,26 @@ test_expect_success 'Pushing a package already in the official repositories.' ' echo "pkgname = official" >>aur.git/.SRCINFO && git -C aur.git commit -q -am "Add official package" && new=$(git -C aur.git rev-parse HEAD) && + cat >expected <<-EOD && + error: package already provided by [core]: official + EOD AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual ' -test_expect_success 'Pushing a package already in the official repositories as Trusted User.' ' +test_expect_failure 'Pushing a package already in the official repositories as Trusted User.' ' old=$(git -C aur.git rev-parse HEAD) && test_when_finished "git -C aur.git reset --hard $old" && echo "pkgname = official" >>aur.git/.SRCINFO && git -C aur.git commit -q -am "Add official package" && new=$(git -C aur.git rev-parse HEAD) && + cat >expected <<-EOD && + warning: package already provided by [core]: official + EOD AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 | grep ^warning: + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual ' test_expect_success 'Trying to hijack a package.' ' @@ -380,8 +421,12 @@ test_expect_success 'Trying to hijack a package.' ' git commit -q -am "Change package name" ) && new=$(git -C aur.git rev-parse HEAD) && + cat >expected <<-EOD && + error: cannot overwrite package: foobar + EOD AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \ - test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 + test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual ' test_done -- 2.9.3
When using SQLite as backend, we need to close the cursor before closing the database to avoid the following error: sqlite3.OperationalError: unable to close due to unfinalized statements or unfinished backups Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/git-update.py | 1 + git-interface/test/t0003-update.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/git-interface/git-update.py b/git-interface/git-update.py index 40d834d..50938c3 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -402,4 +402,5 @@ repo.create_reference('refs/namespaces/' + pkgbase + '/HEAD', sha1_new, True) update_notify(conn, user, pkgbase_id) # Close the database. +cur.close() conn.close() diff --git a/git-interface/test/t0003-update.sh b/git-interface/test/t0003-update.sh index ec830ba..4a45779 100755 --- a/git-interface/test/t0003-update.sh +++ b/git-interface/test/t0003-update.sh @@ -368,7 +368,7 @@ test_expect_success 'Pushing a blacklisted package.' ' test_cmp expected actual ' -test_expect_failure 'Pushing a blacklisted package as Trusted User.' ' +test_expect_success 'Pushing a blacklisted package as Trusted User.' ' old=$(git -C aur.git rev-parse HEAD) && test_when_finished "git -C aur.git reset --hard $old" && echo "pkgname = forbidden" >>aur.git/.SRCINFO && -- 2.9.3
The repo variable is already used to store the pygit2.Repository. Fixes a regression introduced in d273ee5 (Use the official provider list to detect duplicates, 2016-05-17). Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/git-update.py | 3 +-- git-interface/test/t0003-update.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/git-interface/git-update.py b/git-interface/git-update.py index 50938c3..be4c9be 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -373,8 +373,7 @@ for pkgname in srcinfo.utils.get_package_names(metadata): if pkgname in blacklist: warn_or_die('package is blacklisted: {:s}'.format(pkgname)) if pkgname in providers: - repo = providers[pkgname] - warn_or_die('package already provided by [{:s}]: {:s}'.format(repo, pkgname)) + warn_or_die('package already provided by [{:s}]: {:s}'.format(providers[pkgname], pkgname)) cur = conn.execute("SELECT COUNT(*) FROM Packages WHERE Name = ? AND " + "PackageBaseID <> ?", [pkgname, pkgbase_id]) diff --git a/git-interface/test/t0003-update.sh b/git-interface/test/t0003-update.sh index 4a45779..b642089 100755 --- a/git-interface/test/t0003-update.sh +++ b/git-interface/test/t0003-update.sh @@ -396,7 +396,7 @@ test_expect_success 'Pushing a package already in the official repositories.' ' test_cmp expected actual ' -test_expect_failure 'Pushing a package already in the official repositories as Trusted User.' ' +test_expect_success 'Pushing a package already in the official repositories as Trusted User.' ' old=$(git -C aur.git rev-parse HEAD) && test_when_finished "git -C aur.git reset --hard $old" && echo "pkgname = official" >>aur.git/.SRCINFO && -- 2.9.3
participants (1)
-
Lukas Fleischer