summary refs log tree commit diff
path: root/t/spore/01_new_from_string.t
blob: e9d93570fc77a20e9b09311746498f5d8c23ec10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use strict;
use warnings;
use Test::More;
use Test::Exception;

plan tests => 14;

use IO::All;
use Net::HTTP::Spore;

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/;

dies_ok { Net::HTTP::Spore->new_from_spec( "/foo/bar/baz", ) };
like $@, qr/does not exists/;

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( $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( $github_spec, %args );
}

dies_ok {
    Net::HTTP::Spore->new_from_string(
'{"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(
'{"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(
'{"base_url" : "http://services.org/restapi/","methods" : { "get_info" : { "path" : "/show", "method" : "GET" } } }'
);