-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path01-config_spec.lua
152 lines (132 loc) · 4.47 KB
/
01-config_spec.lua
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
local pl_path = require("pl.path")
local pl_utils = require("pl.utils")
local d = require("pl.text").dedent
local restore = require "spec.helpers"
describe("config loader", function()
local config_info = d[[
[default]
region=eu-central-1
max_attempts=99
[profile tieske]
region=us-west-1
]]
local config_filename = pl_path.tmpname()
local config
before_each(function()
restore()
restore.setenv("HOME")
pl_utils.writefile(config_filename, config_info)
end)
after_each(function()
restore()
config = nil
os.remove(config_filename)
end)
it("sets defaults", function()
restore.setenv("AWS_CONFIG_FILE", config_filename)
restore.setenv("AWS_DEFAULT_REGION", "eu-west-1")
os.remove(config_filename) -- delete the file so we revert to defaults
config = require "resty.aws.config"
local conf = assert(config.get_config())
-- just calling out as separate test; picking default region
assert.equal("eu-west-1", conf.region)
-- all defaults
assert.same({
AWS_DEFAULT_REGION = "eu-west-1",
region = "eu-west-1",
AWS_CONFIG_FILE = config_filename,
AWS_EC2_METADATA_DISABLED = true,
AWS_PROFILE = 'default',
AWS_SHARED_CREDENTIALS_FILE = '~/.aws/credentials',
cli_timestamp_format = 'iso8601',
AWS_CLI_TIMESTAMP_FORMAT = 'iso8601',
duration_seconds = 3600,
AWS_DURATION_SECONDS = 3600,
max_attempts = 5,
AWS_MAX_ATTEMPTS = 5,
parameter_validation = true,
AWS_PARAMETER_VALIDATION = true,
retry_mode = 'standard',
AWS_RETRY_MODE = 'standard',
sts_regional_endpoints = 'regional',
AWS_STS_REGIONAL_ENDPOINTS = 'regional',
}, conf)
end)
it("loads the configuration; default profile", function()
restore.setenv("AWS_CONFIG_FILE", config_filename)
config = require "resty.aws.config"
local conf = assert(config.get_config())
-- from the config file; default profile
assert.equal("eu-central-1", conf.region)
assert.equal(99, conf.max_attempts)
assert.same({
AWS_CONFIG_FILE = config_filename,
AWS_EC2_METADATA_DISABLED = true,
AWS_PROFILE = 'default',
AWS_SHARED_CREDENTIALS_FILE = '~/.aws/credentials',
cli_timestamp_format = 'iso8601',
AWS_CLI_TIMESTAMP_FORMAT = 'iso8601',
duration_seconds = 3600,
AWS_DURATION_SECONDS = 3600,
max_attempts = 99,
AWS_MAX_ATTEMPTS = 5,
region = "eu-central-1",
parameter_validation = true,
AWS_PARAMETER_VALIDATION = true,
retry_mode = 'standard',
AWS_RETRY_MODE = 'standard',
sts_regional_endpoints = 'regional',
AWS_STS_REGIONAL_ENDPOINTS = 'regional',
}, conf)
end)
it("loads the configuration; 'tieske' profile", function()
restore.setenv("AWS_CONFIG_FILE", config_filename)
restore.setenv("AWS_PROFILE", "tieske")
config = require "resty.aws.config"
local conf = assert(config.get_config())
-- from the config file; profile 'tieske'
assert.equal("us-west-1", conf.region)
assert.same({
AWS_CONFIG_FILE = config_filename,
AWS_EC2_METADATA_DISABLED = true,
AWS_PROFILE = 'tieske',
AWS_SHARED_CREDENTIALS_FILE = '~/.aws/credentials',
cli_timestamp_format = 'iso8601',
AWS_CLI_TIMESTAMP_FORMAT = 'iso8601',
duration_seconds = 3600,
AWS_DURATION_SECONDS = 3600,
max_attempts = 5,
AWS_MAX_ATTEMPTS = 5,
region = "us-west-1",
parameter_validation = true,
AWS_PARAMETER_VALIDATION = true,
retry_mode = 'standard',
AWS_RETRY_MODE = 'standard',
sts_regional_endpoints = 'regional',
AWS_STS_REGIONAL_ENDPOINTS = 'regional',
}, conf)
end)
it("global field returns the global configuration", function()
config = require "resty.aws.config"
local conf = config.global
assert.same({
region = nil, -- detection should fail
AWS_CONFIG_FILE = "~/.aws/config",
AWS_EC2_METADATA_DISABLED = true,
AWS_PROFILE = 'default',
AWS_SHARED_CREDENTIALS_FILE = '~/.aws/credentials',
cli_timestamp_format = 'iso8601',
AWS_CLI_TIMESTAMP_FORMAT = 'iso8601',
duration_seconds = 3600,
AWS_DURATION_SECONDS = 3600,
max_attempts = 5,
AWS_MAX_ATTEMPTS = 5,
parameter_validation = true,
AWS_PARAMETER_VALIDATION = true,
retry_mode = 'standard',
AWS_RETRY_MODE = 'standard',
sts_regional_endpoints = 'regional',
AWS_STS_REGIONAL_ENDPOINTS = 'regional',
}, conf)
end)
end)