Revision 459e0feb
Added by Paul Kelly almost 14 years ago
- ID 459e0feb5c15f2ff8c175e2d46e372b4d83c6a4c
test/functional/reports_controller_test.rb | ||
---|---|---|
require 'test_helper'
|
||
|
||
class ReportsControllerTest < ActionController::TestCase
|
||
def setup
|
||
@host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
|
||
:domain => Domain.find_or_create_by_name("company.com"),
|
||
:operatingsystem => Operatingsystem.create(:name => "linux", :major => 389),
|
||
:architecture => Architecture.find_or_create_by_name("i386"),
|
||
:environment => Environment.find_or_create_by_name("envy"),
|
||
:disk => "empty partition"
|
||
def test_index
|
||
get :index
|
||
assert_response :success
|
||
assert_not_nil assigns('reports')
|
||
assert_template 'index'
|
||
end
|
||
|
||
test "ActiveScaffold should look for Report model" do
|
||
assert_not_nil ReportsController.active_scaffold_config
|
||
assert ReportsController.active_scaffold_config.model == Report
|
||
def test_show
|
||
create_a_puppet_transaction_report
|
||
Report.last.update_attribute :log, @log
|
||
get :show, :id => Report.last.id
|
||
assert_template 'show'
|
||
end
|
||
|
||
test "should get index" do
|
||
get :index, {}, set_session_user
|
||
assert_response :success
|
||
assert_not_nil assigns(:records)
|
||
def test_create_invalid
|
||
create_a_puppet_transaction_report
|
||
@log.host = nil
|
||
post :create, :report => @log.to_yaml
|
||
assert_response :error
|
||
end
|
||
|
||
# couldn't test create, cause uses Report.import which needs yaml, but create passes it hash
|
||
|
||
# test "should create report" do
|
||
# create_a_puppet_transaction_report
|
||
|
||
# assert_difference('Report.count') do
|
||
# post :create, :report => { :commit => "Create", :record => { :host => h, :log => p, :reported_at => d } }
|
||
# end
|
||
def test_create_valid
|
||
create_a_puppet_transaction_report
|
||
post :create, :report => @log.to_yaml
|
||
assert_response :success
|
||
end
|
||
|
||
# assert_redirected_to reports_path
|
||
# end
|
||
def test_destroy
|
||
report = Report.first
|
||
delete :destroy, :id => report
|
||
assert_redirected_to reports_url
|
||
assert !Report.exists?(report.id)
|
||
end
|
||
|
||
test "should show report" do
|
||
create_a_report
|
||
... | ... | |
def create_a_report
|
||
create_a_puppet_transaction_report
|
||
|
||
@report = Report.create :host => @host, :log => @log, :reported_at => Time.new
|
||
@report = Report.create :host => hosts(:one), :log => @log, :reported_at => Time.new
|
||
end
|
||
|
||
def create_a_puppet_transaction_report
|
||
@log = Puppet::Transaction::Report.new
|
||
@log.time = Time.now.utc
|
||
@log.metrics["time"] = Puppet::Util::Metric.new(:info)
|
||
@log.metrics["time"].values = [[:user, "User", 0.0135350227355957], [:total, "Total", 16.5941832065582], [:service, "Service", 1.46307373046875], [:package, "Package", 0.608669757843018], [:file, "File", 5.92631697654724], [:ssh_authorized_key, "Ssh authorized key", 0.00355410575866699], [:group, "Group", 0.00506687164306641], [:schedule, "Schedule", 0.00130486488342285], [:cron, "Cron", 0.0011448860168457], [:config_retrieval, "Config retrieval", 7.56520414352417], [:exec, "Exec", 1.00578165054321], [:filebucket, "Filebucket", 0.000531196594238281]]
|
||
@log.metrics["time"].values = [[:user, "User", 0.0135350227355957], [:total, "Total", 16.5941832065582], [:service, "Service", 1.46307373046875], [:package, "Package", 0.608669757843018], [:file, "File", 5.92631697654724], [:ssh_authorized_key, "Ssh authorize
|
||
d key", 0.00355410575866699], [:group, "Group", 0.00506687164306641], [:schedule, "Schedule", 0.00130486488342285], [:cron, "Cron", 0.0011448860168457], [:config_retrieval, "Config retrieval", 7.56520414352417], [:exec, "Exec", 1.00578165054321], [:filebucket, "F
|
||
ilebucket", 0.000531196594238281]]
|
||
@log.metrics["resources"] = Puppet::Util::Metric.new(:info)
|
||
@log.metrics["resources"].values = [[:total, "Total", 1273], [:applied, "Applied", 1], [:restarted, "Restarted", 0], [:skipped, "Skipped", 0], [:out_of_sync, "Out of sync", 1], [:scheduled, "Scheduled", 786], [:failed_restarts, "Failed restarts", 0], [:failed, "Failed", 0]]
|
||
l = Puppet::Util::Log.new(:level => "notice", :message => :foo, :tags => %w{foo bar})
|
||
@log.logs << l
|
||
@log.save
|
||
end
|
||
end
|
||
|
Also available in: Unified diff
Fixes #249 - Remove AS from reports
Added a searchbar for hostname, reporting period and the type of report.