diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2018-11-27 12:36:56 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2018-11-27 12:36:56 +0100 |
commit | 248ea9bbb80111e4c8c1a70419bc963355853167 (patch) | |
tree | 03299b8ed7a3dd2838c1da3d79a115d8734967c5 /test | |
parent | f0cc28e3758524d74d20a8219b13966d01085fea (diff) | |
download | git-repo-248ea9bbb80111e4c8c1a70419bc963355853167.tar.gz git-repo-248ea9bbb80111e4c8c1a70419bc963355853167.zip |
add tests and fix errors found by tests
Diffstat (limited to 'test')
-rwxr-xr-x | test/run.sh | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/test/run.sh b/test/run.sh new file mode 100755 index 0000000..430041c --- /dev/null +++ b/test/run.sh @@ -0,0 +1,272 @@ +#!/bin/bash +# depends on: bwrap, expect + +cd $(dirname "$0") +set -x + +fail() { + set +x + echo >&2 + echo "Test : $testname failed" >&2 + echo "Reason: $@" >&2 + echo >&2 + exit 2 +} + +clean() { + if [ -d "bin" ]; then + rm -r bin + fi + if [ -d "work" ]; then + rm -r work + fi + mkdir bin work + cp ../git-repo bin +} + +run() { + bwrap \ + --ro-bind /bin /bin \ + --ro-bind /usr /usr \ + --ro-bind /etc /etc \ + --ro-bind /lib /lib \ + --ro-bind /lib64 /lib64 \ + --ro-bind /run /run \ + --dev /dev \ + --proc /proc \ + --ro-bind bin /usr/local/bin \ + --bind work /git \ + $1 +} + +filemode() { + stat --format=%a "$@" +} + +######################## +testname=help +clean + +{ + cat <<EOF +spawn git repo help +expect "Subcommands of git repo are" +wait +EOF +} | run expect -f - || fail "Expect script failed" + +echo "done" +######################## +testname=create-public +clean + +{ + cat <<EOF +spawn git repo create-public + +expect "New repository name.git" +send "test-repo.git\n" + +expect "Description" +send "Test description\n" + +expect "Create test-repo.git in" +send "y\n" +wait +EOF +} | run expect -f - || fail "Expect script failed" + +test -d work/$USER/test-repo.git || + fail "repo creation failed" +grep "Test description" work/$USER/test-repo.git/description || + fail "Setting description failed" +test $(filemode work/$USER/test-repo.git) == 2775 || + fail "Repodir created with wrong filemode" +test $(filemode work/$USER/test-repo.git/description) == 664 || + fail "Repodir created with wrong filemode" +test -f work/$USER/test-repo.git/PUBLIC || + fail "Test for PUBLIC file" + +######################## +testname=create-shared +clean + +{ + cat <<EOF +spawn git repo create-shared + +expect "New repository name.git" +send "test-repo.git\n" + +expect "Description" +send "Test description\n" + +expect "Create test-repo.git in" +send "y\n" +wait +EOF +} | run expect -f - || fail "Expect script failed" + +test -d work/$USER/test-repo.git || + fail "repo creation failed" +grep "Test description" work/$USER/test-repo.git/description || + fail "Setting description failed" +test $(filemode work/$USER/test-repo.git) == 2770 || + fail "Repodir created with wrong filemode" +test $(filemode work/$USER/test-repo.git/description) == 660 || + fail "Repodir created with wrong filemode" +test \! -f work/$USER/test-repo.git/PUBLIC || + fail "Test for PUBLIC file" + +######################## +testname=create-private +clean + +{ + cat <<EOF +spawn git repo create-private + +expect "New repository name.git" +send "test-repo.git\n" + +expect "Description" +send "Test description\n" + +expect "Create test-repo.git in" +send "y\n" +wait +EOF +} | run expect -f - || fail "Expect script failed" + +test -d work/$USER/test-repo.git || + fail "repo creation failed" +grep "Test description" work/$USER/test-repo.git/description || + fail "Setting description failed" +test $(filemode work/$USER/test-repo.git) == 2700 || + fail "Repodir created with wrong filemode" +test $(filemode work/$USER/test-repo.git/description) == 600 || + fail "Repodir created with wrong filemode" +test \! -f work/$USER/test-repo.git/PUBLIC || + fail "Test for PUBLIC file" + +######################## +testname=list +clean + +{ + cat <<EOF +spawn git repo create-private +expect "New repository name.git" +send "test-repo1.git\n" +expect "Description" +send "Test description\n" +expect "Create" +send "y\n" +wait + +spawn git repo create-private +expect "New repository name.git" +send "test-repo2.git\n" +expect "Description" +send "Test description\n" +expect "Create" +send "y\n" +wait + +spawn git repo list +expect -re "test-repo1\.git.*owner=$USER.*Test description" +expect -re "test-repo2" +EOF +} | run expect -f - || fail "Expect script failed" + + +######################## +testname=public-make-private +clean + +{ + cat <<EOF +spawn git repo create-public +expect "New repository name.git*" +send "test-repo.git\n" +expect "Description" +send "Test description\n" +expect "Create test-repo.git " +send "y\n" +expect eof +wait + +spawn git repo make-private /git/$USER/test-repo.git +expect "test-repo.git*(owner=$USER)" +expect eof +wait +EOF +} | run expect -f - || fail "Expect script failed" + +test $(filemode work/$USER/test-repo.git) == 2700 || + fail "Repodir created with wrong filemode" +test $(filemode work/$USER/test-repo.git/description) == 600 || + fail "Repodir created with wrong filemode" +test \! -f work/$USER/test-repo.git/PUBLIC || + fail "Test for PUBLIC file" + + +######################## +testname=private-make-public +clean + +{ + cat <<EOF +spawn git repo create-private +expect "New repository name.git*" +send "test-repo.git\n" +expect "Description" +send "Test description\n" +expect "Create test-repo.git " +send "y\n" +expect eof +wait + +spawn git repo make-public /git/$USER/test-repo.git +expect "test-repo.git*(owner=$USER group=* PUBLIC)" +expect eof +wait +EOF +} | run expect -f - || fail "Expect script failed" + +test $(filemode work/$USER/test-repo.git) == 2775 || + fail "Repodir created with wrong filemode" +test $(filemode work/$USER/test-repo.git/description) == 664 || + fail "Repodir created with wrong filemode" +test -f work/$USER/test-repo.git/PUBLIC || + fail "Test for PUBLIC file" + + +######################## +testname=show-public +clean + +{ + cat <<EOF +spawn git repo create-public +expect "New repository name.git*" +send "test-repo.git\n" +expect "Description" +send "Test description\n" +expect "Create test-repo.git " +send "y\n" +expect eof +wait + +spawn git repo show /git/$USER/test-repo.git +#expect "/git/$USER/test-repo.git" +expect "Permissions mode 2775" +expect "sharedrepository=0664" +expect "SSH" +expect "HTTP" +expect "set-url origin" +expect "update description" +expect eof +wait +EOF +} | run expect -f - || fail "Expect script failed" |