CloudDeploy/DeploymentCollection.pm untested

filter: Statementstmt 0.0% 0 / 79 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 101 CC 4 SCAR 15.9
CC
4
Cov
0%
search_log_deployments
12.0
get_old_deployment
6.0
customer_deployments
2.0
CRAP 4.9
1 package CloudDeploy::DeploymentCollection {
2 use Moose;
3 use CloudDeploy::Config;
4 use CCfnX::Deployment;
5  
6 has mongo => (is => 'rw', default => sub { CloudDeploy::Config->new->deploy_mongo }, lazy => 1);
7 has mongolog => (is => 'rw', default => sub { CloudDeploy::Config->new->deploylog_mongo }, lazy => 1);
8 has account => (is => 'ro', isa => 'Str', required => 1);
9  
10 sub customer_deployments {
11 my ($self) = @_;
12 my $deployments = $self->mongo->query({
13 account => $self->account
14 });
15  
16 my @list = ();
17  
18 while (my $deployment = $deployments->next) {
19 push @list, $deployment->{ name };
20 }
21  
22 return @list;
23 }
24  
25 sub last_log_deployments {
26 my ($self, $limit) = @_;
27  
28 my $status = { '$nin' => [ 'building', 'updating' ] };
29  
30 my $deployments = $self->mongolog->query({
31 account => $self->account, status => $status
32 })->sort([ timestamp => -1])->limit($limit);
33  
34 my @list = ();
35  
36 while (my $deployment = $deployments->next) {
37 push @list, [ $deployment->{ timestamp }, $deployment->{ status }, $deployment->{ name } ];
38 }
39  
40 return @list;
41 }
42  
43 sub search_log_deployments {
44 my ($self, $criteria, $limit) = @_;
45  
46 unless (grep { /status/ } keys %{ $criteria }) {
47 $criteria->{'status'} = { '$nin' => [ 'building', 'updating' ] };
48 }
49  
50 unless (grep { /account/ } keys %{ $criteria }) {
51 $criteria->{'account'} = $self->account;
52 }
53  
54 my $deployments = $self->mongolog->query($criteria)->sort([ timestamp => -1])->limit($limit);
55  
56 my @list = ();
57  
58 while (my $deployment = $deployments->next) {
59 push @list, [ $deployment->{ timestamp }, $deployment->{ status }, $deployment->{ name } ];
60 }
61  
62 return @list;
63 }
64  
65 sub deployment_exists {
66 my ($self, $name) = @_;
67  
68 my $deployment = $self->mongo->find_one({
69 account => $self->account,
70 name => $name,
71 });
72  
73 return (defined $deployment);
74 }
75  
76 use CCfn;
77 sub get_deployment {
78 my ($self, $name) = @_;
79 my $deploy = CCfnX::Deployment->new_with_roles(
80 { mongo => $self->mongo, account => $self->account, name => $name },
81 'CCfnX::PersistentDeployment');
82  
83 $deploy->get_from_mongo;
84 return $deploy;
85 }
86  
87 sub get_old_deployment {
88 my ($self, $name, $timestamp) = @_;
89  
90 my $status = { '$nin' => [ 'building', 'updating' ] };
91  
92 my $deployment = $self->mongolog->find_one({
93 account => $self->account,
94 status => $status,
95 name => $name,
96 timestamp => $timestamp
97 });
98  
99 my $deploy;
100  
101 if (defined $deployment) {
102 my $log_id = $deployment->{_id}->to_string;
103  
104 $deploy = CCfnX::Deployment->new_with_roles(
105 { mongolog => $self->mongolog, account => $self->account, name => $name, log_id => $log_id },
106 'CCfnX::PersistentDeployment');
107  
108 $deploy->get_from_mongolog;
109 }
110  
111 return $deploy;
112 }
113 }
114  
115 1;