pass slice group name to new
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 10 Dec 2011 21:39:06 +0000 (22:39 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 10 Dec 2011 21:39:06 +0000 (22:39 +0100)
lib/CloudStore/API.pm
t/API.t

index c6aed04..7913d36 100644 (file)
@@ -11,14 +11,16 @@ use File::Find;
 use Data::Dump qw(dump);
 
 sub new {
-       my $class = shift;
-       my $self = {@_};
+       my ($class,$group) = @_;
+
+       my ( undef, $dir, $port, undef ) = getgrnam($group) || die "can't find group $group: $!";
+       my $self = {
+               passwd => '/var/lib/extrausers/passwd',
+               PORT => $port,
+               SLICE => $dir,
+       };
        bless $self, $class;
 
-       $self->{passwd} ||= '/var/lib/extrausers/passwd';
-       $self->{PORT}   ||= $ENV{PORT}  || die "no PORT in env";
-       $self->{SLICE}  ||= $ENV{SLICE} || die "no SLICE in env";
-
        $self->{md5} = $self->user_info('md5');
 
        return $self;
diff --git a/t/API.t b/t/API.t
index 2083c28..7a22ef8 100755 (executable)
--- a/t/API.t
+++ b/t/API.t
@@ -9,10 +9,7 @@ use lib 'lib';
 
 use_ok 'CloudStore::API';
 
-$ENV{PORT}=6500;
-$ENV{SLICE}='/tmp/';
-
-ok my $o = CloudStore::API->new, 'new';
+ok my $o = CloudStore::API->new('s1'), 'new';
 
 cmp_ok $o->create_user('md5@example.com','md5sum',0), '==', 2000, 'create_user md5';