Skip to content

Commit

Permalink
Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySkinner committed Oct 19, 2010
1 parent ef11c6d commit e655dbb
Show file tree
Hide file tree
Showing 26 changed files with 515 additions and 16 deletions.
10 changes: 4 additions & 6 deletions GitAspx.Tests/InfoRefsControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,26 @@ public void Setup() {

[Test]
public void Gets_upload_pack_advertisement() {
controller.Execute("test", "git-upload-pack");
controller.Response.StatusCode.ShouldEqual(200);
controller.Execute("test.git", "git-upload-pack");
controller.Response.ContentType.ShouldContain("application/x-git-upload-pack-advertisement");

var body = controller.Response.OutputStream.GetString();

body.SplitOnNewLine()[0].ShouldEqual("001E# service=git-upload-pack");
body.SplitOnNewLine()[0].ShouldEqual("001e# service=git-upload-pack");
body.ShouldContain("0000009514bf0836c3371b740ebad55fbda6223bd7940f20 HEAD");
body.ShouldContain("multi_ack_detailed");

}

[Test]
public void Gets_receive_pack_advertisement() {
controller.Execute("test", "git-receive-pack");
controller.Response.StatusCode.ShouldEqual(200);
controller.Execute("test.git", "git-receive-pack");

controller.Response.ContentType
.ShouldContain("application/x-git-receive-pack-advertisement");

var body = controller.Response.OutputStream.GetString();
body.SplitOnNewLine()[0].ShouldEqual("001F# service=git-receive-pack");
body.SplitOnNewLine()[0].ShouldEqual("001f# service=git-receive-pack");
body.ShouldContain("0000007314bf0836c3371b740ebad55fbda6223bd7940f20 refs/heads/master");
body.ShouldContain("report-status");
body.ShouldContain("delete-refs");
Expand Down
30 changes: 23 additions & 7 deletions GitAspx.Tests/MainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ namespace GitAspx.Tests {
public class MainTests : BaseTest {
[Test]
public void Gets_upload_pack_advertisement() {
var response = Get("/test/info/refs?service=git-upload-pack");
var response = Get("/test.git/info/refs?service=git-upload-pack");
response.StatusCode.ShouldEqual(HttpStatusCode.OK);
response.Headers["Content-Type"].ShouldContain("application/x-git-upload-pack-advertisement");

var body = response.GetString();

body.SplitOnNewLine()[0].ShouldEqual("001E# service=git-upload-pack");
body.SplitOnNewLine()[0].ShouldEqual("001e# service=git-upload-pack");
body.ShouldContain("0000009514bf0836c3371b740ebad55fbda6223bd7940f20 HEAD");
body.ShouldContain("multi_ack_detailed");
}

[Test]
public void Gets_receive_pack_advertisement() {
var response = Get("/test/info/refs?service=git-receive-pack");
var response = Get("/test.git/info/refs?service=git-receive-pack");
response.StatusCode.ShouldEqual(HttpStatusCode.OK);
response.Headers["Content-Type"].ShouldContain("application/x-git-receive-pack-advertisement");

var body = response.GetString();
body.SplitOnNewLine()[0].ShouldEqual("001F# service=git-receive-pack");
body.SplitOnNewLine()[0].ShouldEqual("001f# service=git-receive-pack");
body.ShouldContain("0000007314bf0836c3371b740ebad55fbda6223bd7940f20 refs/heads/master");
body.ShouldContain("report-status");
body.ShouldContain("delete-refs");
Expand All @@ -55,19 +55,19 @@ public void Gets_receive_pack_advertisement() {

[Test]
public void NoAccess_to_UploadPack_when_incorrect_content_type() {
var response = Post("test/git-upload-pack");
var response = Post("test.git/git-upload-pack");
response.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
}

[Test]
public void NoAccess_to_ReceivePack_when_incorrect_content_type() {
var response = Post("test/git-receive-pack");
var response = Post("test.git/git-receive-pack");
response.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
}

[Test]
public void Not_found_when_wrong_http_method() {
var response = Get("test/git-receive-pack");
var response = Get("test.git/git-receive-pack");
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
}

Expand All @@ -76,5 +76,21 @@ public void Not_found_when_wrong_path() {
var response = Post("no-such-project/git-receive-pack", contentType: "application/x-git-receive-pack-request");
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
}

[Test]
public void Provides_dumb_refs_when_using_dumb_protocol() {
var response = Get("/test.git/info/refs");
response.StatusCode.ShouldEqual(HttpStatusCode.OK);
response.Headers["Content-Type"].ShouldContain("text/plain");

var body = response.GetString();
body.SplitOnNewLine()[0].ShouldEqual("14bf0836c3371b740ebad55fbda6223bd7940f20 refs/heads/master");
}

[Test]
public void Not_found_when_dumb_incorrect_project() {
var response = Get("/no-such-project/info/refs");
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
}
}
}
1 change: 0 additions & 1 deletion GitAspx.Tests/Repositories/test
Submodule test deleted from 14bf08
1 change: 1 addition & 0 deletions GitAspx.Tests/Repositories/test.git/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
7 changes: 7 additions & 0 deletions GitAspx.Tests/Repositories/test.git/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
1 change: 1 addition & 0 deletions GitAspx.Tests/Repositories/test.git/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
15 changes: 15 additions & 0 deletions GitAspx.Tests/Repositories/test.git/hooks/applypatch-msg.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# An example hook script to check the commit log message taken by
# applypatch from an e-mail message.
#
# The hook should exit with non-zero status after issuing an
# appropriate message if it wants to stop the commit. The hook is
# allowed to edit the commit message file.
#
# To enable this hook, rename this file to "applypatch-msg".

. git-sh-setup
test -x "$GIT_DIR/hooks/commit-msg" &&
exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
:
24 changes: 24 additions & 0 deletions GitAspx.Tests/Repositories/test.git/hooks/commit-msg.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
#
# An example hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
#
# To enable this hook, rename this file to "commit-msg".

# Uncomment the below to add a Signed-off-by line to the message.
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
# hook is more suited to it.
#
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

# This example catches duplicate Signed-off-by lines.

test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
echo >&2 Duplicate Signed-off-by lines.
exit 1
}
8 changes: 8 additions & 0 deletions GitAspx.Tests/Repositories/test.git/hooks/post-commit.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
#
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, rename this file to "post-commit".

: Nothing
15 changes: 15 additions & 0 deletions GitAspx.Tests/Repositories/test.git/hooks/post-receive.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# An example hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".

#. /usr/share/doc/git-core/contrib/hooks/post-receive-email
8 changes: 8 additions & 0 deletions GitAspx.Tests/Repositories/test.git/hooks/post-update.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".

exec git update-server-info
14 changes: 14 additions & 0 deletions GitAspx.Tests/Repositories/test.git/hooks/pre-applypatch.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed
# by applypatch from an e-mail message.
#
# The hook should exit with non-zero status after issuing an
# appropriate message if it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-applypatch".

. git-sh-setup
test -x "$GIT_DIR/hooks/pre-commit" &&
exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
:
46 changes: 46 additions & 0 deletions GitAspx.Tests/Repositories/test.git/hooks/pre-commit.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# If you want to allow non-ascii filenames set this variable to true.
allownonascii=$(git config hooks.allownonascii)

# Cross platform projects tend to avoid non-ascii filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test "$(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0')"
then
echo "Error: Attempt to add a non-ascii file name."
echo
echo "This can cause problems if you want to work"
echo "with people on other platforms."
echo
echo "To be portable it is advisable to rename the file ..."
echo
echo "If you know what you are doing you can disable this"
echo "check using:"
echo
echo " git config hooks.allownonascii true"
echo
exit 1
fi

exec git diff-index --check --cached $against --
Loading

0 comments on commit e655dbb

Please sign in to comment.