Annotation of HOPE/Net-OpenAMD/t/network_tests.t, Revision 1.9
1.1 andrew 1: #!perl
2: package NetworkTests;
1.2 andrew 3:
1.9 ! andrew 4: # $AFresh1: network_tests.t,v 1.8 2010/07/13 00:14:43 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]+$'),
! 50: multi_line => re('^.*$'),
! 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.9 ! 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(
! 82: { name => $cmp{single_line},
! 83: bio => $cmp{multi_line},
! 84: }
! 85: ),
1.2 andrew 86: },
87: ],
88: talks => [
89: { args => undef,
1.9 ! andrew 90: expect => array_each(
! 91: { abstract => $cmp{single_line},
! 92: interests => array_each( $cmp{interests} ),
! 93: speakers => array_each( $cmp{single_line} ),
! 94: time => $cmp{single_line},
! 95: title => $cmp{multi_line},
! 96: track => $cmp{track},
! 97: }
! 98: ),
1.2 andrew 99: },
100: ],
101: interests => [
102: { args => undef,
1.9 ! andrew 103: expect => $cmp{all_interests},
1.2 andrew 104: },
105: ],
106: users => [
107: { args => undef,
1.9 ! andrew 108: expect => array_each(
! 109: { interests => array_each( $cmp{interests} ),
! 110: name => $cmp{single_line},
! 111: x => $cmp{coordinate},
! 112: y => $cmp{coordinate},
! 113: }
! 114: ),
1.2 andrew 115: },
116: ],
117: stats => [
118: { args => undef,
1.4 andrew 119: expect => qr/^Unused \s feature/xms,
1.2 andrew 120: },
121: ],
122: );
123:
1.9 ! andrew 124: foreach my $method ( keys %tests ) {
! 125: foreach my $test ( @{ $tests{$method} } ) {
1.2 andrew 126: no warnings 'uninitialized';
127: my $result;
128: eval { $result = $amd->$method( $test->{args} ) };
1.4 andrew 129: if ( ref $test->{expect} eq 'Regexp' ) {
130: like( $@, $test->{expect}, "AMD->$method($test->{args})" );
131: }
132: elsif ( ref $test->{expect} ) {
133: is( $@, '', "AMD->$method($test->{args})" );
1.9 ! andrew 134: cmp_deeply( $result, $test->{expect},
1.6 andrew 135: "AMD->$method($test->{args}) - "
136: . 'got expected result' );
1.4 andrew 137: }
138: else {
139: is( $@, $test->{expect}, "AMD->$method($test->{args})" );
140: }
1.2 andrew 141: }
142: }
1.1 andrew 143: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>