|
6 | 6 | let(:stdout) { output.stdout } |
7 | 7 | let(:stderr) { output.stderr } |
8 | 8 |
|
9 | | - context "" do |
| 9 | + before do |
| 10 | + WebMock.reset! |
| 11 | + |
| 12 | + config_from_contents(API_CLIENT_CONFIG_CONTENTS) |
| 13 | + stub_client_token_request |
| 14 | + Brightbox.config.reauthenticate |
| 15 | + end |
| 16 | + |
| 17 | + context "without arguments" do |
10 | 18 | let(:argv) { %w[servers activate_console] } |
11 | 19 |
|
12 | 20 | it "does not error" do |
13 | 21 | expect { output }.to_not raise_error |
| 22 | + |
| 23 | + aggregate_failures do |
| 24 | + expect(stderr).to match("ERROR: You must specify servers to activate the console for") |
| 25 | + expect(stdout).to be_empty |
| 26 | + end |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + context "with identifier argument" do |
| 31 | + let(:argv) { %w[servers activate_console srv-lv426] } |
| 32 | + let(:token_expires) { "2025-01-01T01:01:01Z" } |
| 33 | + |
| 34 | + before do |
| 35 | + stub_request(:get, "#{api_url}/1.0/servers/srv-lv426") |
| 36 | + .with(query: hash_including(account_id: "acc-12345")) |
| 37 | + .to_return( |
| 38 | + status: 200, |
| 39 | + body: { |
| 40 | + id: "srv-lv426", |
| 41 | + console_token: nil, |
| 42 | + console_token_expires: nil, |
| 43 | + console_url: nil, |
| 44 | + image: { |
| 45 | + id: "img-12345" |
| 46 | + } |
| 47 | + }.to_json |
| 48 | + ) |
| 49 | + |
| 50 | + stub_request(:get, "#{api_url}/1.0/images") |
| 51 | + .with(query: hash_including(account_id: "acc-12345")) |
| 52 | + .to_return( |
| 53 | + status: 200, |
| 54 | + body: [ |
| 55 | + { |
| 56 | + id: "img-12345" |
| 57 | + } |
| 58 | + ].to_json |
| 59 | + ) |
| 60 | + |
| 61 | + stub_request(:post, "#{api_url}/1.0/servers/srv-lv426/activate_console") |
| 62 | + .with(query: hash_including(account_id: "acc-12345")) |
| 63 | + .to_return( |
| 64 | + status: 202, |
| 65 | + body: { |
| 66 | + id: "srv-lv426", |
| 67 | + console_token: "<test-token-placeholder>", |
| 68 | + console_token_expires: token_expires, |
| 69 | + console_url: "https://console.test.test/srv-lv426", |
| 70 | + image: { |
| 71 | + id: "img-12345" |
| 72 | + } |
| 73 | + }.to_json |
| 74 | + ) |
| 75 | + end |
| 76 | + |
| 77 | + context "when in different time zone" do |
| 78 | + around do |example| |
| 79 | + original_tz = ENV["TZ"] |
| 80 | + example.run |
| 81 | + ENV["TZ"] = original_tz |
| 82 | + end |
| 83 | + |
| 84 | + context "when in UTC" do |
| 85 | + before do |
| 86 | + ENV["TZ"] = "Europe/London" |
| 87 | + end |
| 88 | + |
| 89 | + context "without daylight savings" do |
| 90 | + it "does not error" do |
| 91 | + expect { output }.to_not raise_error |
| 92 | + |
| 93 | + aggregate_failures do |
| 94 | + expect(stderr).to match("") |
| 95 | + expect(stderr).not_to match("ERROR") |
| 96 | + |
| 97 | + expect(stdout).to match("url") |
| 98 | + expect(stdout).to match("https://console.test.test/srv-lv426") |
| 99 | + |
| 100 | + expect(stdout).to match("token") |
| 101 | + expect(stdout).to match("<test-token-placeholder>") |
| 102 | + |
| 103 | + expect(stdout).to match("expires") |
| 104 | + expect(stdout).to match("2025-01-01T01:01") |
| 105 | + end |
| 106 | + end |
| 107 | + end |
| 108 | + |
| 109 | + context "with daylight savings (BST)" do |
| 110 | + let(:token_expires) { "2025-07-01T01:01:01Z" } |
| 111 | + |
| 112 | + it "does not error" do |
| 113 | + expect { output }.to_not raise_error |
| 114 | + |
| 115 | + aggregate_failures do |
| 116 | + expect(stderr).to match("") |
| 117 | + expect(stderr).not_to match("ERROR") |
| 118 | + |
| 119 | + expect(stdout).to match("url") |
| 120 | + expect(stdout).to match("https://console.test.test/srv-lv426") |
| 121 | + |
| 122 | + expect(stdout).to match("token") |
| 123 | + expect(stdout).to match("<test-token-placeholder>") |
| 124 | + |
| 125 | + expect(stdout).to match("expires") |
| 126 | + expect(stdout).to match("2025-07-01T02:01") |
| 127 | + end |
| 128 | + end |
| 129 | + end |
| 130 | + end |
| 131 | + |
| 132 | + context "when in EST" do |
| 133 | + around do |example| |
| 134 | + ENV["TZ"] = "America/New_York" |
| 135 | + example.run |
| 136 | + end |
| 137 | + |
| 138 | + it "does not error" do |
| 139 | + expect { output }.to_not raise_error |
| 140 | + |
| 141 | + aggregate_failures do |
| 142 | + expect(stderr).to match("") |
| 143 | + expect(stderr).not_to match("ERROR") |
| 144 | + |
| 145 | + expect(stdout).to match("url") |
| 146 | + expect(stdout).to match("https://console.test.test/srv-lv426") |
| 147 | + |
| 148 | + expect(stdout).to match("token") |
| 149 | + expect(stdout).to match("<test-token-placeholder>") |
| 150 | + |
| 151 | + expect(stdout).to match("expires") |
| 152 | + expect(stdout).to match("2024-12-31T20:01") |
| 153 | + end |
| 154 | + end |
| 155 | + end |
14 | 156 | end |
15 | 157 | end |
16 | 158 | end |
|
0 commit comments