File: | t/090_corpus__010_success_full.t |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!perl | ||||||
2 | |||||||
3 | 1 1 1 | 3199 1 17 | use strict; | ||||
4 | 1 1 1 | 3 0 19 | use warnings; | ||||
5 | 1 1 1 | 766 509 4 | use lib 'lib'; | ||||
6 | |||||||
7 | 1 1 1 | 802 115871 3 | use Test::Most; | ||||
8 | 1 1 1 | 22972 8076 3 | use JSON qw/decode_json/; | ||||
9 | 1 1 1 | 693 3 1334 | use JSON::DJARE::Writer; | ||||
10 | |||||||
11 | 1 | 69212 | my $expected = decode_json( join '', (<DATA>) ); | ||||
12 | |||||||
13 | 1 | 10 | my $djare = JSON::DJARE::Writer->new( | ||||
14 | djare_version => '0.0.2', | ||||||
15 | meta_version => '0.1.0', | ||||||
16 | meta_from => 'rescue.int/launch/machines#POST', | ||||||
17 | meta_schema => 'https://rescue.int/schemas/launch/machines/response.json', | ||||||
18 | auto_timestamp => 1, | ||||||
19 | ); | ||||||
20 | |||||||
21 | 1 | 5 | my $result = $djare->data( | ||||
22 | { | ||||||
23 | machines => [ | ||||||
24 | { | ||||||
25 | id => "thunderbird-1", | ||||||
26 | status => "go", | ||||||
27 | pilot => { | ||||||
28 | username => "scott.tracy", | ||||||
29 | comment => "FAB" | ||||||
30 | } | ||||||
31 | }, | ||||||
32 | { | ||||||
33 | id => "thunderbird-4", | ||||||
34 | status => "go", | ||||||
35 | pilot => { | ||||||
36 | username => "gordon.tracy", | ||||||
37 | comment => "FAB" | ||||||
38 | } | ||||||
39 | } | ||||||
40 | ] | ||||||
41 | } | ||||||
42 | ); | ||||||
43 | |||||||
44 | # meta/trace is discouraged, so we need to manually add to it | ||||||
45 | 1 | 3 | $result->{'meta'}->{'trace'} = { | ||||
46 | "_comment" => "don't stick too much stuff in trace, see the docs", | ||||||
47 | "request-id" => "X-deadbeef" | ||||||
48 | }; | ||||||
49 | |||||||
50 | # Fudge the auto-timestamp | ||||||
51 | 1 | 2 | $expected->{'meta'}->{'timestamp'} = JSON::DJARE::Writer->auto_timestamp; | ||||
52 | |||||||
53 | 1 | 4 | eq_or_diff( $result, $expected, "matches" ); | ||||
54 | |||||||
55 | # Sanity-check that timestamp tho | ||||||
56 | like( | ||||||
57 | 1 | 3383 | $expected->{'meta'}->{'timestamp'}, | ||||
58 | qr/20\d\d\-\d\d\-\d\d \d\d:\d\d:\d\d/, | ||||||
59 | "timestamp looks reasonably shaped" | ||||||
60 | ); | ||||||
61 | |||||||
62 | 1 | 265 | done_testing(); | ||||
63 |