Best Minitest_ruby code snippet using MyModule.teardown
pcore_resource_types_should_have_precedence_over_ruby.rb
Source:pcore_resource_types_should_have_precedence_over_ruby.rb
1test_name 'C98097 - generated pcore resource types should be loaded instead of ruby for custom types' do2tag 'audit:high',3 'audit:integration',4 'audit:refactor', # use `mk_tmp_environment_with_teardown` helper to build environment5 'server'6 environment = 'production'7 step 'setup - install module with custom ruby resource type' do8 #{{{9 testdir = master.tmpdir('c98097')10 codedir = "#{testdir}/codedir"11 site_manifest_content =<<EOM12node default {13 notice(mycustomtype{"foobar":})14}15EOM16 custom_type_content =<<EOM17Puppet::Type.newtype(:mycustomtype) do18 @doc = "Create a new mycustomtype thing."19 newparam(:name, :namevar => true) do20 desc "Name of mycustomtype instance"21 $stderr.puts "this indicates that we are running ruby code and should not be seen when running generated pcore resource"22 end23 def refresh24 end25end26EOM27 apply_manifest_on(master, <<MANIFEST, :catch_failures => true)28File {29 ensure => directory,30 mode => "0755",31}32file {[33 '#{codedir}',34 '#{codedir}/environments',35 '#{codedir}/environments/#{environment}',36 '#{codedir}/environments/#{environment}/manifests',37 '#{codedir}/environments/#{environment}/modules',38 '#{codedir}/environments/#{environment}/modules/mymodule',39 '#{codedir}/environments/#{environment}/modules/mymodule/manifests',40 '#{codedir}/environments/#{environment}/modules/mymodule/lib',41 '#{codedir}/environments/#{environment}/modules/mymodule/lib/puppet',42 '#{codedir}/environments/#{environment}/modules/mymodule/lib/puppet/type'43 ]:44}45file { '#{codedir}/environments/#{environment}/manifests/site.pp':46 ensure => file,47 content => '#{site_manifest_content}',48}49file { '#{codedir}/environments/#{environment}/modules/mymodule/lib/puppet/type/mycustomtype.rb':50 ensure => file,51 content => '#{custom_type_content}',52}53MANIFEST54 conf_opts = {55 'main' => {56 'environmentpath' => "#{codedir}/environments"57 }58 }59 backup_file = backup_the_file(master, puppet_config(master, 'confdir', section: 'master'), testdir, 'puppet.conf')60 lay_down_new_puppet_conf master, conf_opts, testdir61 teardown do62 restore_puppet_conf_from_backup( master, backup_file )63 # See PUP-699564 on(master, "rm -f #{puppet_config(master, 'yamldir', section: 'master')}/node/*.yaml")65 agents.each do |agent|66 on(agent, puppet('config print lastrunfile')) do |command_result|67 agent.rm_rf(command_result.stdout)68 end69 end70 end71 #}}}72 catalog_results = {}73 catalog_results[master.hostname] = { 'ruby_cat' => '', 'pcore_cat' => '' }74 step 'compile catalog using ruby resource' do75 on master, puppet('catalog', 'find', master.hostname) do |result|...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!