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

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

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