root/test/t/103_simple_noit.t

Revision 239594a76cc5a52d016357dde39705aee39bd2e4, 2.4 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

fix this to run on my Mac again

  • Property mode set to 100644
Line 
1 use Test::More tests => 9;
2 use XML::LibXML;
3 use XML::LibXML::XPathContext;
4 use testconfig;
5 use Time::HiRes qw/gettimeofday tv_interval/;
6 use apiclient;
7
8 use strict;
9 my $xp = XML::LibXML->new();
10 my $xpc = XML::LibXML::XPathContext->new();
11 my @r;
12 my $doc;
13 my $codes = {};
14
15 ok(start_noit("103", { logs_debug => { '' => 'false' } }), 'starting noit');
16 sleep(1);
17 my $c = apiclient->new('localhost', $NOIT_API_PORT);
18 my $req_time = [gettimeofday];
19 @r = $c->capabilities();
20 my $answer_time = [gettimeofday];
21 is($r[0], 0, 'capa');
22 $doc = $xp->parse_string($r[1]);
23 foreach ($xpc->findnodes('/noit_capabilities/services/service[@name="control_dispatch"]/command', $doc)) {
24   $codes->{$_->getAttribute("code")} = $_->getAttribute("name");
25 }
26 is_deeply($codes,
27           { '0xfa57feed' => 'livestream_transit'
28           , '0x43415041' => 'capabilities_transit'
29           , '0x44454c45' => 'noit_wire_rest_api'
30           , '0x47455420' => 'noit_wire_rest_api'
31           , '0x48454144' => 'noit_wire_rest_api'
32           , '0x4d455247' => 'noit_wire_rest_api'
33           , '0x504f5354' => 'noit_wire_rest_api'
34           , '0x50555420' => 'noit_wire_rest_api'
35           , '0x7e66feed' => 'log_transit'
36           , '0xda7afeed' => 'log_transit'
37           },
38           'commands available');
39
40 # Time check
41 my $remote_time = $xpc->findvalue('/noit_capabilities/current_time', $doc);
42 my $request_duration = tv_interval($req_time, $answer_time);
43 $remote_time += $request_duration/2.0;
44 my $answer_time_sec = $answer_time->[0] + $answer_time->[1]/1000000.0;
45 my $time_error = abs($remote_time - $answer_time_sec);
46 cmp_ok($time_error, '<', $request_duration, 'time skew check');
47
48 $c = apiclient->new('localhost', $NOIT_API_PORT);
49 @r = $c->get("/checks/show/f7cea020-f19d-11dd-85a6-cb6d3a2207dc");
50 is($r[0], 404, 'get checks');
51
52 @r = $c->put("/checks/set/f7cea020-f19d-11dd-85a6-cb6d3a2207dc",
53         qq{<?xml version="1.0" encoding="utf8"?>
54 <check><attributes><target>127.0.0.1</target><period>5000</period><timeout>1000</timeout><name>selfcheck</name><filterset>allowall</filterset><module>selfcheck</module></attributes><config/></check>});
55
56 is($r[0], 200, 'add selfcheck');
57 $doc = $xp->parse_string($r[1]);
58 is($xpc->findvalue('/check/attributes/uuid', $doc), 'f7cea020-f19d-11dd-85a6-cb6d3a2207dc', 'saved');
59
60 sleep(1);
61 @r = $c->get("/checks/show/f7cea020-f19d-11dd-85a6-cb6d3a2207dc");
62 is($r[0], 200, 'get checks');
63 $doc = $xp->parse_string($r[1]);
64 is($xpc->findvalue('/check/state/state', $doc), 'good', 'results');
65
66 1;
Note: See TracBrowser for help on using the browser.