Sha256: 15368fc92744c282f447e3f4ef7c6c36bbe8613d679322ba4872687adde90353

Contents?: true

Size: 1.85 KB

Versions: 80

Compression:

Stored size: 1.85 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/face'
require 'puppet/indirector/facts/facter'
require 'puppet/indirector/facts/rest'

describe Puppet::Face[:facts, '0.0.1'] do
  describe "#find" do
    it { is_expected.to be_action :find }
  end

  describe '#upload' do
    let(:model) { Puppet::Node::Facts }
    let(:test_data) { model.new('puppet.node.test', {test_fact: 'test value'}) }
    let(:facter_terminus) { model.indirection.terminus(:facter) }
    let(:rest_terminus) { model.indirection.terminus(:rest) }

    before(:each) do
      Puppet.settings.parse_config(<<-CONF)
[main]
server=puppet.server.invalid
certname=puppet.node.invalid
[agent]
server=puppet.server.test
node_name_value=puppet.node.test
CONF

      # Faces start in :user run mode
      Puppet.settings.preferred_run_mode = :user

      facter_terminus.stubs(:find).with(instance_of(Puppet::Indirector::Request)).returns(test_data)
      rest_terminus.stubs(:save).with(instance_of(Puppet::Indirector::Request)).returns(nil)
    end

    it { is_expected.to be_action :upload }

    it "finds facts from terminus_class :facter" do
      facter_terminus.expects(:find).with(instance_of(Puppet::Indirector::Request)).returns(test_data)

      subject.upload
    end

    it "saves facts to terminus_class :rest" do
      rest_terminus.expects(:save).with(instance_of(Puppet::Indirector::Request)).returns(nil)

      subject.upload
    end

    it "uses settings from the agent section of puppet.conf" do
      facter_terminus.expects(:find).with(responds_with(:key, 'puppet.node.test')).returns(test_data)

      subject.upload
    end

    it "logs the name of the server that received the upload" do
      subject.upload

      expect(@logs).to be_any {|log| log.level == :notice &&
                               log.message =~ /Uploading facts for '.*' to: 'puppet\.server\.test'/}
    end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
puppet-6.4.0 spec/unit/face/facts_spec.rb
puppet-6.4.0-x86-mingw32 spec/unit/face/facts_spec.rb
puppet-6.4.0-x64-mingw32 spec/unit/face/facts_spec.rb
puppet-6.4.0-universal-darwin spec/unit/face/facts_spec.rb
puppet-6.0.7 spec/unit/face/facts_spec.rb
puppet-6.0.7-x86-mingw32 spec/unit/face/facts_spec.rb
puppet-6.0.7-x64-mingw32 spec/unit/face/facts_spec.rb
puppet-6.0.7-universal-darwin spec/unit/face/facts_spec.rb
puppet-5.5.12 spec/unit/face/facts_spec.rb
puppet-5.5.12-x86-mingw32 spec/unit/face/facts_spec.rb
puppet-5.5.12-x64-mingw32 spec/unit/face/facts_spec.rb
puppet-5.5.12-universal-darwin spec/unit/face/facts_spec.rb
puppet-6.3.0 spec/unit/face/facts_spec.rb
puppet-6.3.0-x86-mingw32 spec/unit/face/facts_spec.rb
puppet-6.3.0-x64-mingw32 spec/unit/face/facts_spec.rb
puppet-6.3.0-universal-darwin spec/unit/face/facts_spec.rb
puppet-6.2.0 spec/unit/face/facts_spec.rb
puppet-6.2.0-x86-mingw32 spec/unit/face/facts_spec.rb
puppet-6.2.0-x64-mingw32 spec/unit/face/facts_spec.rb
puppet-6.2.0-universal-darwin spec/unit/face/facts_spec.rb