[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.11

1.1       andrew      1: #!perl
                      2: package NetworkTests;
1.2       andrew      3:
1.11    ! andrew      4: # $AFresh1: network_tests.t,v 1.10 2010/07/13 03:23:48 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.8       andrew     17:         plan tests => 13;
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},
        !            63:         {   name => $cmp{single_line},
        !            64:
        !            65:             #interests => array_each( $cmp{interests} ),
        !            66:             #x         => $cmp{coordinate},
        !            67:             #y         => $cmp{coordinate},
        !            68:         }
        !            69:     ];
        !            70:
        !            71:     $cmp{speaker} = [
        !            72:         $cmp{single_line},
        !            73:         {   name => $cmp{single_line},
        !            74:             bio  => $cmp{multi_line},
        !            75:         }
        !            76:     ];
1.9       andrew     77:
1.2       andrew     78:     my %tests = (
                     79:         location => [
                     80:             {   args   => undef,
1.9       andrew     81:                 expect => array_each(
                     82:                     {   area   => $cmp{area},
                     83:                         user   => $cmp{digits},
                     84:                         button => $cmp{boolean},
                     85:                         x      => $cmp{coordinate},
                     86:                         y      => $cmp{coordinate},
                     87:                         time   => $cmp{single_line},
1.4       andrew     88:                     }
1.9       andrew     89:                 ),
1.2       andrew     90:             },
1.10      andrew     91:             {   args   => { user => 'user0' },
                     92:                 expect => array_each(),
1.8       andrew     93:             },
1.11    ! andrew     94:             {   args   => { user => 'user0', limit => 20 },
        !            95:                 expect => array_each(),
        !            96:             },
        !            97:             {   args   => { area => 'Engressa' },
        !            98:                 expect => array_each(),
        !            99:             },
1.2       andrew    100:         ],
                    101:         speakers => [
                    102:             {   args   => undef,
1.11    ! andrew    103:                 expect => array_each( $cmp{speaker} ),
        !           104:             },
        !           105:             {   args => { name => 'The Cheshire Catalyst' },
        !           106:                 expect => array_each( $cmp{speaker} ),
1.2       andrew    107:             },
                    108:         ],
                    109:         talks => [
                    110:             {   args   => undef,
1.9       andrew    111:                 expect => array_each(
1.10      andrew    112:                     {   abstract => $cmp{multi_line},
                    113:                         speakers => array_each( $cmp{single_line} ),
                    114:                         time     => $cmp{single_line},
                    115:                         title    => $cmp{single_line},
                    116:                         track    => $cmp{track},
1.9       andrew    117:                     }
                    118:                 ),
1.2       andrew    119:             },
1.11    ! andrew    120:             {   args   => { interests => 'lockpicking' },
        !           121:                 expect => array_each(
        !           122:                     {   abstract => $cmp{multi_line},
        !           123:                         speakers => array_each( $cmp{single_line} ),
        !           124:                         time     => $cmp{single_line},
        !           125:                         title    => $cmp{single_line},
        !           126:                         track    => $cmp{track},
        !           127:
        !           128:                         # interests => 'lockpicking',
        !           129:                     }
        !           130:                 ),
        !           131:             },
1.2       andrew    132:         ],
                    133:         interests => [
                    134:             {   args   => undef,
1.9       andrew    135:                 expect => $cmp{all_interests},
1.2       andrew    136:             },
                    137:         ],
                    138:         users => [
                    139:             {   args   => undef,
1.11    ! andrew    140:                 expect => array_each( $cmp{user} ),
        !           141:             },
        !           142:             {   args   => { user => 'user0' },
        !           143:                 expect => array_each( $cmp{user} ),
        !           144:             },
        !           145:             {   args   => { user => 'user0', limit => 20 },
        !           146:                 expect => array_each( $cmp{user} ),
        !           147:             },
        !           148:             {   args   => { interests => 'lockpicking' },
        !           149:                 expect => array_each( $cmp{user} ),
1.2       andrew    150:             },
                    151:         ],
                    152:         stats => [
                    153:             {   args   => undef,
1.4       andrew    154:                 expect => qr/^Unused \s feature/xms,
1.2       andrew    155:             },
                    156:         ],
                    157:     );
                    158:
1.9       andrew    159:     foreach my $method ( keys %tests ) {
                    160:         foreach my $test ( @{ $tests{$method} } ) {
1.2       andrew    161:             no warnings 'uninitialized';
                    162:             my $result;
                    163:             eval { $result = $amd->$method( $test->{args} ) };
1.4       andrew    164:             if ( ref $test->{expect} eq 'Regexp' ) {
                    165:                 like( $@, $test->{expect}, "AMD->$method($test->{args})" );
                    166:             }
                    167:             elsif ( ref $test->{expect} ) {
                    168:                 is( $@, '', "AMD->$method($test->{args})" );
1.9       andrew    169:                 cmp_deeply( $result, $test->{expect},
1.6       andrew    170:                           "AMD->$method($test->{args}) - "
                    171:                         . 'got expected result' );
1.4       andrew    172:             }
                    173:             else {
                    174:                 is( $@, $test->{expect}, "AMD->$method($test->{args})" );
                    175:             }
1.2       andrew    176:         }
                    177:     }
1.1       andrew    178: }

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