source: branches/2.0/LATMOS-Accounts/t/05_utils.t @ 2455

Last change on this file since 2455 was 674, checked in by nanardon, 14 years ago
  • add two functions in Utils module:
    • check_oid_validity(): check object name validity
    • check_ug_validity(): check user and group name validity
File size: 1.6 KB
Line 
1use strict;
2use warnings;
3use Test::More tests => 15;
4use File::Temp qw(mkstemp);
5
6use_ok('LATMOS::Accounts::Utils');
7use LATMOS::Accounts::Log;
8
9ok(la_log(LA_NOTICE, "a notice"), "can run la_log");
10
11my ($fh, $file) = mkstemp( "tmpfileXXXXX" );
12print $fh <<EOF;
13attr1: attr1
14attr: val1
15attr: val2
16EOF
17
18seek($fh, 0, 0);
19
20my %attributes = LATMOS::Accounts::Utils::parse_obj_file($fh);
21$fh = undef;
22unlink($file);
23
24# now testing
25is($attributes{'attr1'}, 'attr1', "can get attribute from file");
26ok(eq_set($attributes{'attr'}, [ qw(val1 val2) ]),
27        "can get multiple values attribute");
28
29$ENV{EDITOR} = 'sleep 1; /bin/touch';
30
31ok(LATMOS::Accounts::Utils::dump_read_temp_file(
32        sub { 1; }, sub { 1; }), "Can edit temp file");
33
34ok(!LATMOS::Accounts::Utils::check_oid_validity('toto'), '"toto" is valid oid');
35ok(!LATMOS::Accounts::Utils::check_oid_validity('toTo'), '"toTo" is valid oid');
36ok(LATMOS::Accounts::Utils::check_oid_validity('to to'), '"to to" is invalid oid');
37ok(LATMOS::Accounts::Utils::check_oid_validity(' toto'), '" toto" is invalid oid');
38
39ok(!LATMOS::Accounts::Utils::check_ug_validity('toto'), '"toto" is valid username');
40ok(LATMOS::Accounts::Utils::check_ug_validity('toTo'), '"toTo" is invalid username');
41ok(LATMOS::Accounts::Utils::check_ug_validity('to to'), '"to to" is invalid username');
42ok(LATMOS::Accounts::Utils::check_ug_validity(' toto'), '" toto" is invalid username');
43ok(LATMOS::Accounts::Utils::check_ug_validity('5toto'), '"5toto" is invalid username');
44ok(!LATMOS::Accounts::Utils::check_ug_validity('t5oto'), '"t5oto" is valid username');
Note: See TracBrowser for help on using the repository browser.