summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-10-17 21:46:03 +0200
committerfranck cuny <franck@lumberjaph.net>2010-10-17 21:46:03 +0200
commit1c3ba5b29669ff002ff9650535ec019f4022e1e1 (patch)
tree6e9402fcf6c1db8440b1bf77469b0589f46a80dc /t
parentremove couchdb api; add dummy spec for tests (diff)
downloadnet-http-spore-1c3ba5b29669ff002ff9650535ec019f4022e1e1.tar.gz
update tests to use the dummy api, and replace api_base_url with base_url
Diffstat (limited to 't')
-rw-r--r--t/spore-middleware/auth-basic.t6
-rw-r--r--t/spore-middleware/format-auto.t2
-rw-r--r--t/spore-middleware/format-json.t8
-rw-r--r--t/spore-middleware/format-xml.t8
-rw-r--r--t/spore-middleware/format-yaml.t8
-rw-r--r--t/spore-middleware/runtime.t8
-rw-r--r--t/spore-middleware/useragent.t8
-rw-r--r--t/spore-request/exception.t8
-rw-r--r--t/spore/01_new_from_string.t26
-rw-r--r--t/spore/02_enable.t8
10 files changed, 46 insertions, 44 deletions
diff --git a/t/spore-middleware/auth-basic.t b/t/spore-middleware/auth-basic.t
index e0e1f05..a6c5ac7 100644
--- a/t/spore-middleware/auth-basic.t
+++ b/t/spore-middleware/auth-basic.t
@@ -10,7 +10,7 @@ my $username = 'franck';
my $password = 's3kr3t';
my $mock_server = {
- '/test_spore/_all_docs' => sub {
+ '/show' => sub {
my $req = shift;
my $auth = $req->header('Authorization');
if ($auth) {
@@ -41,14 +41,14 @@ plan tests => 3 * @tests;
foreach my $test (@tests) {
ok my $client = Net::HTTP::Spore->new_from_spec(
- 't/specs/couchdb.json', api_base_url => 'http://localhost:5984'
+ 't/specs/api.json', base_url => 'http://localhost/'
),
'client created';
foreach ( @{ $test->{middlewares} } ) {
$client->enable(@$_);
}
- my $res = $client->get_all_documents( database => 'test_spore' );
+ my $res = $client->get_info();
is $res->[0], $test->{expected}->{status}, 'valid HTTP status';
is $res->[2], $test->{expected}->{body}, 'valid HTTP body';
}
diff --git a/t/spore-middleware/format-auto.t b/t/spore-middleware/format-auto.t
index e90e16b..857d65d 100644
--- a/t/spore-middleware/format-auto.t
+++ b/t/spore-middleware/format-auto.t
@@ -22,7 +22,7 @@ my $mock_server = {
};
my $api = {
- api_base_url => 'http://services.org/api',
+ base_url => 'http://services.org/api',
methods => {
'show' => {
path => '/show',
diff --git a/t/spore-middleware/format-json.t b/t/spore-middleware/format-json.t
index 61a557f..95d84c3 100644
--- a/t/spore-middleware/format-json.t
+++ b/t/spore-middleware/format-json.t
@@ -9,7 +9,7 @@ use Net::HTTP::Spore;
my $content = { keys => [qw/1 2 3/] };
my $mock_server = {
- '/test_spore/_all_docs' => sub {
+ '/show' => sub {
my $req = shift;
$req->new_response(
200,
@@ -20,13 +20,13 @@ my $mock_server = {
};
ok my $client =
- Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json',
- api_base_url => 'http://localhost:5984' );
+ Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
+ base_url => 'http://localhost:5984' );
$client->enable('Format::JSON');
$client->enable('Mock', tests => $mock_server);
-my $res = $client->get_all_documents( database => 'test_spore' );
+my $res = $client->get_info();
is $res->[0], 200;
is_deeply $res->[2], $content;
is $res->header('Content-Type'), 'application/json';
diff --git a/t/spore-middleware/format-xml.t b/t/spore-middleware/format-xml.t
index 623e281..492f564 100644
--- a/t/spore-middleware/format-xml.t
+++ b/t/spore-middleware/format-xml.t
@@ -9,7 +9,7 @@ use Net::HTTP::Spore;
my $content = { keys => [qw/1 2 3/] };
my $mock_server = {
- '/test_spore/_all_docs' => sub {
+ '/show' => sub {
my $req = shift;
$req->new_response( 200, [ 'Content-Type' => 'text/xml' ],
XMLout($content) );
@@ -17,13 +17,13 @@ my $mock_server = {
};
ok my $client =
- Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json',
- api_base_url => 'http://localhost:5984' );
+ Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
+ base_url => 'http://localhost:5984' );
$client->enable('Format::XML');
$client->enable( 'Mock', tests => $mock_server );
-my $res = $client->get_all_documents( database => 'test_spore' );
+my $res = $client->get_info();
is $res->[0], 200;
is_deeply $res->[2], $content;
is $res->header('Content-Type'), 'text/xml';
diff --git a/t/spore-middleware/format-yaml.t b/t/spore-middleware/format-yaml.t
index db9629d..58c743e 100644
--- a/t/spore-middleware/format-yaml.t
+++ b/t/spore-middleware/format-yaml.t
@@ -9,7 +9,7 @@ use Net::HTTP::Spore;
my $content = { keys => [qw/1 2 3/] };
my $mock_server = {
- '/test_spore/_all_docs' => sub {
+ '/show' => sub {
my $req = shift;
$req->new_response( 200, [ 'Content-Type' => 'text/x-yaml' ],
Dump($content) );
@@ -17,13 +17,13 @@ my $mock_server = {
};
ok my $client =
- Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json',
- api_base_url => 'http://localhost:5984' );
+ Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
+ base_url => 'http://localhost:5984' );
$client->enable('Format::YAML');
$client->enable( 'Mock', tests => $mock_server );
-my $res = $client->get_all_documents( database => 'test_spore' );
+my $res = $client->get_info();
is $res->[0], 200;
is_deeply $res->[2], $content;
is $res->header('Content-Type'), 'text/x-yaml';
diff --git a/t/spore-middleware/runtime.t b/t/spore-middleware/runtime.t
index e7509d6..07b2a63 100644
--- a/t/spore-middleware/runtime.t
+++ b/t/spore-middleware/runtime.t
@@ -5,20 +5,20 @@ use Test::More;
use Net::HTTP::Spore;
my $mock_server = {
- '/test_spore/_all_docs' => sub {
+ '/show' => sub {
my $req = shift;
$req->new_response( 200, [ 'Content-Type' => 'text/plan' ], 'ok');
},
};
ok my $client =
- Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json',
- api_base_url => 'http://localhost:5984' );
+ Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
+ base_url => 'http://localhost:5984' );
$client->enable('Runtime');
$client->enable('Mock', tests => $mock_server);
-my $res = $client->get_all_documents(database => 'test_spore');
+my $res = $client->get_info();
ok $res->header('X-Spore-Runtime');
done_testing;
diff --git a/t/spore-middleware/useragent.t b/t/spore-middleware/useragent.t
index 92af94b..190a66e 100644
--- a/t/spore-middleware/useragent.t
+++ b/t/spore-middleware/useragent.t
@@ -5,22 +5,22 @@ use Test::More;
use Net::HTTP::Spore;
my $mock_server = {
- '/test_spore/_all_docs' => sub {
+ '/show' => sub {
my $req = shift;
$req->new_response( 200, [ 'Content-Type' => 'text/plain' ], 'ok');
},
};
ok my $client =
- Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json',
- api_base_url => 'http://localhost:5984' );
+ Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
+ base_url => 'http://localhost:5984' );
my $ua_str = 'Test::Spore middleware';
$client->enable('UserAgent', useragent => $ua_str);
$client->enable('Mock', tests => $mock_server);
-my $res = $client->get_all_documents(database => 'test_spore');
+my $res = $client->get_info();
is $res->request->header('User-Agent'), $ua_str;
done_testing;
diff --git a/t/spore-request/exception.t b/t/spore-request/exception.t
index 5d5af38..fdf51cb 100644
--- a/t/spore-request/exception.t
+++ b/t/spore-request/exception.t
@@ -5,19 +5,19 @@ use Test::More;
use Net::HTTP::Spore;
my $mock_server = {
- '/test_spore/_all_docs' => sub {
+ '/show' => sub {
my $req = shift;
die;
},
};
ok my $client =
- Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json',
- api_base_url => 'http://localhost:5984' );
+ Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
+ base_url => 'http://localhost' );
$client->enable( 'Mock', tests => $mock_server );
-my $res = $client->get_all_documents(database => 'test_spore');
+my $res = $client->get_info();
is $res->[0], 599;
like $res->[2]->{error}, qr/Died/;
diff --git a/t/spore/01_new_from_string.t b/t/spore/01_new_from_string.t
index 34bfedf..e9d9357 100644
--- a/t/spore/01_new_from_string.t
+++ b/t/spore/01_new_from_string.t
@@ -8,9 +8,13 @@ plan tests => 14;
use IO::All;
use Net::HTTP::Spore;
-my $couchdb_spec = 't/specs/couchdb.json';
-my %args = ( api_base_url => 'http://localhost:5984', );
-my $content < io($couchdb_spec);
+my $api_spec = 't/specs/api.json';
+my %args = ( base_url => 'http://localhost/', );
+
+my $github_spec =
+ "http://github.com/franckcuny/spore/raw/master/services/github.json";
+
+my $content < io($api_spec);
dies_ok { Net::HTTP::Spore->new_from_spec };
like $@, qr/specification file is missing/;
@@ -18,33 +22,31 @@ like $@, qr/specification file is missing/;
dies_ok { Net::HTTP::Spore->new_from_spec( "/foo/bar/baz", ) };
like $@, qr/does not exists/;
-dies_ok { Net::HTTP::Spore->new_from_spec( $couchdb_spec, ) };
-like $@, qr/api_base_url is missing/;
+dies_ok { Net::HTTP::Spore->new_from_spec( $api_spec, ) };
+like $@, qr/base_url is missing/;
-ok my $client = Net::HTTP::Spore->new_from_spec( $couchdb_spec, %args );
+ok my $client = Net::HTTP::Spore->new_from_spec( $api_spec, %args );
ok $client = Net::HTTP::Spore->new_from_string( $content, %args );
SKIP: {
skip "require RUN_HTTP_TEST", 1 unless $ENV{RUN_HTTP_TEST};
- ok $client = Net::HTTP::Spore->new_from_spec(
- 'http://github.com/franckcuny/spore/raw/master/services/github.json',
- %args );
+ ok $client = Net::HTTP::Spore->new_from_spec( $github_spec, %args );
}
dies_ok {
Net::HTTP::Spore->new_from_string(
-'{"api_base_url" : "http://services.org/restapi/","methods" : { "get_info" : { "method" : "GET" } } }'
+'{"base_url" : "http://services.org/restapi/","methods" : { "get_info" : { "method" : "GET" } } }'
);
};
like $@, qr/Attribute \(path\) is required/;
dies_ok {
Net::HTTP::Spore->new_from_string(
-'{"api_base_url" : "http://services.org/restapi/","methods" : { "get_info" : { "method" : "PET", "path":"/info" } } }'
+'{"base_url" : "http://services.org/restapi/","methods" : { "get_info" : { "method" : "PET", "path":"/info" } } }'
);
};
like $@, qr/Attribute \(method\) does not pass the type constraint/;
ok $client = Net::HTTP::Spore->new_from_string(
-'{"api_base_url" : "http://services.org/restapi/","methods" : { "get_info" : { "path" : "/show", "method" : "GET" } } }'
+'{"base_url" : "http://services.org/restapi/","methods" : { "get_info" : { "path" : "/show", "method" : "GET" } } }'
);
diff --git a/t/spore/02_enable.t b/t/spore/02_enable.t
index 3f25606..2bd7402 100644
--- a/t/spore/02_enable.t
+++ b/t/spore/02_enable.t
@@ -16,11 +16,11 @@ sub call { 1 }
package main;
-my $couchdb_spec = 't/specs/couchdb.json';
-my %args = ( api_base_url => 'http://localhost:5984', );
-my $content < io($couchdb_spec);
+my $api_spec = 't/specs/api.json';
+my %args = ( base_url => 'http://localhost/', );
+my $content < io($api_spec);
-ok my $client = Net::HTTP::Spore->new_from_spec( $couchdb_spec, %args );
+ok my $client = Net::HTTP::Spore->new_from_spec( $api_spec, %args );
is scalar @{$client->middlewares}, 0, 'no middleware';