Skip to content

Commit

Permalink
Merge pull request #15639 from zakiva/quota_numeric_values
Browse files Browse the repository at this point in the history
Convert Container quotas to numeric values
  • Loading branch information
blomquisg authored Oct 2, 2017
2 parents 820734d + 22f10df commit 61b9dfb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/models/container_quota_item.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
class ContainerQuotaItem < ApplicationRecord
belongs_to :container_quota

virtual_column :quota_desired_display, :type => :string
virtual_column :quota_enforced_display, :type => :string
virtual_column :quota_observed_display, :type => :string

def quota_desired_display
quota_display(quota_desired)
end

def quota_enforced_display
quota_display(quota_enforced)
end

def quota_observed_display
quota_display(quota_observed)
end

private

def quota_display(quota)
(quota % 1).zero? ? quota.to_i.to_s : quota.to_s
end
end
23 changes: 23 additions & 0 deletions spec/models/container_quota_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe ContainerQuotaItem do
it "converts float to string" do
quota_item = ContainerQuotaItem.new(:resource => 'cpu',
:quota_desired => 4.2,
:quota_enforced => 1.99,
:quota_observed => 0.01)

expect(quota_item).to have_attributes(:quota_desired_display => '4.2',
:quota_enforced_display => '1.99',
:quota_observed_display => '0.01')
end

it "rounds float to int" do
quota_item = ContainerQuotaItem.new(:resource => 'pods',
:quota_desired => 42.0,
:quota_enforced => 1.0,
:quota_observed => 0.0)

expect(quota_item).to have_attributes(:quota_desired_display => '42',
:quota_enforced_display => '1',
:quota_observed_display => '0')
end
end

0 comments on commit 61b9dfb

Please sign in to comment.