voxpupuli / onceover

Your gateway drug to automated infrastructure testing with Puppet
Apache License 2.0
142 stars 45 forks source link

undefined method `on_supported_os` #175

Closed cdenneen closed 5 years ago

cdenneen commented 6 years ago

Support for tests using rspec-puppet-facts and facterdb. I currently have tests that are using this hash and when running spec via onceover it complains because it doesn't know what this method. I'm currently trying to transition from control repo that's essentially configured like pdk would with slight modifications because of being a control repository to testing with onceover and this is a blocker currently. Maybe with onceover supporting pdk this might work. Is there WIP on that task?

dylanratcliffe commented 6 years ago

Hey @cdenneen, the on_supported_os method uses metadata.json to determine what OSes are relevant to that particular module. As a controlrepo doesn't have a metadata.json, this won't work. There are a few reasons why I have opted not to do FacterDB support yet (However I still might, I would certainly accept a PR on it) which I will detail below:

I do work pretty closely with the PDK team and integration is coming, but it's not the next cab off the rank. If you have a more specific requirement that the above doesn't address please let me know though.

cdenneen commented 6 years ago

@dylanratcliffe on_supported_os defaults to using metadata.json if function isn't passed parameter.

require 'spec_helper'

describe 'role::sensu_server_enterprise' do
  on_supported_os(supported_os: [
                    {
                      'operatingsystem' => 'CentOS',
                      'operatingsystemrelease' => %w[
                        6
                        7
                      ],
                    },
                  ]).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge(puppetversion: Puppet.version,
                    vm_type: 'rspec',
                    sshdsakey: 'sshdsakey',
                    role: 'sensu_server_enterprise')
      end

By specifying this at the top of a role I can specify which OS's linux & windows... just windows... just linux... which flavors or versions of each in the supported_os Array.

I still am able to add custom facts here or could in some others ways as well but it avoids me having to generate puppet facts on every OS I need to test on (this is already done for me in facterdb)

dylanratcliffe commented 6 years ago

Yeah it would be possible, and if you wanted to write spec tests like that you totally could, onceover would handle pulling down modules etc. and then it would run any tests it finds in spec/{classes,defines,unit,functions,hosts,integration,types} as per the readme. I personally can't see many scenarios where it would be easier to write all these tests from scratch using this method than it would be to just run puppet facts on a few boxes but I guess if you had a very large number of supported OSes or permutations of custom facts that need to be tested it might be worth doing. Either way onceover supports this right now, here's an example of me running a very simple test alongside default onceover ones: https://github.com/dylanratcliffe/puppet_controlrepo/blob/production/spec/classes/test_spec.rb and there are also examples in the readme which show how to interact with Onceover's config etc. in native Ruby

cdenneen commented 6 years ago

Is there a way to have onceover custom add rspec-puppet-facts? On Thu, Jul 12, 2018 at 10:14 PM Dylan notifications@github.com wrote:

Yeah it would be possible, and if you wanted to write spec tests like that you totally could, onceover would handle pulling down modules etc. and then it would run any tests it finds in spec/{classes,defines,unit,functions,hosts,integration,types} as per the readme https://github.com/dylanratcliffe/onceover#accessing-onceover-in-a-traditional-rspec-test. I personally can't see many scenarios where it would be easier to write all these tests from scratch using this method than it would be to just run puppet facts on a few boxes but I guess if you had a very large number of supported OSes or permutations of custom facts that need to be tested it might be worth doing. Either way onceover supports this right now, here's an example of me running a very simple test alongside default onceover ones: https://github.com/dylanratcliffe/puppet_controlrepo/blob/production/spec/classes/test_spec.rb and there are also examples in the readme which show how to interact with Onceover's config etc. in native Ruby

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dylanratcliffe/onceover/issues/175#issuecomment-404704737, or mute the thread https://github.com/notifications/unsubscribe-auth/AAr84b1cAcszC7Jrwssg5aChnOBm8DQIks5uGAKdgaJpZM4VJ60G .

dylanratcliffe commented 6 years ago

What do you mean?

cdenneen commented 6 years ago

I mean add rspec-puppet-facts to onceover config so when it creates Gemfile it adds any custom gems like this one. On Thu, Jul 19, 2018 at 2:19 AM Dylan notifications@github.com wrote:

What do you mean?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dylanratcliffe/onceover/issues/175#issuecomment-406167075, or mute the thread https://github.com/notifications/unsubscribe-auth/AAr84dUdrOZOmaTqePaQszfNP_HAzwS5ks5uICTxgaJpZM4VJ60G .

cdenneen commented 5 years ago

@dylanratcliffe has there been way to add custom gem's to the Gemfile onceover uses?

dylanratcliffe commented 5 years ago

@cdenneen Onceover uses the Gemfile that's in your repo. When you run onceover init it creates the gemfile initially but it doesn't manage it going forward, you can make whatever modifications you want in there and onceover will use them

dylanratcliffe commented 5 years ago

Closing because I need to clean up some tickets, if you're not seeing the above behaviour please re-open