/
DynamoDB.pm6
88 lines (75 loc) · 2.24 KB
/
DynamoDB.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use v6;
unit module Test::Amazon::DynamoDB;
use Amazon::DynamoDB;
use AWS::Credentials;
use AWS::Session;
my constant $resolver = AWS::Credentials::Provider::FromEnv.new(
:access-key<TEST_AWS_DDB_ACCESS_KEY_ID>,
:secret-key<TEST_AWS_DDB_SECRET_ACCESS_KEY>,
:token<TEST_AWS_DDB_SECURITY_TOKEN TEST_AWS_DDB_SESSION_TOKEN>,
:expiry-time<TEST_AWS_DDB_CREDENTIAL_EXPIRATION>,
);
sub test-session() is export {
AWS::Session.new(
config-file => 't/aws/config'.IO,
credentials-file => 't/aws/credentials'.IO,
region => 'us-east-1',
);
}
sub test-credentials() is export {
AWS::Credentials.new(
access-key => 'AKISUCHABADIDEATOHAV',
secret-key => 'PJaLYouReallyOughtNotToDoThisOrPainComes',
);
}
sub new-dynamodb-actions(
:$ua is copy,
:$scheme is copy,
:$hostname is copy,
:$port is copy,
:$session is copy,
:$credentials is copy,
) is export {
$scheme //= test-env<scheme>;
$hostname //= test-env<hostname>;
$port //= test-env<port>;
$session //= test-session();
$credentials //= test-credentials();
Amazon::DynamoDB.new(
:$scheme, :$hostname, :$port,
:$session,
:$credentials,
|(:$ua with $ua),
);
}
sub test-env is export {
$ //= %(
scheme => %*ENV<TEST_AWS_DDB_SCHEME> // 'http',
hostname => %*ENV<TEST_AWS_DDB_HOSTNAME>,
port => %*ENV<TEST_AWS_DDB_PORT>.defined ?? %*ENV<TEST_AWS_DDB_PORT>.Int !! Int,
table-prefix => %*ENV<TEST_AWS_DDB_TABLE_PREFIX>,
)
}
sub test-env-is-ok is export {
constant $required = all(< hostname table-prefix >);
test-env.{ $required }.defined;
}
sub test-env-skip-message is export {
q<Missing required environment, at least TEST_AWS_DDB_HOSTNAME and TEST_AWS_DDB_TABLE_PREFIX must be set.>;
}
sub test-prefix is export {
my $test-name = $*PROGRAM-NAME.IO.basename.subst(/.t$/, '');
$test-name ~ $*PID
}
sub tn(Str $name) is export {
my $test-tn = join '_', test-prefix(), $name;
with test-env.<table-prefix> -> $table-prefix {
join '_', $table-prefix, $test-tn
}
else {
$test-tn
}
}
sub test-data($name) is export {
EVALFILE("t/corpus/$name.p6");
}