]> Dogcows Code - chaz/graphql-client/blob - t/cli.t
2ae980e4f0a76e55785ba01d8da9fd56ff1bd404
[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 subtest 'get_options' => sub {
12 my $expected = {
13 format => 'json:pretty',
14 help => undef,
15 manual => undef,
16 operation_name => undef,
17 outfile => undef,
18 query => 'bar',
19 transport => undef,
20 unpack => 0,
21 url => 'foo',
22 variables => undef,
23 version => undef,
24 };
25
26 my $r = GraphQL::Client::CLI->_get_options(qw{--url foo --query bar});
27 is_deeply($r, $expected, '--url and --query set options') or diag explain $r;
28
29 $r = GraphQL::Client::CLI->_get_options(qw{foo --query bar});
30 is_deeply($r, $expected, '--url is optional') or diag explain $r;
31
32 $r = GraphQL::Client::CLI->_get_options(qw{foo bar});
33 is_deeply($r, $expected, '--query is also optional') or diag explain $r;
34 };
35
36 subtest 'expand_vars' => sub {
37 my $r = GraphQL::Client::CLI::_expand_vars({
38 'foo.bar' => 'baz',
39 'foo.qux.muf' => 42,
40 'arr1[1].tut' => 'whatever',
41 'arr2[1][0].meh'=> 3.1415,
42 });
43 is_deeply($r, {
44 foo => {
45 bar => 'baz',
46 qux => {
47 muf => 42,
48 },
49 },
50 arr1 => [
51 undef,
52 {
53 tut => 'whatever',
54 }
55 ],
56 arr2 => [
57 undef,
58 [
59 {
60 meh => 3.1415,
61 },
62 ],
63 ],
64 }, 'expand all the vars') or diag explain $r;
65
66 throws_ok {
67 GraphQL::Client::CLI::_expand_vars({
68 'foo[0]' => 'baz',
69 'foo.bar' => 'muf',
70 });
71 } qr/^Conflicting keys/, 'throw if conflict between hash and array';
72
73 throws_ok {
74 GraphQL::Client::CLI::_expand_vars({
75 'foo' => 'baz',
76 'foo.bar' => 'muf',
77 });
78 } qr/^Conflicting keys/, 'throw if conflict between hash and scalar';
79 };
80
81 done_testing;
This page took 0.036149 seconds and 4 git commands to generate.