[BACK]Return to network_tests.t CVS log [TXT][DIR] Up to [local] / HOPE / Net-OpenAMD / t

Annotation of HOPE/Net-OpenAMD/t/network_tests.t, Revision 1.13

1.1       andrew      1: #!perl
                      2: package NetworkTests;
1.2       andrew      3:
1.13    ! andrew      4: # $AFresh1: network_tests.t,v 1.12 2010/07/13 06:10:31 andrew Exp $
1.1       andrew      5:
                      6: use strict;
                      7: use warnings;
                      8:
                      9: use Test::More;
1.9       andrew     10: use Test::Deep;
1.1       andrew     11: use Net::OpenAMD;
1.11      andrew     12:
                     13: #use Data::Dumper;
1.1       andrew     14:
1.2       andrew     15: if ( !caller() ) {
                     16:     if ( $ENV{'NETWORK_TESTS'} ) {
1.12      andrew     17:         plan tests => 31;
1.1       andrew     18:     }
                     19:     else {
1.6       andrew     20:         plan skip_all =>
                     21:             'Network test.  Set $ENV{NETWORK_TESTS} to a true value to run.';
1.1       andrew     22:     }
                     23:
1.9       andrew     24:     my $amd
                     25:         = Net::OpenAMD->new( { base_uri => 'http://api.hope.net/api/', } );
                     26:     run_tests($amd);
                     27:
                     28:     #done_testing();
                     29: }
                     30:
                     31: 1;
                     32:
                     33: sub run_tests {
                     34:     my ($amd) = @_;
                     35:
                     36:     my @interests = (
                     37:         "new tech",           "activism",
                     38:         "radio",              "lockpicking",
                     39:         "crypto",             "privacy",
                     40:         "ethics",             "telephones",
                     41:         "social engineering", "hacker spaces",
                     42:         "hardware hacking",   "nostalgia",
                     43:         "communities",        "science",
                     44:         "government",         "network security",
                     45:         "malicious software", "pen testing",
                     46:         "web",                "niche hacks",
                     47:         "media"
                     48:     );
                     49:     my %cmp = (
                     50:         single_line   => re('^[^\n]+$'),
1.10      andrew     51:         multi_line    => re('(?xms:^.*$)'),
1.9       andrew     52:         digits        => re('^\d+$'),
                     53:         track         => any( 'Lovelace', 'Tesla', 'Bell', 'Hooper' ),
                     54:         area          => any('Engressia'),
                     55:         interests     => any(@interests),
                     56:         all_interests => bag(@interests),
                     57:         coordinate    => re('^\d\d\.\d+$'),
                     58:         boolean => any( 'True', 'False' ),
                     59:     );
                     60:
1.11      andrew     61:     $cmp{user} = [
                     62:         $cmp{single_line},
1.13    ! andrew     63:         superhashof(
        !            64:             {   name => $cmp{single_line},
1.11      andrew     65:
1.13    ! andrew     66:                 #interests => array_each( $cmp{interests} ),
        !            67:                 #x         => $cmp{coordinate},
        !            68:                 #y         => $cmp{coordinate},
        !            69:             }
        !            70:         ),
1.11      andrew     71:     ];
                     72:
                     73:     $cmp{speaker} = [
                     74:         $cmp{single_line},
                     75:         {   name => $cmp{single_line},
                     76:             bio  => $cmp{multi_line},
                     77:         }
                     78:     ];
1.9       andrew     79:
1.13    ! andrew     80:     $cmp{location} = superhashof(
        !            81:         {   area => $cmp{area},
        !            82:             user => $cmp{digits},
        !            83:
        !            84:             #button => $cmp{boolean},
        !            85:             x => $cmp{coordinate},
        !            86:             y => $cmp{coordinate},
        !            87:
        !            88:             #time   => $cmp{single_line},
        !            89:         }
        !            90:     );
        !            91:
1.2       andrew     92:     my %tests = (
                     93:         location => [
                     94:             {   args   => undef,
1.13    ! andrew     95:                 expect => array_each( $cmp{location} ),
1.2       andrew     96:             },
1.10      andrew     97:             {   args   => { user => 'user0' },
                     98:                 expect => array_each(),
1.8       andrew     99:             },
1.13    ! andrew    100:             {   args   => { user => 'user0', limit => 5 },
1.11      andrew    101:                 expect => array_each(),
                    102:             },
                    103:             {   args   => { area => 'Engressa' },
                    104:                 expect => array_each(),
                    105:             },
1.2       andrew    106:         ],
                    107:         speakers => [
                    108:             {   args   => undef,
1.11      andrew    109:                 expect => array_each( $cmp{speaker} ),
                    110:             },
                    111:             {   args => { name => 'The Cheshire Catalyst' },
                    112:                 expect => array_each( $cmp{speaker} ),
1.2       andrew    113:             },
                    114:         ],
                    115:         talks => [
                    116:             {   args   => undef,
1.9       andrew    117:                 expect => array_each(
1.10      andrew    118:                     {   abstract => $cmp{multi_line},
                    119:                         speakers => array_each( $cmp{single_line} ),
                    120:                         time     => $cmp{single_line},
                    121:                         title    => $cmp{single_line},
                    122:                         track    => $cmp{track},
1.9       andrew    123:                     }
                    124:                 ),
1.2       andrew    125:             },
1.11      andrew    126:             {   args   => { interests => 'lockpicking' },
                    127:                 expect => array_each(
                    128:                     {   abstract => $cmp{multi_line},
                    129:                         speakers => array_each( $cmp{single_line} ),
                    130:                         time     => $cmp{single_line},
                    131:                         title    => $cmp{single_line},
                    132:                         track    => $cmp{track},
                    133:
                    134:                         # interests => 'lockpicking',
                    135:                     }
                    136:                 ),
                    137:             },
1.2       andrew    138:         ],
                    139:         interests => [
                    140:             {   args   => undef,
1.9       andrew    141:                 expect => $cmp{all_interests},
1.2       andrew    142:             },
                    143:         ],
                    144:         users => [
                    145:             {   args   => undef,
1.11      andrew    146:                 expect => array_each( $cmp{user} ),
                    147:             },
                    148:             {   args   => { user => 'user0' },
                    149:                 expect => array_each( $cmp{user} ),
                    150:             },
                    151:             {   args   => { user => 'user0', limit => 20 },
                    152:                 expect => array_each( $cmp{user} ),
                    153:             },
                    154:             {   args   => { interests => 'lockpicking' },
                    155:                 expect => array_each( $cmp{user} ),
1.2       andrew    156:             },
                    157:         ],
                    158:         stats => [
                    159:             {   args   => undef,
1.4       andrew    160:                 expect => qr/^Unused \s feature/xms,
1.2       andrew    161:             },
                    162:         ],
                    163:     );
                    164:
1.9       andrew    165:     foreach my $method ( keys %tests ) {
                    166:         foreach my $test ( @{ $tests{$method} } ) {
1.2       andrew    167:             no warnings 'uninitialized';
                    168:             my $result;
                    169:             eval { $result = $amd->$method( $test->{args} ) };
1.4       andrew    170:             if ( ref $test->{expect} eq 'Regexp' ) {
                    171:                 like( $@, $test->{expect}, "AMD->$method($test->{args})" );
                    172:             }
                    173:             elsif ( ref $test->{expect} ) {
                    174:                 is( $@, '', "AMD->$method($test->{args})" );
1.9       andrew    175:                 cmp_deeply( $result, $test->{expect},
1.6       andrew    176:                           "AMD->$method($test->{args}) - "
                    177:                         . 'got expected result' );
1.4       andrew    178:             }
                    179:             else {
                    180:                 is( $@, $test->{expect}, "AMD->$method($test->{args})" );
                    181:             }
1.2       andrew    182:         }
                    183:     }
1.1       andrew    184: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>