Giter Club home page Giter Club logo

Comments (8)

DavidS avatar DavidS commented on July 17, 2024

Please try specifying the facter version you want to test through setting facterversion on on_supported_os (see https://github.com/mcanevet/rspec-puppet-facts/blob/fe21de12108fbab0123bdc4db2365a29ea62f171/lib/rspec-puppet-facts.rb#L34) . This could use a sentence or two in the README to make it discoverable.

Related, there is talk on getting cfacter (that is, facter 3) into gems for testing: https://tickets.puppetlabs.com/browse/FACT-1542 . please vote there to help prioritise this issue.

from rspec-puppet-facts.

cdenneen avatar cdenneen commented on July 17, 2024

@DavidS any good way to get this in the spec_helper.rb so I don't have to specify in the array of the spec test?

from rspec-puppet-facts.

cdenneen avatar cdenneen commented on July 17, 2024

@DavidS tried the following but didn't work (you can see the commented out stubbed fact I had to use before):

  on_supported_os({
    supported_os: [
      {
        'operatingsystem' => 'CentOS',
        'operatingsystemrelease' => [
          '7'
        ],
        'facterversion' => '3.6.4'
      }
    ]
  }).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge({
          puppetversion: Puppet.version,
          sudoversion: '1.7.10p9',
          ap_env: 'dev',
          role: 'mapi',
          awsregion: 'us-east-1'
#          memory: {
#            system: {
#              total_bytes: '1111'
#            }
#          }
        })
      end

Even tried:

  on_supported_os({
    supported_os: [
      {
        'operatingsystem' => 'CentOS',
        'operatingsystemrelease' => [
          '7'
        ]
      }
    ]
  }).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge({
          facterversion: '3.6.4',
          puppetversion: Puppet.version,
          sudoversion: '1.7.10p9',
          ap_env: 'dev',
          role: 'mapi',
          awsregion: 'us-east-1'
#          memory: {
#            system: {
#              total_bytes: '1111'
#            }
#          }
        })
      end

from rspec-puppet-facts.

cdenneen avatar cdenneen commented on July 17, 2024

I even tried to move this to spec_helper.rb with no luck:

RSpec.configure do |c|
  c.tty = true
  c.mock_framework = :rspec
  c.mock_with(:rspec)
  c.after(:suite) do
    RSpec::Puppet::Coverage.report!(95)
  end
  c.hiera_config = File.expand_path(
    File.join(__FILE__, '../fixtures/hiera.yaml')
  )
  default_facts = {
    puppetversion: Puppet.version,
    facterversion: '3.6.4'
  }
  c.default_facts = default_facts
end

But oddly if I do this in my own script it will return just fine ( facterversion > 2.5.1 ):

require 'facterdb'
require 'rspec-puppet-facts'

facterversion = ARGV[0]
facter_version_filter = RspecPuppetFacts.facter_version_to_filter(facterversion)
db = FacterDB.get_facts({ :facterversion => facter_version_filter })

version = facterversion

filter = []

filter << {
  :facterversion => facter_version_filter,
  :operatingsystem => 'CentOS',
  :operatingsystemmajrelease => '7',
  :hardwaremodel => 'x86_64',
}

received_facts = FacterDB::get_facts(filter)

puts received_facts[0].to_h[:memory]['system']['total_bytes']
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.6.1
512798720
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.7
6089424896
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.4
6089424896
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.0
514228224
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 2.5
mytest.rb:21:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)

from rspec-puppet-facts.

cdenneen avatar cdenneen commented on July 17, 2024

I found a way to do it within the individual spec ... the facterversion has to be on the same level as supported_os:

  on_supported_os({
   facterversion: '3.7',
    supported_os: [
      {
        'operatingsystem' => 'CentOS',
        'operatingsystemrelease' => [
          '7'
        ]
      }
    ]
  }).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge({
          puppetversion: Puppet.version,
          sudoversion: '1.7.10p9',
          ap_env: 'dev',
          role: 'mapi',
          awsregion: 'us-east-1'
#          memory: {
#            system: {
#              total_bytes: '1111'
#            }
#          }
        })
      end

Does anyone know how to get that to work from the spec_helper.rb example above... doesn't appear to be reading default_facts.

from rspec-puppet-facts.

cyberious avatar cyberious commented on July 17, 2024

Any update on this, fighting with the same issue.

from rspec-puppet-facts.

cyberious avatar cyberious commented on July 17, 2024

Ugly as it is the way I worked around this in my spec_helper file was to do something like this

require 'facter'

module Facter
  def self.version
    ENV['FACTER_VERSION'] || '3.8.0'
  end
end

from rspec-puppet-facts.

ghoneycutt avatar ghoneycutt commented on July 17, 2024

Facter 2.5.1 appears to be working. If someone would like to send a patch to allow for cfacter, I would be happy to add it to the test matrix.

from rspec-puppet-facts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.