|
13 | 13 | require 'tempfile' |
14 | 14 |
|
15 | 15 | describe SoftLayer::Config do |
| 16 | + |
| 17 | + before :each do |
| 18 | + ENV.delete("SL_USERNAME") |
| 19 | + ENV.delete("SL_API_KEY") |
| 20 | + ENV.delete("SL_API_USER_AGENT") |
| 21 | + ENV.delete("SL_PROFILE") |
| 22 | + end |
| 23 | + |
16 | 24 | it "retrieves config information from environment variables" do |
17 | 25 | ENV.store("SL_USERNAME", "PoohBear") |
18 | 26 | ENV.store("SL_API_KEY", "DEADBEEFBADF00D") |
|
41 | 49 | expect(settings[:timeout]).to eq(40) |
42 | 50 | end |
43 | 51 |
|
| 52 | + it "retrieves the properties from a custom file using a custom profile" do |
| 53 | + ENV.store("SL_PROFILE", "softlayer_qa") |
| 54 | + file = Tempfile.new('properties_from_file') |
| 55 | + begin |
| 56 | + file.puts("[softlayer_dev]") |
| 57 | + file.puts("username = PoohBear") |
| 58 | + file.puts("api_key = DEADBEEFBADF00D") |
| 59 | + file.puts("timeout = 40") |
| 60 | + file.puts("\n") |
| 61 | + file.puts("[softlayer_qa]") |
| 62 | + file.puts("username = Piglet") |
| 63 | + file.puts("api_key = MOOOOOOOO") |
| 64 | + file.puts("timeout = 60") |
| 65 | + file.puts("\n") |
| 66 | + file.puts("[softlayer_prod]") |
| 67 | + file.puts("username = Eeyore") |
| 68 | + file.puts("api_key = VEG_ALL_THE_WAY") |
| 69 | + file.puts("timeout = 80") |
| 70 | + file.close |
| 71 | + |
| 72 | + settings = SoftLayer::Config.file_settings(file.path) |
| 73 | + ensure |
| 74 | + file.close |
| 75 | + file.unlink |
| 76 | + end |
| 77 | + |
| 78 | + expect(settings[:username]).to eq("Piglet") |
| 79 | + expect(settings[:api_key]).to eq("MOOOOOOOO") |
| 80 | + expect(settings[:timeout]).to eq(60) |
| 81 | + end |
44 | 82 |
|
45 | 83 | it "retrieves the timeout field as an integer when presented as a string" do |
46 | 84 | file = Tempfile.new('config_test') |
|
0 commit comments