1 |
ada932ab
|
Dmitri Dolguikh
|
require 'test_plugin_helper'
|
2 |
|
|
|
3 |
|
|
class DockerRegistryTest < ActiveSupport::TestCase
|
4 |
f0062004
|
Sebastian Gräßl
|
subject { FactoryGirl.create(:docker_registry) }
|
5 |
|
|
|
6 |
30891c0a
|
Daniel Lobato
|
test 'used_location_ids should return correct location ids' do
|
7 |
ada932ab
|
Dmitri Dolguikh
|
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 |
30891c0a
|
Daniel Lobato
|
test 'used_organization_ids should return correct organization ids' do
|
15 |
ada932ab
|
Dmitri Dolguikh
|
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 |
64f6a1f2
|
Dmitri Dolguikh
|
|
22 |
|
|
test 'password is stored encrypted' do
|
23 |
a79b7ae3
|
Daniel Lobato
|
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 |
fe3c8eff
|
Daniel Lobato
|
assert registry.is_decryptable?(registry.password_in_db)
|
27 |
|
|
end
|
28 |
|
|
|
29 |
9ea40591
|
Daniel Lobato
|
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 |
f0062004
|
Sebastian Gräßl
|
describe 'registry validation' do
|
35 |
9ea40591
|
Daniel Lobato
|
setup do
|
36 |
f0062004
|
Sebastian Gräßl
|
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 |
9ea40591
|
Daniel Lobato
|
end
|
43 |
|
|
|
44 |
f0062004
|
Sebastian Gräßl
|
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 |
9ea40591
|
Daniel Lobato
|
end
|
49 |
f0062004
|
Sebastian Gräßl
|
end
|
50 |
|
|
|
51 |
|
|
describe '#api' do
|
52 |
|
|
let(:api) { subject.api }
|
53 |
9ea40591
|
Daniel Lobato
|
|
54 |
f0062004
|
Sebastian Gräßl
|
test 'returns a RegistryApi instance' do
|
55 |
|
|
assert_kind_of Service::RegistryApi, api
|
56 |
394e9883
|
Daniel Lobato
|
end
|
57 |
64f6a1f2
|
Dmitri Dolguikh
|
end
|
58 |
f02a9ce2
|
Sebastian Gräßl
|
|
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 |
ada932ab
|
Dmitri Dolguikh
|
end |