blob: d058aac0a5345a8d0c49cca6236c28b34c1778db [file] [log] [blame]
Akron3340ae72022-11-22 12:20:13 +01001#!usr/bin/env perl
2use Mojolicious::Lite;
3use Mojolicious::Commands;
4use Data::Dumper;
5use Test::Output qw/:stdout :stderr :combined :functions/;
6use Test::More;
7use Test::Mojo;
8use Mojo::Util qw/decode encode/;
9use Mojo::JSON qw/decode_json/;
10use Mojo::File 'path';
11use File::Temp 'tempdir';
12
13my $t = Test::Mojo->new('Kalamar');
14
15my $dir = tempdir CLEANUP => 1;
16chdir $dir;
17
18my $dir_ext = tempdir CLEANUP => 1;
19
20my $cmds = $t->app->commands;
21
22like(
23 join(' ', @{$cmds->namespaces}),
24 qr!Mojolicious::Command!,
25 'Namespace is set'
26);
27
28like(
29 join(' ', @{$cmds->namespaces}),
30 qr!Kalamar::Command!,
31 'Namespace is set'
32);
33
34stdout_like(
35 sub {
36 local $ENV{HARNESS_ACTIVE} = 0;
37 $cmds->run('super-client-info');
38 },
39 qr/\[write\].*super_client_info/,
40 'Write'
41);
42
43stdout_unlike(
44 sub {
45 local $ENV{HARNESS_ACTIVE} = 0;
46 $cmds->run('super-client-info');
47 },
48 qr/\[write\].*super_client_info/,
49 'Already exists'
50);
51
52my $file = path($dir, 'super_client_info');
53
54my $out = decode_json($file->slurp);
55
56like($out->{client_id},qr!^.{20}$!);
57like($out->{client_secret},qr!^.{20}$!);
58
59unlink $file->to_string;
60
61stdout_like(
62 sub {
63 local $ENV{HARNESS_ACTIVE} = 0;
64 $cmds->run('super-client-info', 'my-client');
65 },
66 qr/\[write\].*super_client_info/,
67 'Write with client id'
68);
69
70$out = decode_json($file->slurp);
71
72like($out->{client_id}, qr!my-client$!);
73like($out->{client_secret}, qr!^.{20}$!);
74
75my $file_ext = path($dir_ext, 'super_client_fun');
76
77stdout_like(
78 sub {
79 local $ENV{HARNESS_ACTIVE} = 0;
80 $cmds->run('super-client-info', 'my-client-2', $file_ext);
81 },
82 qr/\[write\].*super_client_fun/,
83 'Error'
84);
85
86$out = decode_json($file->slurp);
87
88like($out->{client_id}, qr!my-client$!);
89like($out->{client_secret}, qr!^.{20}$!);
90
91my $secret_1 = $out->{client_secret};
92
93$out = decode_json($file_ext->slurp);
94
95like($out->{client_id}, qr!my-client-2$!);
96like($out->{client_secret}, qr!^.{20}$!);
97
98my $secret_2 = $out->{client_secret};
99
100isnt($secret_1, $secret_2, 'Generated secrets differ');
101
102
103done_testing;
104__END__