Project

General

Profile

Download (992 Bytes) Statistics
| Branch: | Tag: | Revision:

foreman_docker / test / units / utility_service_test.rb @ 27a7d2c4

1
require 'test_plugin_helper'
2

    
3
class UtilitiesServiceTest < ActiveSupport::TestCase
4
  test "parses empty and nil input as 0" do
5
    assert_equal ForemanDocker::Utility.parse_memory(""), 0
6
    assert_equal ForemanDocker::Utility.parse_memory(nil), 0
7
    assert_equal ForemanDocker::Utility.parse_memory("        "), 0
8
  end
9

    
10
  test "correctly parses a number without unit" do
11
    assert_equal ForemanDocker::Utility.parse_memory("1234"), 1_234
12
    assert_equal ForemanDocker::Utility.parse_memory("  123 4     "), 1_234
13
  end
14

    
15
  test "correctl parses number with unit" do
16
    assert_equal ForemanDocker::Utility.parse_memory("10K"), 10_240
17
    assert_equal ForemanDocker::Utility.parse_memory("20k"), 20_480
18
    assert_equal ForemanDocker::Utility.parse_memory("5 G"), 5_368_709_120
19
    assert_equal ForemanDocker::Utility.parse_memory("10m"), 10_485_760
20
  end
21

    
22
  test "raises on bad input" do
23
    assert_raise RuntimeError do
24
      ForemanDocker::Utility.parse_memory("26V")
25
    end
26
  end
27
end