source: trunk/LATMOS-Accounts/t/05_utils.t @ 1966

Last change on this file since 1966 was 1378, checked in by nanardon, 9 years ago

add yesno() function for configutration option

File size: 1.8 KB
RevLine 
[209]1use strict;
2use warnings;
[1378]3use Test::More tests => 21;
[335]4use File::Temp qw(mkstemp);
[209]5
6use_ok('LATMOS::Accounts::Utils');
[1216]7use_ok('LATMOS::Accounts::Mail');
[210]8use LATMOS::Accounts::Log;
9
10ok(la_log(LA_NOTICE, "a notice"), "can run la_log");
[335]11
12my ($fh, $file) = mkstemp( "tmpfileXXXXX" );
13print $fh <<EOF;
14attr1: attr1
15attr: val1
16attr: val2
17EOF
18
19seek($fh, 0, 0);
20
21my %attributes = LATMOS::Accounts::Utils::parse_obj_file($fh);
22$fh = undef;
[338]23unlink($file);
[335]24
25# now testing
26is($attributes{'attr1'}, 'attr1', "can get attribute from file");
27ok(eq_set($attributes{'attr'}, [ qw(val1 val2) ]),
28        "can get multiple values attribute");
29
30$ENV{EDITOR} = 'sleep 1; /bin/touch';
31
32ok(LATMOS::Accounts::Utils::dump_read_temp_file(
33        sub { 1; }, sub { 1; }), "Can edit temp file");
[674]34
35ok(!LATMOS::Accounts::Utils::check_oid_validity('toto'), '"toto" is valid oid');
36ok(!LATMOS::Accounts::Utils::check_oid_validity('toTo'), '"toTo" is valid oid');
37ok(LATMOS::Accounts::Utils::check_oid_validity('to to'), '"to to" is invalid oid');
38ok(LATMOS::Accounts::Utils::check_oid_validity(' toto'), '" toto" is invalid oid');
39
40ok(!LATMOS::Accounts::Utils::check_ug_validity('toto'), '"toto" is valid username');
41ok(LATMOS::Accounts::Utils::check_ug_validity('toTo'), '"toTo" is invalid username');
42ok(LATMOS::Accounts::Utils::check_ug_validity('to to'), '"to to" is invalid username');
43ok(LATMOS::Accounts::Utils::check_ug_validity(' toto'), '" toto" is invalid username');
44ok(LATMOS::Accounts::Utils::check_ug_validity('5toto'), '"5toto" is invalid username');
45ok(!LATMOS::Accounts::Utils::check_ug_validity('t5oto'), '"t5oto" is valid username');
[1378]46
47is(yesno('yes'),  1, 'yes is true');
48is(yesno('true'), 1, 'true is true');
49is(yesno('23'),   1, '23 is true');
50is(yesno('no'),   0, 'no is false');
51is(yesno('what'), 'what', 'what is what?');
Note: See TracBrowser for help on using the repository browser.