Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / ext / action_helpers / perl / t / basic.t
diff --git a/ext/action_helpers/perl/t/basic.t b/ext/action_helpers/perl/t/basic.t
new file mode 100644 (file)
index 0000000..4717efb
--- /dev/null
@@ -0,0 +1,30 @@
+#!perl
+use strict;
+use Test::More;
+use JSON;
+use File::Temp;
+
+my $class = "MCollective::Action";
+use_ok( $class );
+
+my $infile  = File::Temp->new;
+my $outfile = File::Temp->new;
+
+$ENV{MCOLLECTIVE_REQUEST_FILE} = $infile->filename;
+$ENV{MCOLLECTIVE_REPLY_FILE}   = $outfile->filename;
+print $infile JSON->new->encode({ red => "apples", blue => "moon" });
+close $infile;
+{
+    my $mc = $class->new;
+    isa_ok( $mc, $class );
+    is( $mc->request->{red}, "apples", "apples are red" );
+    $mc->reply->{potato} = "chips";
+}
+
+my $json = do { local $/; <$outfile> };
+ok( $json, "Got some JSON" );
+my $reply = JSON->new->decode( $json );
+
+is( $reply->{potato}, "chips", "Got the reply that potato = chips" );
+
+done_testing();