|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | +require 'tempfile' |
| 5 | + |
| 6 | +RSpec.describe 'minimizing provider get calls' do |
| 7 | + let(:common_args) { '--verbose --trace --strict=error --modulepath spec/fixtures' } |
| 8 | + |
| 9 | + describe 'using `puppet resource` with a basic type' do |
| 10 | + it 'calls get 1 time' do |
| 11 | + stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_get_calls_basic") |
| 12 | + expect(stdout_str).to match %r{Notice: test_get_calls_basic: Provider get called 1 times} |
| 13 | + expect(stdout_str).not_to match %r{Notice: test_get_calls_basic: Provider get called 2 times} |
| 14 | + expect(status).to eq 0 |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + describe 'using `puppet apply` with a basic type' do |
| 19 | + it 'calls get 2 times' do |
| 20 | + stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_get_calls_basic { foo: } test_get_calls_basic { bar: }\"") |
| 21 | + expect(stdout_str).to match %r{Notice: test_get_calls_basic: Provider get called 1 times} |
| 22 | + expect(stdout_str).to match %r{Notice: test_get_calls_basic: Provider get called 2 times} |
| 23 | + expect(stdout_str).not_to match %r{Notice: test_get_calls_basic: Provider get called 3 times} |
| 24 | + expect(stdout_str).not_to match %r{Creating} |
| 25 | + end |
| 26 | + |
| 27 | + it 'calls get 3 times with resource purging' do |
| 28 | + stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_get_calls_basic { foo: } test_get_calls_basic { bar: } resources { test_get_calls_basic: purge => true }\"") |
| 29 | + expect(stdout_str).to match %r{Notice: test_get_calls_basic: Provider get called 1 times} |
| 30 | + expect(stdout_str).to match %r{Notice: test_get_calls_basic: Provider get called 2 times} |
| 31 | + expect(stdout_str).to match %r{Notice: test_get_calls_basic: Provider get called 3 times} |
| 32 | + expect(stdout_str).not_to match %r{Notice: test_get_calls_basic: Provider get called 4 times} |
| 33 | + expect(stdout_str).not_to match %r{Creating} |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + describe 'using `puppet resource` with a simple_get_filter type' do |
| 38 | + it 'calls get 1 time' do |
| 39 | + stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_get_calls_sgf") |
| 40 | + expect(stdout_str).to match %r{Notice: test_get_calls_sgf: Provider get called 1 times} |
| 41 | + expect(stdout_str).not_to match %r{Notice: test_get_calls_sgf: Provider get called 2 times} |
| 42 | + expect(status.exitstatus).to be_zero |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + describe 'using `puppet apply` with a type using simple_get_filter' do |
| 47 | + it 'calls get 2 times' do |
| 48 | + stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_get_calls_sgf { foo: } test_get_calls_sgf { bar: }\"") |
| 49 | + expect(stdout_str).to match %r{Notice: test_get_calls_sgf: Provider get called 1 times} |
| 50 | + expect(stdout_str).to match %r{Notice: test_get_calls_sgf: Provider get called 2 times} |
| 51 | + expect(stdout_str).not_to match %r{Notice: test_get_calls_sgf: Provider get called 3 times} |
| 52 | + expect(stdout_str).not_to match %r{Creating} |
| 53 | + end |
| 54 | + |
| 55 | + it 'calls get 3 times when resource purging' do |
| 56 | + stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_get_calls_sgf { foo: } test_get_calls_sgf { bar: } resources { test_get_calls_sgf: purge => true }\"") |
| 57 | + expect(stdout_str).to match %r{Notice: test_get_calls_sgf: Provider get called 1 times} |
| 58 | + expect(stdout_str).to match %r{Notice: test_get_calls_sgf: Provider get called 2 times} |
| 59 | + expect(stdout_str).to match %r{Notice: test_get_calls_sgf: Provider get called 3 times} |
| 60 | + expect(stdout_str).not_to match %r{Notice: test_get_calls_sgf: Provider get called 4 times} |
| 61 | + expect(stdout_str).not_to match %r{Creating} |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments