avoid fatpacking JSON::Path::Evaluator
[chaz/graphql-client] / t / cli.t
1 #!/usr/bin/env perl
2
3 use warnings;
4 use strict;
5
6 use Test::Exception;
7 use Test::More;
8
9 use GraphQL::Client::CLI;
10
11 delete $ENV{GRAPHQL_CLIENT_OPTIONS};
12
13 subtest 'get_options' => sub {
14 my $expected = {
15 format => 'json:pretty',
16 filter => undef,
17 help => undef,
18 manual => undef,
19 operation_name => undef,
20 outfile => undef,
21 query => 'bar',
22 transport => undef,
23 unpack => 0,
24 url => 'foo',
25 variables => undef,
26 version => undef,
27 };
28
29 my $r = GraphQL::Client::CLI->_get_options(qw{--url foo --query bar});
30 is_deeply($r, $expected, '--url and --query set options') or diag explain $r;
31
32 $r = GraphQL::Client::CLI->_get_options(qw{foo --query bar});
33 is_deeply($r, $expected, '--url is optional') or diag explain $r;
34
35 $r = GraphQL::Client::CLI->_get_options(qw{foo bar});
36 is_deeply($r, $expected, '--query is also optional') or diag explain $r;
37
38 {
39 local $ENV{GRAPHQL_CLIENT_OPTIONS} = '--url asdf --query "baz qux" --unpack';
40 local $expected->{query} = 'baz qux';
41 local $expected->{unpack} = 1;
42 $r = GraphQL::Client::CLI->_get_options(qw{--url foo});
43 is_deeply($r, $expected, 'options can come from GRAPHQL_CLIENT_OPTIONS') or diag explain $r;
44 }
45 };
46
47 subtest 'expand_vars' => sub {
48 my $r = GraphQL::Client::CLI::_expand_vars({
49 'foo.bar' => 'baz',
50 'foo.qux.muf' => 42,
51 'arr1[1].tut' => 'whatever',
52 'arr2[1][0].meh'=> 3.1415,
53 });
54 is_deeply($r, {
55 foo => {
56 bar => 'baz',
57 qux => {
58 muf => 42,
59 },
60 },
61 arr1 => [
62 undef,
63 {
64 tut => 'whatever',
65 }
66 ],
67 arr2 => [
68 undef,
69 [
70 {
71 meh => 3.1415,
72 },
73 ],
74 ],
75 }, 'expand all the vars') or diag explain $r;
76
77 throws_ok {
78 GraphQL::Client::CLI::_expand_vars({
79 'foo[0]' => 'baz',
80 'foo.bar' => 'muf',
81 });
82 } qr/^Conflicting keys/, 'throw if conflict between hash and array';
83
84 throws_ok {
85 GraphQL::Client::CLI::_expand_vars({
86 'foo' => 'baz',
87 'foo.bar' => 'muf',
88 });
89 } qr/^Conflicting keys/, 'throw if conflict between hash and scalar';
90 };
91
92 done_testing;
This page took 0.039679 seconds and 4 git commands to generate.