forked from jeckhart/bash-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-ec2-metadata.bats
71 lines (59 loc) · 1.54 KB
/
aws-ec2-metadata.bats
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
#!/usr/bin/env bats
source "$BATS_TEST_DIRNAME/../modules/bash-commons/src/aws.sh"
load "test-helper"
load "aws-helper"
readonly local_ipv4="11.22.33.44"
readonly public_ipv4="55.66.77.88"
readonly local_hostname="ip-10-251-50-12.ec2.internal"
readonly public_hostname="ec2-203-0-113-25.compute-1.amazonaws.com"
readonly instance_id="i-1234567890abcdef0"
readonly mock_region="us-west-1"
readonly availability_zone="${mock_region}b"
function setup {
start_ec2_metadata_mock \
"$local_ipv4" \
"$public_ipv4" \
"$local_hostname" \
"$public_hostname" \
"$instance_id" \
"$mock_region" \
"$availability_zone"
}
function teardown {
stop_ec2_metadata_mock
}
@test "aws_get_instance_private_ip" {
run aws_get_instance_private_ip
assert_success
assert_output "$local_ipv4"
}
@test "aws_get_instance_public_ip" {
run aws_get_instance_public_ip
assert_success
assert_output "$public_ipv4"
}
@test "aws_get_instance_private_hostname" {
run aws_get_instance_private_hostname
assert_success
assert_output "$local_hostname"
}
@test "aws_get_instance_public_hostname" {
run aws_get_instance_public_hostname
assert_success
assert_output "$public_hostname"
}
@test "aws_get_instance_id" {
run aws_get_instance_id
assert_success
assert_output "$instance_id"
}
@test "aws_get_instance_region" {
run aws_get_instance_region
assert_success
assert_output "$mock_region"
}
@test "aws_get_ec2_instance_availability_zone" {
run aws_get_ec2_instance_availability_zone
assert_success
assert_output "$availability_zone"
}