summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan "Duke" Leto <jonathan@leto.net>2011-05-22 21:02:23 -0700
committerJonathan "Duke" Leto <jonathan@leto.net>2011-05-22 21:02:23 -0700
commit84147ee6d4a5d53d93f4a73300a192f854eb1ccd (patch)
tree883782c9efc36d21f1efbc19bb4f593ca9e5a9d8
parentRemove dep on Git::Repository (diff)
parentMake hook test data refer to the new git repo for testing (diff)
downloadjitterbug-84147ee6d4a5d53d93f4a73300a192f854eb1ccd.tar.gz
Merge branch 'master' into git_refactor
Diffstat (limited to '')
-rw-r--r--eg/post_hook.t3
-rw-r--r--lib/jitterbug/Task.pm8
-rw-r--r--scripts/post_to_hook.pl57
-rw-r--r--t/003_hook_route.t4
-rw-r--r--t/005_builder.t4
-rw-r--r--t/data/hook_data.yml (renamed from t/data/test.yaml)2
-rw-r--r--t/data/test.yml4
-rw-r--r--t/data/testing.git/HEAD1
-rw-r--r--t/data/testing.git/config4
-rw-r--r--t/data/testing.git/description1
-rw-r--r--t/data/testing.git/info/exclude6
-rw-r--r--t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idxbin0 -> 5188 bytes
-rw-r--r--t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.packbin0 -> 12344 bytes
-rw-r--r--t/data/testing.git/packed-refs2
-rw-r--r--t/tmp/build/.exists0
-rw-r--r--t/tmp/reports/.exists0
16 files changed, 87 insertions, 9 deletions
diff --git a/eg/post_hook.t b/eg/post_hook.t
index 3715abc..4165f46 100644
--- a/eg/post_hook.t
+++ b/eg/post_hook.t
@@ -5,8 +5,9 @@ use LWP::UserAgent;
use HTTP::Request::Common;
use YAML qw/LoadFile/;
use JSON;
+use File::Spec::Functions;
-my $content = LoadFile('t/data/test.yaml');
+my $content = LoadFile(catfile(qw/t data hook_data.yml/));
my $payload = JSON::encode_json($content);
my $url = "http://localhost:5000/hook/";
diff --git a/lib/jitterbug/Task.pm b/lib/jitterbug/Task.pm
index dd7d1f6..bd949e3 100644
--- a/lib/jitterbug/Task.pm
+++ b/lib/jitterbug/Task.pm
@@ -5,10 +5,14 @@ use Dancer::Plugin::DBIC;
use jitterbug::Plugin::Template;
get '/:id' => sub {
- my $task = schema->resultset('Task')->find( params->{id} );
+ unless ( defined params->{id} ) {
+ send_error("task id missing!", 400);
+ return;
+ }
+ my $task = schema->resultset('Task')->find( params->{id} );
- if ( !defined $task ) {
+ unless ( defined $task ) {
send_error("task does not exist!", 404);
return;
}
diff --git a/scripts/post_to_hook.pl b/scripts/post_to_hook.pl
new file mode 100644
index 0000000..55d3d73
--- /dev/null
+++ b/scripts/post_to_hook.pl
@@ -0,0 +1,57 @@
+use strict;
+use warnings;
+
+use jitterbug;
+use jitterbug::Schema;
+
+use JSON;
+use YAML qw/LoadFile Dump/;
+
+use File::Temp qw/tempdir/;
+
+use Dancer::Test;
+use Dancer::Config qw/setting/;
+use File::Spec::Functions;
+
+my $content = LoadFile(shift || catfile(qw/t data hook_data.yml/));
+
+my $db_file = catfile( qw/t data jitterbug.db/ );
+my $dsn = 'dbi:SQLite:dbname=' . $db_file;
+my $schema = jitterbug::Schema->connect($dsn);
+# assume we have a deployed schema
+# $schema->deploy;
+
+setting plugins => {
+ DBIC => {
+ schema => {
+ skip_automake => 1,
+ pckg => "jitterbug::Schema",
+ connect_info => [$dsn]
+ }
+ }
+};
+
+{
+ my $response = dancer_response(
+ POST => '/hook/',
+ {
+ headers =>
+ [ 'Content-Type' => 'application/x-www-form-urlencoded' ],
+ body => _generate_post_request($content),
+ }
+ );
+
+ printf "Response was: %s\n", $response->{status};
+}
+
+sub _generate_post_request {
+ my $content = shift;
+ my $payload = "payload=" . JSON::encode_json($content);
+ open my $in, '<', \$payload;
+
+ $ENV{'CONTENT_LENGTH'} = length($payload);
+ $ENV{'CONTENT_TYPE'} = 'application/x-www-form-urlencoded';
+ $ENV{'psgi.input'} = $in;
+ return $payload;
+}
+
diff --git a/t/003_hook_route.t b/t/003_hook_route.t
index 0ce6771..0361b15 100644
--- a/t/003_hook_route.t
+++ b/t/003_hook_route.t
@@ -13,8 +13,10 @@ use File::Temp qw/tempdir/;
use Dancer::Test;
use Dancer::Config qw/setting/;
+use File::Spec::Functions;
+my $hook_data = catfile(qw/t data hook_data.yml/);
-my $content = LoadFile('t/data/test.yaml');
+my $content = LoadFile($hook_data);
my $db_dir = tempdir( CLEANUP => 1 );
my $db_file = File::Spec->catfile( $db_dir, 'jitterbug.db' );
diff --git a/t/005_builder.t b/t/005_builder.t
index cc0bb0a..603001a 100644
--- a/t/005_builder.t
+++ b/t/005_builder.t
@@ -77,10 +77,10 @@ jitterbug::Test->init();
},
'builder' => {},
'reports' => {
- 'dir' => '/tmp/jitterbug'
+ 'dir' => './t/tmp/reports'
},
'build' => {
- 'dir' => '/tmp/build'
+ 'dir' => './t/tmp/build',
},
'options' => {
'email_on_pass' => '0',
diff --git a/t/data/test.yaml b/t/data/hook_data.yml
index c8e1a63..da5b78f 100644
--- a/t/data/test.yaml
+++ b/t/data/hook_data.yml
@@ -39,5 +39,5 @@ repository:
name: franckcuny
private: !!perl/scalar:JSON::XS::Boolean 1
pushed_at: 2010/09/23 08:04:49 -0700
- url: https://github.com/sukria/Dancer
+ url: ./t/data/testing.git
watchers: 1
diff --git a/t/data/test.yml b/t/data/test.yml
index d8d21c0..98f8e65 100644
--- a/t/data/test.yml
+++ b/t/data/test.yml
@@ -12,9 +12,9 @@ engines:
jitterbug:
reports:
- dir: /tmp/jitterbug
+ dir: ./t/tmp/reports
build:
- dir: /tmp/build
+ dir: ./t/tmp/build
build_process:
builder: ./scripts/capsule.sh
builder_variables: STUFF=BLAH
diff --git a/t/data/testing.git/HEAD b/t/data/testing.git/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/t/data/testing.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/t/data/testing.git/config b/t/data/testing.git/config
new file mode 100644
index 0000000..07d359d
--- /dev/null
+++ b/t/data/testing.git/config
@@ -0,0 +1,4 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
diff --git a/t/data/testing.git/description b/t/data/testing.git/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/t/data/testing.git/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/t/data/testing.git/info/exclude b/t/data/testing.git/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/t/data/testing.git/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx b/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx
new file mode 100644
index 0000000..f03f9d2
--- /dev/null
+++ b/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx
Binary files differ
diff --git a/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack b/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack
new file mode 100644
index 0000000..6d0725c
--- /dev/null
+++ b/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack
Binary files differ
diff --git a/t/data/testing.git/packed-refs b/t/data/testing.git/packed-refs
new file mode 100644
index 0000000..4a1d788
--- /dev/null
+++ b/t/data/testing.git/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+3ab75b9a29e09bf027f64250b44cab19b316c128 refs/heads/master
diff --git a/t/tmp/build/.exists b/t/tmp/build/.exists
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/t/tmp/build/.exists
diff --git a/t/tmp/reports/.exists b/t/tmp/reports/.exists
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/t/tmp/reports/.exists