-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathserver_usage_spec.rb
More file actions
70 lines (57 loc) · 2.41 KB
/
server_usage_spec.rb
File metadata and controls
70 lines (57 loc) · 2.41 KB
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
require "spec_helper"
describe "server_usage", :mock_only do
let!(:client) { create_client }
let!(:account) { create_account(client: client, account: { owner: create_user(client: client)}) }
let!(:provider) { create_provider(account: account) }
let!(:environment) { create_environment(account: account, name: SecureRandom.hex(10)) }
before(:each) do
now = Time.now
billing_month = now.strftime("%Y-%m")
month_beginning = DateTime.new(now.year, now.month, 1)
client.find(:server_usages, account.id).merge!(
"2014-05" => [
{
"start_at" => "2014-05-01T00:00:00+00:00",
"end_at" => "2014-05-31T23:59:59+00:00",
"report_time" => Time.now.iso8601,
"flavor" => "m1.large",
"dedicated" => false,
"location" => "us-east-1d",
"environment" => "https://api.engineyard.com/environments/#{environment.id}",
"provider" => "https://api.engineyard.com/providers/#{provider.id}",
},
],
billing_month => [
{
"start_at" => month_beginning.iso8601,
"end_at" => nil, # still running
"report_time" => now.iso8601,
"flavor" => "m1.large",
"dedicated" => false,
"location" => "correct-location",
"environment" => "https://api.engineyard.com/environments/#{environment.id}",
"provider" => "https://api.engineyard.com/providers/#{provider.id}",
},
],
)
end
it "can fetch usage for an account and billing_month" do
server_usages = client.server_usages.all(account_id: account.id, billing_month: "2014-05")
expect(server_usages.size).to eq(1)
server_usage = server_usages.first
expect(server_usage.start_at).not_to be_nil
expect(server_usage.end_at).not_to be_nil
expect(server_usage.report_time).not_to be_nil
expect(server_usage.flavor).to eq("m1.large")
expect(server_usage.location).to eq("us-east-1d")
expect(server_usage.dedicated).to be false
expect(server_usage.environment).to eq(environment)
expect(server_usage.provider).to eq(provider)
end
it "defaults to the current billing_month" do
server_usages = client.server_usages.all(account_id: account.id)
expect(server_usages.size).to eq(1)
server_usage = server_usages.first
expect(server_usage.location).to eq("correct-location")
end
end