Project

General

Profile

Download (1.54 KB) Statistics
| Branch: | Tag: | Revision:

foreman-docker / test / units / docker_registry_test.rb @ 9ea40591

1
require 'test_plugin_helper'
2

    
3
class DockerRegistryTest < ActiveSupport::TestCase
4
  test 'used_location_ids should return correct location ids' do
5
    location = FactoryGirl.build(:location)
6
    r = as_admin do
7
      FactoryGirl.create(:docker_registry, :locations => ([location]))
8
    end
9
    assert r.used_location_ids.include?(location.id)
10
  end
11

    
12
  test 'used_organization_ids should return correct organization ids' do
13
    organization = FactoryGirl.build(:organization)
14
    r = as_admin do
15
      FactoryGirl.create(:docker_registry, :organizations => ([organization]))
16
    end
17
    assert r.used_organization_ids.include?(organization.id)
18
  end
19

    
20
  test 'password is stored encrypted' do
21
    registry = as_admin { FactoryGirl.build(:docker_registry) }
22
    registry.password = 'encrypted-whatever'
23
    DockerRegistry.any_instance.expects(:encryption_key).at_least_once.returns('fakeencryptionkey')
24
    assert registry.is_decryptable?(registry.password_in_db)
25
  end
26

    
27
  should validate_presence_of(:name)
28
  should validate_presence_of(:url)
29
  should validate_uniqueness_of(:name)
30
  should validate_uniqueness_of(:url)
31

    
32
  context 'attempt to login' do
33
    setup do
34
      @registry = FactoryGirl.build(:docker_registry)
35
      @registry.unstub(:attempt_login)
36
    end
37

    
38
    test 'before creating a registry' do
39
      ::Docker.expects(:authenticate!)
40
      assert @registry.valid?
41
    end
42

    
43
    test 'display errors in case authentication failed' do
44
      ::Docker.expects(:authenticate!).
45
        raises(Docker::Error::AuthenticationError)
46
      refute @registry.valid?
47
    end
48
  end
49
end