config_files 0.1.6 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +94 -0
- data/.gitignore +2 -3
- data/.rubocop.yml +81 -0
- data/CHANGELOG.md +154 -0
- data/Gemfile +12 -1
- data/MULTI_RUBY_SETUP.md +158 -0
- data/README.md +246 -23
- data/Rakefile +26 -3
- data/TESTING.md +226 -0
- data/config_files.gemspec +12 -9
- data/docker/Dockerfile.test +32 -0
- data/lib/config_files/file_factory.rb +7 -3
- data/lib/config_files/loader_factory.rb +20 -11
- data/lib/config_files/loaders/base_parser.rb +133 -0
- data/lib/config_files/loaders/conf.rb +61 -0
- data/lib/config_files/loaders/default.rb +3 -1
- data/lib/config_files/loaders/ini.rb +48 -0
- data/lib/config_files/loaders/json.rb +3 -1
- data/lib/config_files/loaders/xml.rb +67 -0
- data/lib/config_files/loaders/yaml.rb +2 -0
- data/lib/config_files/loaders.rb +6 -1
- data/lib/config_files/version.rb +3 -1
- data/lib/config_files.rb +34 -18
- data/lib/meta.rb +3 -1
- data/scripts/install_rubies_asdf.sh +187 -0
- data/scripts/test_docker.sh +91 -0
- data/scripts/test_multiple_rubies.sh +290 -0
- data/test/comprehensive_multi_directory_test.rb +168 -0
- data/test/config/dummy.json +10 -0
- data/test/config/dummy.yml +6 -0
- data/test/config_files_test.rb +10 -8
- data/test/etc/dummy.conf +14 -2
- data/test/etc/dummy.ini +12 -0
- data/test/etc/dummy.xml +13 -0
- data/test/etc/dummy.yml +2 -2
- data/test/loader_factory_test.rb +10 -10
- data/test/loaders_test.rb +362 -0
- data/test/local/dummy.json +10 -0
- data/test/local/dummy.yml +6 -0
- data/test/mixed_format_test.rb +152 -0
- data/test/multi_directory_test.rb +126 -0
- data/test/test_helper.rb +3 -0
- metadata +49 -26
- data/Gemfile.lock +0 -34
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Script to test multiple Ruby versions using Docker
|
4
|
+
|
5
|
+
set -e
|
6
|
+
|
7
|
+
# Colors for output
|
8
|
+
RED='\033[0;31m'
|
9
|
+
GREEN='\033[0;32m'
|
10
|
+
YELLOW='\033[1;33m'
|
11
|
+
NC='\033[0m' # No Color
|
12
|
+
|
13
|
+
# Ruby versions to test
|
14
|
+
RUBY_VERSIONS=("2.7" "3.0" "3.1" "3.2" "3.3" "3.4")
|
15
|
+
|
16
|
+
# ActiveSupport versions to test
|
17
|
+
ACTIVESUPPORT_VERSIONS=("~> 6.1.0" "~> 7.0.0" "~> 7.1.0" "~> 7.2.0")
|
18
|
+
|
19
|
+
# Function to test a specific Ruby and ActiveSupport combination
|
20
|
+
test_combination() {
|
21
|
+
local ruby_version=$1
|
22
|
+
local activesupport_version=$2
|
23
|
+
|
24
|
+
echo -e "${YELLOW}Testing Ruby ${ruby_version} with ActiveSupport ${activesupport_version}${NC}"
|
25
|
+
|
26
|
+
# Skip incompatible combinations
|
27
|
+
if [[ "$ruby_version" =~ ^2\.[67] ]] && [[ "$activesupport_version" =~ 7\.[12] ]]; then
|
28
|
+
echo -e "${YELLOW}Skipping incompatible combination${NC}"
|
29
|
+
return 0
|
30
|
+
fi
|
31
|
+
|
32
|
+
# Build and run Docker container
|
33
|
+
if docker build \
|
34
|
+
--build-arg RUBY_VERSION="$ruby_version" \
|
35
|
+
--build-arg ACTIVESUPPORT_VERSION="$activesupport_version" \
|
36
|
+
-f docker/Dockerfile.test \
|
37
|
+
-t "config_files_test:ruby${ruby_version}-as${activesupport_version//[~>. ]/}" \
|
38
|
+
. && \
|
39
|
+
docker run --rm "config_files_test:ruby${ruby_version}-as${activesupport_version//[~>. ]/}"; then
|
40
|
+
echo -e "${GREEN}✓ Ruby ${ruby_version} with ActiveSupport ${activesupport_version} - PASSED${NC}"
|
41
|
+
return 0
|
42
|
+
else
|
43
|
+
echo -e "${RED}✗ Ruby ${ruby_version} with ActiveSupport ${activesupport_version} - FAILED${NC}"
|
44
|
+
return 1
|
45
|
+
fi
|
46
|
+
}
|
47
|
+
|
48
|
+
# Main execution
|
49
|
+
echo -e "${YELLOW}Starting Docker-based multi-Ruby testing...${NC}"
|
50
|
+
|
51
|
+
# Check if Docker is available
|
52
|
+
if ! command -v docker >/dev/null 2>&1; then
|
53
|
+
echo -e "${RED}Docker not found. Please install Docker to use this script.${NC}"
|
54
|
+
exit 1
|
55
|
+
fi
|
56
|
+
|
57
|
+
failed_combinations=()
|
58
|
+
total_tests=0
|
59
|
+
passed_tests=0
|
60
|
+
|
61
|
+
for ruby_version in "${RUBY_VERSIONS[@]}"; do
|
62
|
+
for activesupport_version in "${ACTIVESUPPORT_VERSIONS[@]}"; do
|
63
|
+
total_tests=$((total_tests + 1))
|
64
|
+
|
65
|
+
if test_combination "$ruby_version" "$activesupport_version"; then
|
66
|
+
passed_tests=$((passed_tests + 1))
|
67
|
+
else
|
68
|
+
failed_combinations+=("Ruby ${ruby_version} + ActiveSupport ${activesupport_version}")
|
69
|
+
fi
|
70
|
+
done
|
71
|
+
done
|
72
|
+
|
73
|
+
# Clean up Docker images
|
74
|
+
echo -e "\n${YELLOW}Cleaning up Docker images...${NC}"
|
75
|
+
docker images --format "table {{.Repository}}:{{.Tag}}" | grep "config_files_test" | xargs -r docker rmi
|
76
|
+
|
77
|
+
# Summary
|
78
|
+
echo -e "\n${YELLOW}=== Test Summary ===${NC}"
|
79
|
+
echo -e "Total combinations tested: ${total_tests}"
|
80
|
+
echo -e "${GREEN}Passed: ${passed_tests}${NC}"
|
81
|
+
echo -e "${RED}Failed: $((total_tests - passed_tests))${NC}"
|
82
|
+
|
83
|
+
if [ ${#failed_combinations[@]} -gt 0 ]; then
|
84
|
+
echo -e "\n${RED}Failed combinations:${NC}"
|
85
|
+
for combination in "${failed_combinations[@]}"; do
|
86
|
+
echo -e "${RED} - ${combination}${NC}"
|
87
|
+
done
|
88
|
+
exit 1
|
89
|
+
else
|
90
|
+
echo -e "\n${GREEN}All tests passed! 🎉${NC}"
|
91
|
+
fi
|
@@ -0,0 +1,290 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Script to test multiple Ruby versions locally
|
4
|
+
# Supports asdf, rbenv, and rvm
|
5
|
+
|
6
|
+
set -e
|
7
|
+
|
8
|
+
# Colors for output
|
9
|
+
RED='\033[0;31m'
|
10
|
+
GREEN='\033[0;32m'
|
11
|
+
YELLOW='\033[1;33m'
|
12
|
+
BLUE='\033[0;34m'
|
13
|
+
NC='\033[0m' # No Color
|
14
|
+
|
15
|
+
# Ruby versions to test
|
16
|
+
RUBY_VERSIONS=("2.7.8" "3.0.6" "3.1.4" "3.2.2" "3.3.0" "3.4.1")
|
17
|
+
|
18
|
+
# ActiveSupport versions to test
|
19
|
+
ACTIVESUPPORT_VERSIONS=("~> 6.1.0" "~> 7.0.0" "~> 7.1.0" "~> 7.2.0")
|
20
|
+
|
21
|
+
# Detect which Ruby version manager is available
|
22
|
+
RUBY_MANAGER=""
|
23
|
+
|
24
|
+
detect_ruby_manager() {
|
25
|
+
if command -v asdf >/dev/null 2>&1; then
|
26
|
+
RUBY_MANAGER="asdf"
|
27
|
+
echo -e "${BLUE}Detected asdf${NC}"
|
28
|
+
elif command -v rbenv >/dev/null 2>&1; then
|
29
|
+
RUBY_MANAGER="rbenv"
|
30
|
+
echo -e "${BLUE}Detected rbenv${NC}"
|
31
|
+
elif command -v rvm >/dev/null 2>&1; then
|
32
|
+
RUBY_MANAGER="rvm"
|
33
|
+
echo -e "${BLUE}Detected rvm${NC}"
|
34
|
+
else
|
35
|
+
echo -e "${RED}No Ruby version manager found!${NC}"
|
36
|
+
echo -e "${YELLOW}Please install one of the following:${NC}"
|
37
|
+
echo -e " - asdf: https://asdf-vm.com/guide/getting-started.html"
|
38
|
+
echo -e " - rbenv: https://github.com/rbenv/rbenv#installation"
|
39
|
+
echo -e " - rvm: https://rvm.io/rvm/install"
|
40
|
+
exit 1
|
41
|
+
fi
|
42
|
+
}
|
43
|
+
|
44
|
+
# Function to check if Ruby version is installed
|
45
|
+
check_ruby_version() {
|
46
|
+
local version=$1
|
47
|
+
case $RUBY_MANAGER in
|
48
|
+
"asdf")
|
49
|
+
asdf list ruby 2>/dev/null | grep -q "^\s*${version}$"
|
50
|
+
;;
|
51
|
+
"rbenv")
|
52
|
+
rbenv versions --bare | grep -q "^${version}$"
|
53
|
+
;;
|
54
|
+
"rvm")
|
55
|
+
rvm list | grep -q "${version}"
|
56
|
+
;;
|
57
|
+
esac
|
58
|
+
}
|
59
|
+
|
60
|
+
# Function to install Ruby version if not present
|
61
|
+
install_ruby_version() {
|
62
|
+
local version=$1
|
63
|
+
echo -e "${YELLOW}Installing Ruby ${version} with ${RUBY_MANAGER}...${NC}"
|
64
|
+
|
65
|
+
case $RUBY_MANAGER in
|
66
|
+
"asdf")
|
67
|
+
# Check if ruby plugin is installed
|
68
|
+
if ! asdf plugin list | grep -q "^ruby$"; then
|
69
|
+
echo -e "${YELLOW}Installing Ruby plugin for asdf...${NC}"
|
70
|
+
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
|
71
|
+
fi
|
72
|
+
asdf install ruby "$version"
|
73
|
+
;;
|
74
|
+
"rbenv")
|
75
|
+
rbenv install "$version"
|
76
|
+
;;
|
77
|
+
"rvm")
|
78
|
+
rvm install "$version"
|
79
|
+
;;
|
80
|
+
esac
|
81
|
+
|
82
|
+
if [ $? -eq 0 ]; then
|
83
|
+
echo -e "${GREEN}✓ Ruby ${version} installed successfully${NC}"
|
84
|
+
return 0
|
85
|
+
else
|
86
|
+
echo -e "${RED}✗ Failed to install Ruby ${version}${NC}"
|
87
|
+
return 1
|
88
|
+
fi
|
89
|
+
}
|
90
|
+
|
91
|
+
# Function to switch Ruby version
|
92
|
+
switch_ruby() {
|
93
|
+
local version=$1
|
94
|
+
|
95
|
+
case $RUBY_MANAGER in
|
96
|
+
"asdf")
|
97
|
+
asdf local ruby "$version"
|
98
|
+
# Verify the switch worked
|
99
|
+
local current_version
|
100
|
+
current_version=$(asdf current ruby 2>/dev/null | awk '{print $2}')
|
101
|
+
if [[ "$current_version" != "$version" ]]; then
|
102
|
+
echo -e "${RED}Failed to switch to Ruby ${version}. Current: ${current_version}${NC}"
|
103
|
+
return 1
|
104
|
+
fi
|
105
|
+
;;
|
106
|
+
"rbenv")
|
107
|
+
rbenv shell "$version"
|
108
|
+
# Verify the switch worked
|
109
|
+
local current_version
|
110
|
+
current_version=$(rbenv version-name)
|
111
|
+
if [[ "$current_version" != "$version" ]]; then
|
112
|
+
echo -e "${RED}Failed to switch to Ruby ${version}. Current: ${current_version}${NC}"
|
113
|
+
return 1
|
114
|
+
fi
|
115
|
+
;;
|
116
|
+
"rvm")
|
117
|
+
rvm use "$version"
|
118
|
+
# rvm use typically handles verification internally
|
119
|
+
;;
|
120
|
+
esac
|
121
|
+
|
122
|
+
echo -e "${BLUE}Switched to Ruby ${version} using ${RUBY_MANAGER}${NC}"
|
123
|
+
return 0
|
124
|
+
}
|
125
|
+
|
126
|
+
# Function to list available Ruby versions
|
127
|
+
list_available_versions() {
|
128
|
+
echo -e "\n${BLUE}Available Ruby versions:${NC}"
|
129
|
+
case $RUBY_MANAGER in
|
130
|
+
"asdf")
|
131
|
+
asdf list ruby 2>/dev/null || echo " No Ruby versions installed"
|
132
|
+
;;
|
133
|
+
"rbenv")
|
134
|
+
rbenv versions --bare || echo " No Ruby versions installed"
|
135
|
+
;;
|
136
|
+
"rvm")
|
137
|
+
rvm list || echo " No Ruby versions installed"
|
138
|
+
;;
|
139
|
+
esac
|
140
|
+
}
|
141
|
+
|
142
|
+
# Function to test a specific Ruby and ActiveSupport combination
|
143
|
+
test_combination() {
|
144
|
+
local ruby_version=$1
|
145
|
+
local activesupport_version=$2
|
146
|
+
|
147
|
+
echo -e "${YELLOW}Testing Ruby ${ruby_version} with ActiveSupport ${activesupport_version}${NC}"
|
148
|
+
|
149
|
+
# Skip incompatible combinations
|
150
|
+
if [[ "$ruby_version" =~ ^2\.[67] ]] && [[ "$activesupport_version" =~ 7\.[12] ]]; then
|
151
|
+
echo -e "${YELLOW}Skipping incompatible combination${NC}"
|
152
|
+
return 0
|
153
|
+
fi
|
154
|
+
|
155
|
+
# Create temporary Gemfile
|
156
|
+
cat > Gemfile.test << EOF
|
157
|
+
source 'https://rubygems.org'
|
158
|
+
|
159
|
+
gemspec
|
160
|
+
|
161
|
+
gem 'activesupport', '${activesupport_version}'
|
162
|
+
gem 'minitest', '~> 5.20'
|
163
|
+
gem 'mutex_m' if RUBY_VERSION >= '3.4'
|
164
|
+
gem 'rake'
|
165
|
+
EOF
|
166
|
+
|
167
|
+
# Install dependencies and run tests
|
168
|
+
if bundle install --gemfile=Gemfile.test && BUNDLE_GEMFILE=Gemfile.test bundle exec rake test; then
|
169
|
+
echo -e "${GREEN}✓ Ruby ${ruby_version} with ActiveSupport ${activesupport_version} - PASSED${NC}"
|
170
|
+
return 0
|
171
|
+
else
|
172
|
+
echo -e "${RED}✗ Ruby ${ruby_version} with ActiveSupport ${activesupport_version} - FAILED${NC}"
|
173
|
+
return 1
|
174
|
+
fi
|
175
|
+
}
|
176
|
+
|
177
|
+
# Handle command line arguments
|
178
|
+
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
179
|
+
echo -e "${BLUE}ConfigFiles Multi-Ruby Testing Script${NC}"
|
180
|
+
echo -e "${BLUE}====================================${NC}"
|
181
|
+
echo
|
182
|
+
echo -e "${YELLOW}Usage:${NC} $0 [options]"
|
183
|
+
echo
|
184
|
+
echo -e "${YELLOW}Options:${NC}"
|
185
|
+
echo -e " -h, --help Show this help message"
|
186
|
+
echo -e " --list List available Ruby versions and exit"
|
187
|
+
echo -e " --auto-install Automatically install missing Ruby versions without prompting"
|
188
|
+
echo
|
189
|
+
echo -e "${YELLOW}Supported Ruby Version Managers:${NC}"
|
190
|
+
echo -e " - asdf (recommended)"
|
191
|
+
echo -e " - rbenv"
|
192
|
+
echo -e " - rvm"
|
193
|
+
echo
|
194
|
+
echo -e "${YELLOW}Ruby Versions Tested:${NC}"
|
195
|
+
for version in "${RUBY_VERSIONS[@]}"; do
|
196
|
+
echo -e " - Ruby ${version}"
|
197
|
+
done
|
198
|
+
echo
|
199
|
+
echo -e "${YELLOW}ActiveSupport Versions Tested:${NC}"
|
200
|
+
for version in "${ACTIVESUPPORT_VERSIONS[@]}"; do
|
201
|
+
echo -e " - ActiveSupport ${version}"
|
202
|
+
done
|
203
|
+
echo
|
204
|
+
echo -e "${YELLOW}Examples:${NC}"
|
205
|
+
echo -e " $0 # Run interactive testing"
|
206
|
+
echo -e " $0 --list # Show available Ruby versions"
|
207
|
+
echo -e " $0 --auto-install # Install missing versions automatically"
|
208
|
+
exit 0
|
209
|
+
fi
|
210
|
+
|
211
|
+
# Main execution
|
212
|
+
echo -e "${YELLOW}Starting multi-Ruby testing...${NC}"
|
213
|
+
|
214
|
+
# Detect Ruby version manager
|
215
|
+
detect_ruby_manager
|
216
|
+
|
217
|
+
# Show available versions
|
218
|
+
list_available_versions
|
219
|
+
|
220
|
+
failed_combinations=()
|
221
|
+
total_tests=0
|
222
|
+
passed_tests=0
|
223
|
+
installed_versions=()
|
224
|
+
|
225
|
+
# Check and install Ruby versions
|
226
|
+
echo -e "\n${BLUE}Checking required Ruby versions...${NC}"
|
227
|
+
for ruby_version in "${RUBY_VERSIONS[@]}"; do
|
228
|
+
if check_ruby_version "$ruby_version"; then
|
229
|
+
echo -e "${GREEN}✓ Ruby ${ruby_version} is already installed${NC}"
|
230
|
+
installed_versions+=("$ruby_version")
|
231
|
+
else
|
232
|
+
echo -e "${YELLOW}Ruby ${ruby_version} not found${NC}"
|
233
|
+
read -p "Install Ruby ${ruby_version}? (y/N): " -n 1 -r
|
234
|
+
echo
|
235
|
+
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
236
|
+
if install_ruby_version "$ruby_version"; then
|
237
|
+
installed_versions+=("$ruby_version")
|
238
|
+
else
|
239
|
+
echo -e "${RED}Skipping Ruby ${ruby_version} due to installation failure${NC}"
|
240
|
+
fi
|
241
|
+
else
|
242
|
+
echo -e "${YELLOW}Skipping Ruby ${ruby_version}${NC}"
|
243
|
+
fi
|
244
|
+
fi
|
245
|
+
done
|
246
|
+
|
247
|
+
if [ ${#installed_versions[@]} -eq 0 ]; then
|
248
|
+
echo -e "${RED}No Ruby versions available for testing. Exiting.${NC}"
|
249
|
+
exit 1
|
250
|
+
fi
|
251
|
+
|
252
|
+
echo -e "\n${BLUE}Testing with ${#installed_versions[@]} Ruby versions...${NC}"
|
253
|
+
|
254
|
+
for ruby_version in "${installed_versions[@]}"; do
|
255
|
+
echo -e "\n${YELLOW}=== Testing Ruby ${ruby_version} ===${NC}"
|
256
|
+
|
257
|
+
if ! switch_ruby "$ruby_version"; then
|
258
|
+
echo -e "${RED}Failed to switch to Ruby ${ruby_version}. Skipping.${NC}"
|
259
|
+
continue
|
260
|
+
fi
|
261
|
+
|
262
|
+
for activesupport_version in "${ACTIVESUPPORT_VERSIONS[@]}"; do
|
263
|
+
total_tests=$((total_tests + 1))
|
264
|
+
|
265
|
+
if test_combination "$ruby_version" "$activesupport_version"; then
|
266
|
+
passed_tests=$((passed_tests + 1))
|
267
|
+
else
|
268
|
+
failed_combinations+=("Ruby ${ruby_version} + ActiveSupport ${activesupport_version}")
|
269
|
+
fi
|
270
|
+
|
271
|
+
# Clean up
|
272
|
+
rm -f Gemfile.test Gemfile.test.lock
|
273
|
+
done
|
274
|
+
done
|
275
|
+
|
276
|
+
# Summary
|
277
|
+
echo -e "\n${YELLOW}=== Test Summary ===${NC}"
|
278
|
+
echo -e "Total combinations tested: ${total_tests}"
|
279
|
+
echo -e "${GREEN}Passed: ${passed_tests}${NC}"
|
280
|
+
echo -e "${RED}Failed: $((total_tests - passed_tests))${NC}"
|
281
|
+
|
282
|
+
if [ ${#failed_combinations[@]} -gt 0 ]; then
|
283
|
+
echo -e "\n${RED}Failed combinations:${NC}"
|
284
|
+
for combination in "${failed_combinations[@]}"; do
|
285
|
+
echo -e "${RED} - ${combination}${NC}"
|
286
|
+
done
|
287
|
+
exit 1
|
288
|
+
else
|
289
|
+
echo -e "\n${GREEN}All tests passed! 🎉${NC}"
|
290
|
+
fi
|
@@ -0,0 +1,168 @@
|
|
1
|
+
$LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'config_files'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class ComprehensiveMultiDirectoryTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
# Create a comprehensive test scenario with multiple directories and formats
|
9
|
+
FileUtils.mkdir_p('test/comprehensive/global')
|
10
|
+
FileUtils.mkdir_p('test/comprehensive/environment')
|
11
|
+
FileUtils.mkdir_p('test/comprehensive/local')
|
12
|
+
|
13
|
+
# Global config (YAML)
|
14
|
+
File.write('test/comprehensive/global/app.yml', <<~YAML)
|
15
|
+
database:
|
16
|
+
host: global-db.example.com
|
17
|
+
port: 5432
|
18
|
+
pool_size: 10
|
19
|
+
app:
|
20
|
+
name: MyApp
|
21
|
+
version: 1.0.0
|
22
|
+
debug: false
|
23
|
+
features:
|
24
|
+
feature_a: true
|
25
|
+
feature_b: false
|
26
|
+
global_setting: true
|
27
|
+
YAML
|
28
|
+
|
29
|
+
# Environment config (JSON)
|
30
|
+
File.write('test/comprehensive/environment/app.json', <<~JSON)
|
31
|
+
{
|
32
|
+
"database": {
|
33
|
+
"host": "staging-db.example.com",
|
34
|
+
"username": "staging_user",
|
35
|
+
"password": "staging_pass"
|
36
|
+
},
|
37
|
+
"app": {
|
38
|
+
"debug": true,
|
39
|
+
"log_level": "debug"
|
40
|
+
},
|
41
|
+
"features": {
|
42
|
+
"feature_b": true,
|
43
|
+
"feature_c": true
|
44
|
+
},
|
45
|
+
"environment_setting": "staging"
|
46
|
+
}
|
47
|
+
JSON
|
48
|
+
|
49
|
+
# Local config (both YAML and JSON to test within-directory merging)
|
50
|
+
File.write('test/comprehensive/local/app.yml', <<~YAML)
|
51
|
+
database:
|
52
|
+
host: localhost
|
53
|
+
port: 3306
|
54
|
+
app:
|
55
|
+
debug: false
|
56
|
+
local_override: true
|
57
|
+
local_yaml_setting: true
|
58
|
+
YAML
|
59
|
+
|
60
|
+
File.write('test/comprehensive/local/app.json', <<~JSON)
|
61
|
+
{
|
62
|
+
"database": {
|
63
|
+
"host": "127.0.0.1",
|
64
|
+
"ssl": true
|
65
|
+
},
|
66
|
+
"app": {
|
67
|
+
"environment": "development"
|
68
|
+
},
|
69
|
+
"local_json_setting": true
|
70
|
+
}
|
71
|
+
JSON
|
72
|
+
end
|
73
|
+
|
74
|
+
def teardown
|
75
|
+
FileUtils.rm_rf('test/comprehensive')
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_comprehensive_multi_directory_multi_format_merging
|
79
|
+
# Create test class with all directories
|
80
|
+
comprehensive_class = Class.new do
|
81
|
+
include ConfigFiles
|
82
|
+
config_directories etc: [
|
83
|
+
'test/comprehensive/global',
|
84
|
+
'test/comprehensive/environment',
|
85
|
+
'test/comprehensive/local',
|
86
|
+
]
|
87
|
+
static_config_files :app
|
88
|
+
end
|
89
|
+
|
90
|
+
config = comprehensive_class.app
|
91
|
+
|
92
|
+
# Test that all unique keys from all files are present
|
93
|
+
assert config.key?(:global_setting), "Should have global-only setting"
|
94
|
+
assert config.key?(:environment_setting), "Should have environment-only setting"
|
95
|
+
assert config.key?(:local_yaml_setting), "Should have local YAML setting"
|
96
|
+
assert config.key?(:local_json_setting), "Should have local JSON setting"
|
97
|
+
|
98
|
+
# Test database configuration deep merging with global taking precedence
|
99
|
+
db = config[:database]
|
100
|
+
|
101
|
+
assert_equal 'global-db.example.com', db[:host], "Host should be from global YAML (highest priority)"
|
102
|
+
assert_equal 5432, db[:port], "Port should be from global YAML"
|
103
|
+
assert_equal 10, db[:pool_size], "Pool size should be from global YAML"
|
104
|
+
assert_equal 'staging_user', db[:username], "Username should be from environment JSON"
|
105
|
+
assert_equal 'staging_pass', db[:password], "Password should be from environment JSON"
|
106
|
+
assert db[:ssl], "SSL should be from local JSON"
|
107
|
+
|
108
|
+
# Test app configuration merging
|
109
|
+
app = config[:app]
|
110
|
+
|
111
|
+
assert_equal 'MyApp', app[:name], "Name should be from global YAML"
|
112
|
+
assert_equal '1.0.0', app[:version], "Version should be from global YAML"
|
113
|
+
refute app[:debug], "Debug should be from global YAML (highest priority)"
|
114
|
+
assert_equal 'debug', app[:log_level], "Log level should be from environment JSON"
|
115
|
+
assert app[:local_override], "Local override should be from local YAML"
|
116
|
+
assert_equal 'development', app[:environment], "Environment should be from local JSON"
|
117
|
+
|
118
|
+
# Test features array merging
|
119
|
+
features = config[:features]
|
120
|
+
|
121
|
+
assert features[:feature_a], "Feature A should be from global YAML"
|
122
|
+
refute features[:feature_b], "Feature B should be from global YAML (highest priority)"
|
123
|
+
assert features[:feature_c], "Feature C should be from environment JSON"
|
124
|
+
|
125
|
+
# Test environment-specific setting
|
126
|
+
assert_equal 'staging', config[:environment_setting], "Environment setting should be preserved"
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_directory_order_matters
|
130
|
+
# Test that directory order affects final values
|
131
|
+
reverse_order_class = Class.new do
|
132
|
+
include ConfigFiles
|
133
|
+
config_directories etc: [
|
134
|
+
'test/comprehensive/local',
|
135
|
+
'test/comprehensive/environment',
|
136
|
+
'test/comprehensive/global',
|
137
|
+
]
|
138
|
+
static_config_files :app
|
139
|
+
end
|
140
|
+
|
141
|
+
config = reverse_order_class.app
|
142
|
+
|
143
|
+
# With reversed order, local should override global (local comes first)
|
144
|
+
assert_equal 'localhost', config[:database][:host], "Local should override global when local comes first"
|
145
|
+
refute config[:app][:debug], "Local debug setting should override others"
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_missing_directories_handled_gracefully
|
149
|
+
# Test with some non-existent directories
|
150
|
+
mixed_existence_class = Class.new do
|
151
|
+
include ConfigFiles
|
152
|
+
config_directories etc: [
|
153
|
+
'test/comprehensive/nonexistent1',
|
154
|
+
'test/comprehensive/global',
|
155
|
+
'test/comprehensive/nonexistent2',
|
156
|
+
'test/comprehensive/local',
|
157
|
+
]
|
158
|
+
static_config_files :app
|
159
|
+
end
|
160
|
+
|
161
|
+
config = mixed_existence_class.app
|
162
|
+
|
163
|
+
# Should still work with existing directories
|
164
|
+
assert config.key?(:global_setting), "Should have global settings"
|
165
|
+
assert config.key?(:local_yaml_setting), "Should have local settings"
|
166
|
+
assert_equal 'global-db.example.com', config[:database][:host], "Should merge from existing directories (global overrides local)"
|
167
|
+
end
|
168
|
+
end
|
data/test/config_files_test.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
4
|
require 'minitest/autorun'
|
3
5
|
require 'config_files'
|
4
6
|
class Dummy
|
5
7
|
include ConfigFiles
|
6
|
-
config_directories :
|
8
|
+
config_directories etc: ['test/etc', 'test/nofiles/etc']
|
7
9
|
static_config_files :dummy, :broken
|
8
10
|
end
|
9
11
|
|
10
12
|
class Dummy2 < Dummy
|
11
|
-
config_directories
|
13
|
+
config_directories config: ['test/etc', 'test/nofiles/etc']
|
12
14
|
class << self
|
13
15
|
def config_key
|
14
|
-
|
16
|
+
'config'
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -21,7 +23,7 @@ class Defaults
|
|
21
23
|
static_config_files :dummy
|
22
24
|
end
|
23
25
|
|
24
|
-
class ConfigFilesTest <
|
26
|
+
class ConfigFilesTest < Minitest::Test
|
25
27
|
def test_config_key
|
26
28
|
assert_equal(:etc, Dummy.config_key)
|
27
29
|
end
|
@@ -43,7 +45,7 @@ class ConfigFilesTest < MiniTest::Test
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def test_empty_for_missing_files
|
46
|
-
|
48
|
+
assert_empty(Dummy.broken)
|
47
49
|
end
|
48
50
|
|
49
51
|
def test_yaml_and_config_override
|
@@ -51,6 +53,6 @@ class ConfigFilesTest < MiniTest::Test
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def test_defaults_are_picked_up_when_no_directories_used
|
54
|
-
|
56
|
+
assert_nil(Defaults.dummy[:config_test])
|
55
57
|
end
|
56
|
-
end
|
58
|
+
end
|
data/test/etc/dummy.conf
CHANGED
@@ -1,2 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# CONF format test file - supports multiple syntaxes
|
2
|
+
config_test=test2
|
3
|
+
only_in_conf: conf_file
|
4
|
+
server.name myserver
|
5
|
+
nested.config.value=nested_value
|
6
|
+
|
7
|
+
[database]
|
8
|
+
host: conf-db.example.com
|
9
|
+
port 5433
|
10
|
+
ssl=true
|
11
|
+
|
12
|
+
[app]
|
13
|
+
name: "CONF App"
|
14
|
+
debug false
|
data/test/etc/dummy.ini
ADDED
data/test/etc/dummy.xml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<config>
|
3
|
+
<global_setting>xml_value</global_setting>
|
4
|
+
<database>
|
5
|
+
<host>xml-db.example.com</host>
|
6
|
+
<port>5432</port>
|
7
|
+
<ssl>true</ssl>
|
8
|
+
</database>
|
9
|
+
<app name="XML App">
|
10
|
+
<debug>false</debug>
|
11
|
+
<version>3.0</version>
|
12
|
+
</app>
|
13
|
+
</config>
|
data/test/etc/dummy.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
config_test: test
|
2
|
+
only_in_yaml: yaml_file
|