Project

General

Profile

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

foreman-docker / test / units / docker_registry_test.rb @ f02a9ce2

1
require 'test_plugin_helper'
2

    
3
class DockerRegistryTest < ActiveSupport::TestCase
4
  subject { FactoryGirl.create(:docker_registry) }
5

    
6
  test 'used_location_ids should return correct location ids' do
7
    location = FactoryGirl.build(:location)
8
    r = as_admin do
9
      FactoryGirl.create(:docker_registry, :locations => ([location]))
10
    end
11
    assert r.used_location_ids.include?(location.id)
12
  end
13

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

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

    
29
  should validate_presence_of(:name)
30
  should validate_presence_of(:url)
31
  should validate_uniqueness_of(:name)
32
  should validate_uniqueness_of(:url)
33

    
34
  describe 'registry validation' do
35
    setup do
36
      subject.unstub(:attempt_login)
37
    end
38

    
39
    test 'is valid when the api is ok' do
40
      subject.api.expects(:ok?).returns(true)
41
      assert subject.valid?
42
    end
43

    
44
    test 'is not valid when api is not ok' do
45
      subject.api.expects(:ok?)
46
        .raises(Docker::Error::AuthenticationError)
47
      refute subject.valid?
48
    end
49
  end
50

    
51
  describe '#api' do
52
    let(:api) { subject.api }
53

    
54
    test 'returns a RegistryApi instance' do
55
      assert_kind_of Service::RegistryApi, api
56
    end
57
  end
58

    
59
  describe '#api' do
60
    let(:api) { subject.api }
61

    
62
    test 'returns a RegistryApi instance' do
63
      assert_kind_of Service::RegistryApi, api
64
    end
65
  end
66
end