Revision 8ebbbecf
Added by Shira Maximov almost 6 years ago
test/controllers/api/v2/fact_values_controller_test.rb | ||
---|---|---|
test "should get index" do
|
||
get :index
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)
|
||
refute_empty fact_values
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {@host.name=>{"kernelversion"=>"2.6.9"}}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
test "should get facts for given host only" do
|
||
get :index, params: { :host_id => @host.name }
|
||
get :index, params: {:host_id => @host.name}
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = FactValue.build_facts_hash(FactValue.where(:host_id => @host.id))
|
||
expected_hash = {@host.name =>{"kernelversion"=>"2.6.9"}, "kernelversion"=>"2.6.9"}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
test "should get facts for given host id" do
|
||
get :index, params: { :host_id => @host.id }
|
||
get :index, params: {:host_id => @host.id}
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = FactValue.build_facts_hash(FactValue.where(:host_id => @host.id))
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {@host.name =>{"kernelversion"=>"2.6.9"}, "kernelversion"=>"2.6.9"}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
... | ... | |
setup_user
|
||
@host.update_attribute(:hostgroup, FactoryBot.create(:hostgroup))
|
||
as_user(users(:one)) do
|
||
get :index, params: { :search => "host.hostgroup = #{@host.hostgroup.name}" }
|
||
get :index, params: {:search => "host.hostgroup = #{@host.hostgroup.name}"}
|
||
end
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = FactValue.build_facts_hash(FactValue.where(:host_id => @host.id))
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {@host.name=>{"kernelversion"=>"2.6.9"}}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
test "should return empty result in case host doesn't exists" do
|
||
get :index, params: {:host_id => 9000}
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
... | ... | |
|
||
def setup_user
|
||
@request.session[:user] = users(:one).id
|
||
users(:one).roles = [Role.default, Role.find_by_name('Viewer')]
|
||
users(:one).roles = [Role.default, Role.find_by_name('Viewer')]
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #20891 - Remove hostname from /hosts/x/facts results