Skip to content

Commit d69085c

Browse files
committed
Specs for console expiry time zone
This was ticketed as an issue and fixed without tests. The ticket was not set as started so picked up again, tested and found to be done.
1 parent aca56a1 commit d69085c

2 files changed

Lines changed: 148 additions & 2 deletions

File tree

lib/brightbox-cli/commands/servers/activate_console.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ module Brightbox
2323
uri.query = "password=#{r['console_token']}"
2424

2525
expires = Time.parse(r["console_token_expires"])
26-
consoles << { :url => uri.to_s, :token => r["console_token"], :expires => expires.localtime.to_s }
26+
consoles << {
27+
url: uri.to_s,
28+
token: r["console_token"],
29+
expires: expires.localtime.to_s
30+
}
2731
end
2832

2933
render_table(consoles, global_options.merge(:fields => %i[url token expires], :resize => false))

spec/commands/servers/activate_console_spec.rb

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,153 @@
66
let(:stdout) { output.stdout }
77
let(:stderr) { output.stderr }
88

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
1018
let(:argv) { %w[servers activate_console] }
1119

1220
it "does not error" do
1321
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
14156
end
15157
end
16158
end

0 commit comments

Comments
 (0)