Revision 00bd7de4
Added by Michael Moll about 5 years ago
test/functionals/image_search_controller_test.rb | ||
---|---|---|
12 | 12 |
|
13 | 13 |
setup do |
14 | 14 |
Service::RegistryApi.stubs(:docker_hub).returns(docker_hub) |
15 |
ComputeResource::ActiveRecord_Relation.any_instance
|
|
15 |
ComputeResource.const_get(:ActiveRecord_Relation).any_instance
|
|
16 | 16 |
.stubs(:find).returns(compute_resource) |
17 |
DockerRegistry::ActiveRecord_Relation.any_instance
|
|
17 |
DockerRegistry.const_get(:ActiveRecord_Relation).any_instance
|
|
18 | 18 |
.stubs(:find).returns(registry) |
19 | 19 |
end |
20 | 20 |
|
... | ... | |
30 | 30 |
tags_enabled = ['true', 'false'].sample |
31 | 31 |
image_search_service.expects(:search).with({ term: term, tags: tags_enabled }) |
32 | 32 |
.returns([]) |
33 |
xhr :get, :search_repository, |
|
34 |
{ registry: search_types.sample, search: term, tags: tags_enabled, |
|
35 |
id: compute_resource }, set_session_user |
|
33 |
get :search_repository, |
|
34 |
params: { registry: search_types.sample, search: term, tags: tags_enabled, |
|
35 |
id: compute_resource }, |
|
36 |
session: set_session_user, |
|
37 |
xhr: true |
|
36 | 38 |
end |
37 | 39 |
|
38 | 40 |
test 'returns an array of { label:, value: } hashes' do |
39 | 41 |
image_search_service.expects(:search).with({ term: term, tags: 'true' }) |
40 | 42 |
.returns(tags) |
41 |
xhr :get, :search_repository, |
|
42 |
{ registry: search_types.sample, search: term, tags: 'true', |
|
43 |
id: compute_resource }, set_session_user |
|
43 |
get :search_repository, |
|
44 |
params: { registry: search_types.sample, search: term, tags: 'true', |
|
45 |
id: compute_resource }, |
|
46 |
session: set_session_user, |
|
47 |
xhr: true |
|
48 |
|
|
44 | 49 |
assert_equal tags.first, JSON.parse(response.body).first['value'] |
45 | 50 |
end |
46 | 51 |
|
... | ... | |
48 | 53 |
image_search_service.expects(:search) |
49 | 54 |
.with({ term: term, tags: 'false' }) |
50 | 55 |
.returns([{ 'name' => term }]) |
51 |
xhr :get, :search_repository,
|
|
56 |
get :search_repository, params:
|
|
52 | 57 |
{ registry: search_types.sample, search: term, |
53 |
id: compute_resource, format: :html}, set_session_user |
|
58 |
id: compute_resource, format: :html }, |
|
59 |
session: set_session_user, xhr: true |
|
60 |
|
|
54 | 61 |
assert response.body.include?(term) |
55 | 62 |
end |
56 | 63 |
|
... | ... | |
58 | 65 |
test "search_repository catch exceptions on network errors like #{error}" do |
59 | 66 |
image_search_service.expects(:search) |
60 | 67 |
.raises(error) |
61 |
xhr :get, :search_repository, |
|
62 |
{ registry: search_types.sample, search: term, id: compute_resource }, set_session_user |
|
68 |
get :search_repository, |
|
69 |
params: { registry: search_types.sample, search: term, id: compute_resource }, |
|
70 |
session: set_session_user, xhr: true |
|
63 | 71 |
|
64 | 72 |
assert_response :error |
65 | 73 |
assert response.body.include?('An error occured during repository search:') |
... | ... | |
76 | 84 |
"star_count" => 0 |
77 | 85 |
}] |
78 | 86 |
image_search_service.expects(:search).returns(expected) |
79 |
xhr :get, :search_repository, |
|
80 |
{ registry: search_types.sample, search: 'centos', id: compute_resource, format: :html }, set_session_user |
|
87 |
get :search_repository, |
|
88 |
params: { registry: search_types.sample, search: 'centos', id: compute_resource, format: :html }, |
|
89 |
session: set_session_user, |
|
90 |
xhr: true |
|
91 |
|
|
81 | 92 |
assert_response :success |
82 | 93 |
refute response.body.include?(repo_full_name) |
83 | 94 |
assert response.body.include?(repository) |
... | ... | |
94 | 105 |
"star_count" => 0 |
95 | 106 |
}] |
96 | 107 |
image_search_service.expects(:search).returns(expected) |
97 |
xhr :get, :search_repository, |
|
98 |
{ registry: search_types.sample, search: term, id: compute_resource, format: :html }, set_session_user |
|
108 |
get :search_repository, |
|
109 |
params: { registry: search_types.sample, search: term, id: compute_resource, format: :html }, |
|
110 |
session: set_session_user, |
|
111 |
xhr: true |
|
112 |
|
|
99 | 113 |
assert_response :success |
100 | 114 |
assert response.body.include?(repo_full_name) |
101 | 115 |
assert response.body.include?(repository) |
... | ... | |
111 | 125 |
.returns([OpenStruct.new(info: { 'RepoTags' => [term] })]) |
112 | 126 |
docker_hub.expects(:search).returns({}) |
113 | 127 |
|
114 |
xhr :get, :search_repository, |
|
115 |
{ registry: search_type, search: term, |
|
116 |
id: compute_resource }, set_session_user |
|
128 |
get :search_repository, |
|
129 |
params: { registry: search_type, search: term, |
|
130 |
id: compute_resource }, |
|
131 |
session: set_session_user, |
|
132 |
xhr: true |
|
117 | 133 |
end |
118 | 134 |
end |
119 | 135 |
|
... | ... | |
126 | 142 |
registry.api.expects(:search).with(docker_image) |
127 | 143 |
.returns({}) |
128 | 144 |
|
129 |
xhr :get, :search_repository, |
|
130 |
{ registry: search_type, registry_id: registry, |
|
131 |
search: term, id: compute_resource }, set_session_user |
|
145 |
get :search_repository, |
|
146 |
params: { registry: search_type, registry_id: registry, |
|
147 |
search: term, id: compute_resource }, |
|
148 |
session: set_session_user, |
|
149 |
xhr: true |
|
132 | 150 |
end |
133 | 151 |
end |
134 | 152 |
end |
... | ... | |
147 | 165 |
.returns(tags) |
148 | 166 |
docker_hub.expects(:tags).returns([]) |
149 | 167 |
|
150 |
xhr :get, :search_repository, |
|
151 |
{ registry: search_type, search: term, tags: 'true', |
|
152 |
id: compute_resource }, set_session_user |
|
168 |
get :search_repository, |
|
169 |
params: { registry: search_type, search: term, |
|
170 |
tags: 'true', id: compute_resource }, |
|
171 |
session: set_session_user, |
|
172 |
xhr: true |
|
153 | 173 |
end |
154 | 174 |
end |
155 | 175 |
|
... | ... | |
162 | 182 |
registry.api.expects(:tags).with(docker_image, tag_fragment) |
163 | 183 |
.returns([]) |
164 | 184 |
|
165 |
xhr :get, :search_repository, |
|
166 |
{ registry: search_type, registry_id: registry, tags: 'true', |
|
167 |
search: term, id: compute_resource }, set_session_user |
|
185 |
get :search_repository, |
|
186 |
params: { registry: search_type, registry_id: registry, tags: 'true', |
|
187 |
search: term, id: compute_resource }, |
|
188 |
session: set_session_user, |
|
189 |
xhr: true |
|
168 | 190 |
end |
169 | 191 |
end |
170 | 192 |
end |
Also available in: Unified diff
More Rails 5.1 changes