From: Dobrica Pavlinusic Date: Sun, 28 Oct 2007 11:11:40 +0000 (+0000) Subject: refactore response tests to create response xml files if X-Git-Url: http://git.rot13.org/?p=perl-cwmp.git;a=commitdiff_plain;h=7708ae2c562775287d41712106c5dac618e39bea refactore response tests to create response xml files if they doesn't exist (so, implementing new command consists of adding one line in 20-response.t, re-run test and check if xml is valid and commit it :-) git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@164 836a5e1a-633d-0410-964b-294494ad4392 --- diff --git a/t/20-response.t b/t/20-response.t index b273606..f3dea36 100755 --- a/t/20-response.t +++ b/t/20-response.t @@ -4,83 +4,40 @@ use warnings; my $debug = shift @ARGV; -use Test::More tests => 11; +use Test::More tests => 12; use Data::Dump qw/dump/; +use Cwd qw/abs_path/; +use File::Slurp; use blib; BEGIN { use_ok('CWMP::Response'); } -#ok( my $xml = join("",), 'xml' ); -#diag $xml if $debug; +ok(my $abs_path = abs_path($0), "abs_path"); +$abs_path =~ s!/[^/]*$!/!; #!fix-vim ok( my $response = CWMP::Response->new({ debug => $debug }), 'new' ); isa_ok( $response, 'CWMP::Response' ); -sub is_like { - my ( $command, $template_xml ) = @_; +sub check_response { + my $command = shift || die "no command?"; - ok( my $xml = $response->$command({ ID => 42 }), $command ); - diag $xml if $debug; - chomp( $xml ); - chomp( $template_xml ); - like( $xml, qr{^\Q$template_xml\E$}, $command . ' xml' ); -} + ok( my $xml = $response->$command({ ID => 42 }), "generate response for $command" ); + + my $file = "$abs_path/response/$command.xml"; -is_like( 'InformResponse', <<__SOAP__ - - - 42 - 0 - - - - 1 - - - -__SOAP__ -); + if ( ! -e $file ) { + diag "creating $file"; + write_file( $file, $xml ); + } -is_like( 'GetRPCMethods', <<__SOAP__ - - - 42 - 0 - - - - - -__SOAP__ -); + my $template_xml = read_file( $file ) || die "can't read template xml $file: $!"; -is_like( 'Reboot', <<__SOAP__ - - - 42 - 0 - - - - - -__SOAP__ -); + is( $xml, $template_xml, "compare $command" ); +} -is_like( 'GetParameterNames', <<__SOAP__ - - - 42 - 0 - - - - - 0 - - - -__SOAP__ -); +check_response( 'InformResponse' ); +check_response( 'GetRPCMethods' ); +check_response( 'Reboot' ); +check_response( 'GetParameterNames' ); diff --git a/t/response/GetParameterNames.xml b/t/response/GetParameterNames.xml new file mode 100644 index 0000000..90cd0eb --- /dev/null +++ b/t/response/GetParameterNames.xml @@ -0,0 +1,14 @@ + + + 42 + 0 + + + + + 0 + + + \ No newline at end of file diff --git a/t/response/GetRPCMethods.xml b/t/response/GetRPCMethods.xml new file mode 100644 index 0000000..259756b --- /dev/null +++ b/t/response/GetRPCMethods.xml @@ -0,0 +1,11 @@ + + + 42 + 0 + + + + + \ No newline at end of file diff --git a/t/response/InformResponse.xml b/t/response/InformResponse.xml new file mode 100644 index 0000000..8ae94fc --- /dev/null +++ b/t/response/InformResponse.xml @@ -0,0 +1,13 @@ + + + 42 + 0 + + + + 1 + + + \ No newline at end of file diff --git a/t/response/Reboot.xml b/t/response/Reboot.xml new file mode 100644 index 0000000..fb92986 --- /dev/null +++ b/t/response/Reboot.xml @@ -0,0 +1,11 @@ + + + 42 + 0 + + + + + \ No newline at end of file