1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_admin_script';
7 # just in case the user env has stuff in it
8 delete $ENV{JSON_ANY_ORDER};
9 delete $ENV{DBICTEST_VERSION_WARNS_INDISCRIMINATELY};
19 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
21 my @json_backends = qw(DWIW PP JSON CPANEL XS);
23 # test the script is setting @INC properly
24 test_exec (qw|-It/lib/testinclude --schema=DBICTestAdminInc --connect=[] --insert|);
25 cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from connecting a custom INC schema' );
27 # test that config works properly
30 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --create --connect=["klaatu","barada","nikto"]|);
31 cmp_ok( $? >> 8, '==', 71, 'Correct schema loaded via config' ) || exit;
34 # test that config-file works properly
35 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --config=t/lib/admincfgtest.json --config-stanza=Model::Gort --deploy|);
36 cmp_ok ($? >> 8, '==', 71, 'Correct schema loaded via testconfig');
38 for my $js (@json_backends) {
41 eval {JSON::Any->import ($js); 1 }
42 or skip ("JSON backend $js is not available, skip testing", 1);
44 local $ENV{JSON_ANY_ORDER} = $js;
45 eval { test_dbicadmin () };
53 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
55 my $employees = $schema->resultset('Employee');
57 test_exec( default_args(), qw|--op=insert --set={"name":"Matt"}| );
58 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
60 my $employee = $employees->find(1);
61 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
63 test_exec( default_args(), qw|--op=update --set={"name":"Trout"}| );
64 $employee = $employees->find(1);
65 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
67 test_exec( default_args(), qw|--op=insert --set={"name":"Aran"}| );
70 skip ("MSWin32 doesn't support -|", 1) if $^O eq 'MSWin32';
72 my ($perl) = $^X =~ /(.*)/;
74 open(my $fh, "-|", ( $perl, '-MDBICTest::RunMode', 'script/dbicadmin', default_args(), qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
75 my $data = do { local $/; <$fh> };
77 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
78 diag ("data from select is $data")
82 test_exec( default_args(), qw|--op=delete --where={"name":"Trout"}| );
83 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
87 my $dsn = JSON::Any->encode([
88 'dbi:SQLite:dbname=' . DBICTest->_sqlite_dbfilename,
95 qw|--quiet --schema=DBICTest::Schema --class=Employee|,
97 qw|--force -I testincludenoniterference|,
102 my ($perl) = $^X =~ /(.*)/;
104 my @args = ($perl, '-MDBICTest::RunMode', File::Spec->catfile(qw(script dbicadmin)), @_);
106 if ($^O eq 'MSWin32') {
107 require Win32::ShellQuote; # included in test optdeps
108 @args = Win32::ShellQuote::quote_system_list(@args);