r1511 - trunk/varnish-tools/regress/lib/Varnish/Test

des at projects.linpro.no des at projects.linpro.no
Wed Jun 13 13:12:08 CEST 2007


Author: des
Date: 2007-06-13 13:12:07 +0200 (Wed, 13 Jun 2007)
New Revision: 1511

Modified:
   trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm
Log:
Let send_command() take care of quoting and assembling the command.


Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm	2007-06-12 12:26:03 UTC (rev 1510)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm	2007-06-13 11:12:07 UTC (rev 1511)
@@ -124,12 +124,20 @@
 		   $name, split(':', $self->{'engine'}->{'config'}->{'server_address'}));
 }
 
-sub send_command($$) {
-    my ($self, $command) = @_;
+sub send_command($@) {
+    my ($self, @args) = @_;
     croak 'not ready' if $self->{'state'} eq 'init';
     croak sprintf('busy awaiting earlier command (%s)', $self->{'pending'})
       if defined $self->{'pending'};
 
+    foreach (@args) {
+	if (m/[\s\"\n]/) {
+	    s/\n/\\n/g;
+	    s/\"/\\\"/g;
+	    s/^(.*)$/"$1"/g;
+	}
+    }
+    my $command = join(' ', @args);
     $self->{'mux'}->write($self->{'stdin'}, $command . "\n");
     $self->{'pending'} = $command;
 }
@@ -137,10 +145,13 @@
 sub send_vcl($$$) {
     my ($self, $config, $vcl) = @_;
 
-    $vcl =~ s/\n/ /g;
-    $vcl =~ s/"/\\"/g;
+    $self->send_command('vcl.inline', $config, $vcl);
+}
 
-    $self->send_command(sprintf('vcl.inline %s "%s"', $config, $vcl));
+sub use_vcl($$) {
+    my ($self, $config) = @_;
+
+    $self->send_command('vcl.use', $config);
 }
 
 sub start_child($) {
@@ -193,7 +204,7 @@
     }
 
     $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'})
-      if ($$data =~ /^200 0/ and $self->{'pending'});
+	if ($$data =~ /^200 0/ and $self->{'pending'});
 
     $$data = '';
 }




More information about the varnish-commit mailing list