Revision 85b0dee0
Added by Michael Moll about 8 years ago
spec/functions/ensure_value_in_string_spec.rb | ||
---|---|---|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||
|
||
it 'should exist' do
|
||
Puppet::Parser::Functions.function('ensure_value_in_string').should == 'function_ensure_value_in_string'
|
||
expect(Puppet::Parser::Functions.function('ensure_value_in_string')).to eq 'function_ensure_value_in_string'
|
||
end
|
||
|
||
it 'should throw an error with bad number of arguments' do
|
||
... | ... | |
end
|
||
|
||
it 'should append values to the end' do
|
||
scope.function_ensure_value_in_string(['one,two', ['three']]).should eq('one,two,three')
|
||
expect(scope.function_ensure_value_in_string(['one,two', ['three']])).to eq 'one,two,three'
|
||
end
|
||
|
||
it 'should append values to the end in same order' do
|
||
scope.function_ensure_value_in_string(['one,two', ['three', 'four']]).should eq('one,two,three,four')
|
||
expect(scope.function_ensure_value_in_string(['one,two', ['three', 'four']])).to eq 'one,two,three,four'
|
||
end
|
||
|
||
it 'should not append values existing in original string' do
|
||
scope.function_ensure_value_in_string(['one,two', ['two', 'three']]).should eq('one,two,three')
|
||
scope.function_ensure_value_in_string(['one,two', ['one', 'three']]).should eq('one,two,three')
|
||
scope.function_ensure_value_in_string(['one,two', ['one', 'two']]).should eq('one,two')
|
||
expect(scope.function_ensure_value_in_string(['one,two', ['two', 'three']])).to eq 'one,two,three'
|
||
expect(scope.function_ensure_value_in_string(['one,two', ['one', 'three']])).to eq 'one,two,three'
|
||
expect(scope.function_ensure_value_in_string(['one,two', ['one', 'two']])).to eq 'one,two'
|
||
end
|
||
|
||
it 'should append even to empty strings' do
|
||
scope.function_ensure_value_in_string(['', ['two', 'three']]).should eq('two,three')
|
||
expect(scope.function_ensure_value_in_string(['', ['two', 'three']])).to eq 'two,three'
|
||
end
|
||
|
||
it 'should append even empty array' do
|
||
scope.function_ensure_value_in_string(['one,two', []]).should eq('one,two')
|
||
expect(scope.function_ensure_value_in_string(['one,two', []])).to eq 'one,two'
|
||
end
|
||
|
||
it 'should not allow using wrong types and undefined values' do
|
||
... | ... | |
end
|
||
|
||
it 'should ignore whitespaces but preserve it' do
|
||
scope.function_ensure_value_in_string(['one, two, three , four', ['five']]).should eq('one, two, three , four,five')
|
||
expect(scope.function_ensure_value_in_string(['one, two, three , four', ['five']])).to eq 'one, two, three , four,five'
|
||
end
|
||
|
||
it 'should accept third argument as a custom separator' do
|
||
scope.function_ensure_value_in_string(['one,two', ['two', 'three'], ', ']).should eq('one,two, three')
|
||
expect(scope.function_ensure_value_in_string(['one,two', ['two', 'three'], ', '])).to eq 'one,two, three'
|
||
end
|
||
end
|
spec/functions/foreman_spec.rb | ||
---|---|---|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||
|
||
it 'should exist' do
|
||
Puppet::Parser::Functions.function('foreman').should == 'function_foreman'
|
||
expect(Puppet::Parser::Functions.function('foreman')).to eq 'function_foreman'
|
||
end
|
||
|
||
it 'should throw an error with no arguments' do
|
||
lambda {
|
||
expect(lambda {
|
||
scope.function_foreman([])
|
||
}.should(raise_error(Puppet::ParseError))
|
||
}). to raise_error(Puppet::ParseError)
|
||
end
|
||
|
||
# TODO: Test functionality of the actual function.
|
spec/functions/smartvar_spec.rb | ||
---|---|---|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||
|
||
it 'should exist' do
|
||
Puppet::Parser::Functions.function('smartvar').should == 'function_smartvar'
|
||
expect(Puppet::Parser::Functions.function('smartvar')).to eq 'function_smartvar'
|
||
end
|
||
|
||
it 'should throw an error with no arguments' do
|
||
lambda {
|
||
expect(lambda {
|
||
scope.function_smartvar([])
|
||
}.should(raise_error(Puppet::ParseError))
|
||
}).to raise_error(Puppet::ParseError)
|
||
end
|
||
|
||
# TODO: Test functionality of the actual function.
|
spec/unit/foreman_external_node_spec.rb | ||
---|---|---|
|
||
req = enc.generate_fact_request('fake.host.fqdn.com',"#{static_fixture_path}/fake.host.fqdn.com.yaml")
|
||
enc.upload_facts('fake.host.fqdn.com',req)
|
||
webstub.should have_been_requested
|
||
expect(webstub).to have_been_requested
|
||
|
||
# test pushing facts async
|
||
http_fact_requests = []
|
||
http_fact_requests << ['fake.host.fqdn.com', req]
|
||
enc.upload_facts_parallel(http_fact_requests)
|
||
|
||
webstub.should have_been_requested.times(2)
|
||
expect(webstub).to have_been_requested.times(2)
|
||
|
||
http_fact_requests << ['fake.host.fqdn.com', req]
|
||
http_fact_requests << ['fake.host.fqdn.com', req]
|
||
enc.upload_facts_parallel(http_fact_requests)
|
||
|
||
webstub.should have_been_requested.times(4)
|
||
expect(webstub).to have_been_requested.times(4)
|
||
end
|
||
|
||
it "should have the correct certname and hostname" do
|
||
# fake2 does not appear in the fixture, so we know it
|
||
# must be preferring the passed-in certname from ARGV
|
||
hash = enc.build_body('fake2.host.fqdn.com',"#{static_fixture_path}/fake.host.fqdn.com.yaml")
|
||
hash['certname'].should eql('fake2.host.fqdn.com')
|
||
hash['name'].should eql('fake.host.fqdn.com')
|
||
hash['facts'].should be_a(Hash)
|
||
expect(hash['certname']).to eql 'fake2.host.fqdn.com'
|
||
expect(hash['name']).to eql 'fake.host.fqdn.com'
|
||
expect(hash['facts']).to be_a(Hash)
|
||
end
|
||
|
||
end
|
spec/unit/foreman_report_processor_spec.rb | ||
---|---|---|
it "should connect to the URL in the processor" do
|
||
stub = stub_request(:post, "http://localhost:3000/api/reports")
|
||
subject.process
|
||
stub.should have_been_requested
|
||
expect(stub).to have_been_requested
|
||
end
|
||
end
|
||
|
||
describe "Puppet Report Format 0" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-format-0.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report.
|
||
should eql(JSON.parse(File.read("#{static_fixture_path}/report-format-0.json")))
|
||
expect(subject.generate_report).to eql(JSON.parse(File.read("#{static_fixture_path}/report-format-0.json")))
|
||
}
|
||
end
|
||
|
||
describe "Puppet Report Format 1" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-format-1.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report.
|
||
should eql(JSON.parse(File.read("#{static_fixture_path}/report-format-1.json")))
|
||
expect(subject.generate_report).to eql(JSON.parse(File.read("#{static_fixture_path}/report-format-1.json")))
|
||
}
|
||
end
|
||
|
||
describe "Puppet Report Format 2" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-format-2.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report.
|
||
should eql(JSON.parse(File.read("#{static_fixture_path}/report-format-2.json")))
|
||
expect(subject.generate_report).to eql(JSON.parse(File.read("#{static_fixture_path}/report-format-2.json")))
|
||
}
|
||
end
|
||
|
||
describe "Puppet Report Format 3" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-format-3.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report.
|
||
should eql(JSON.parse(File.read("#{static_fixture_path}/report-format-3.json")))
|
||
expect(subject.generate_report).to eql(JSON.parse(File.read("#{static_fixture_path}/report-format-3.json")))
|
||
}
|
||
end
|
||
|
||
describe "report should support failure metrics" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-2.6.5-errors.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report['status']['failed'].should eql(3)
|
||
expect(subject.generate_report['status']['failed']).to eql 3
|
||
}
|
||
end
|
||
|
||
describe "report should not support noops" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-2.6.12-noops.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report['status']['pending'].should eql(10)
|
||
expect(subject.generate_report['status']['pending']).to eql 10
|
||
}
|
||
end
|
||
|
||
describe "empty reports have the correct format" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-empty.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report.
|
||
should eql(JSON.parse(File.read("#{static_fixture_path}/report-empty.json")))
|
||
expect(subject.generate_report).to eql(JSON.parse(File.read("#{static_fixture_path}/report-empty.json")))
|
||
}
|
||
end
|
||
|
||
describe "report should not include finished_catalog_run messages" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-2.6.12-noops.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report['logs'].map { |l| l['log']['messages']['message']}.to_s.
|
||
should_not match /Finished catalog run in/
|
||
expect(subject.generate_report['logs'].map { |l| l['log']['messages']['message']}.to_s).not_to match /Finished catalog run in/
|
||
}
|
||
end
|
||
|
||
describe "report should not include debug level messages" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-2.6.2-debug.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report['logs'].map { |l| l['log']['level']}.to_s.
|
||
should_not match /debug/
|
||
expect(subject.generate_report['logs'].map { |l| l['log']['level']}.to_s).not_to match /debug/
|
||
}
|
||
end
|
||
|
||
describe "report should show failure metrics for failed catalog fetches" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-3.5.1-catalog-errors.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report['status']['failed'].should eql(1)
|
||
expect(subject.generate_report['status']['failed']).to eql 1
|
||
}
|
||
end
|
||
|
||
describe "report should properly bypass log processor changes" do
|
||
subject { YAML.load_file("#{static_fixture_path}/report-log-preprocessed.yaml").extend(processor) }
|
||
it {
|
||
subject.generate_report['status']['failed'].should eql(1)
|
||
expect(subject.generate_report['status']['failed']).to eql 1
|
||
}
|
||
end
|
||
|
Also available in: Unified diff
modernize deprecated rspec syntax
Closes GH-415