diff --git a/.rubocop.yml b/.rubocop.yml index 33c33fa..1823837 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,534 +1,538 @@ --- require: - rubocop-performance - rubocop-rspec AllCops: DisplayCopNames: true TargetRubyVersion: '2.4' Include: - "**/*.rb" Exclude: - bin/* - ".vendor/**/*" - "**/Gemfile" - "**/Rakefile" - pkg/**/* - spec/fixtures/**/* - vendor/**/* - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" Layout/LineLength: Description: People have wide screens, use them. Max: 200 RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. Exclude: - spec/acceptance/**/*.rb RSpec/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each Style/BlockDelimiters: Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to be consistent then. EnforcedStyle: braces_for_chaining Style/ClassAndModuleChildren: Description: Compact style reduces the required amount of indentation. EnforcedStyle: compact Style/EmptyElse: Description: Enforce against empty else clauses, but allow `nil` for clarity. EnforcedStyle: empty Style/FormatString: Description: Following the main puppet project's style, prefer the % format format. EnforcedStyle: percent Style/FormatStringToken: Description: Following the main puppet project's style, prefer the simpler template tokens over annotated ones. EnforcedStyle: template Style/Lambda: Description: Prefer the keyword for easier discoverability. EnforcedStyle: literal Style/RegexpLiteral: Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 EnforcedStyle: percent_r Style/TernaryParentheses: Description: Checks for use of parentheses around ternary conditions. Enforce parentheses on complex expressions for better readability, but seriously consider breaking it up. EnforcedStyle: require_parentheses_when_complex Style/TrailingCommaInArguments: Description: Prefer always trailing comma on multiline argument lists. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma Style/TrailingCommaInArrayLiteral: Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: Exclude: - lib/puppet/parser/functions/**/* - spec/**/* Style/WordArray: EnforcedStyle: brackets Performance/AncestorsInclude: Enabled: true Performance/BigDecimalWithNumericArgument: Enabled: true Performance/BlockGivenWithExplicitBlock: Enabled: true Performance/Caller: Enabled: true Performance/CaseWhenSplat: Enabled: true Performance/Casecmp: Enabled: true Performance/CollectionLiteralInLoop: + Exclude: + - spec/**/* Enabled: true Performance/CompareWithBlock: Enabled: true Performance/ConstantRegexp: Enabled: true Performance/Count: Enabled: true Performance/Detect: Enabled: true Performance/DoubleStartEndWith: Enabled: true Performance/EndWith: Enabled: true Performance/FixedSize: Enabled: true Performance/FlatMap: Enabled: true Performance/MethodObjectAsBlock: Enabled: true Performance/RangeInclude: Enabled: true Performance/RedundantBlockCall: Enabled: true Performance/RedundantMatch: Enabled: true Performance/RedundantMerge: Enabled: true Performance/RedundantSortBlock: Enabled: true Performance/RedundantStringChars: Enabled: true Performance/RegexpMatch: Enabled: true Performance/ReverseEach: Enabled: true Performance/ReverseFirst: Enabled: true Performance/Size: Enabled: true Performance/SortReverse: Enabled: true Performance/Squeeze: Enabled: true Performance/StartWith: Enabled: true Performance/StringInclude: Enabled: true Performance/StringReplacement: Enabled: true Performance/Sum: Enabled: true Performance/TimesMap: Enabled: true Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true Bundler/InsecureProtocolSource: Enabled: false Gemspec/DuplicatedAssignment: Enabled: false Gemspec/OrderedDependencies: Enabled: false Gemspec/RequiredRubyVersion: Enabled: false Gemspec/RubyVersionGlobalsUsage: Enabled: false Layout/ArgumentAlignment: Enabled: false Layout/BeginEndAlignment: Enabled: false Layout/ClosingHeredocIndentation: Enabled: false Layout/EmptyComment: Enabled: false Layout/EmptyLineAfterGuardClause: Enabled: false Layout/EmptyLinesAroundArguments: Enabled: false Layout/EmptyLinesAroundAttributeAccessor: Enabled: false Layout/EndOfLine: Enabled: false Layout/FirstArgumentIndentation: Enabled: false Layout/HashAlignment: Enabled: false Layout/HeredocIndentation: Enabled: false Layout/LeadingEmptyLines: Enabled: false Layout/SpaceAroundMethodCallOperator: Enabled: false Layout/SpaceInsideArrayLiteralBrackets: Enabled: false Layout/SpaceInsideReferenceBrackets: Enabled: false Lint/BigDecimalNew: Enabled: false Lint/BooleanSymbol: Enabled: false Lint/ConstantDefinitionInBlock: Enabled: false Lint/DeprecatedOpenSSLConstant: Enabled: false Lint/DisjunctiveAssignmentInConstructor: Enabled: false Lint/DuplicateBranch: Enabled: false Lint/DuplicateElsifCondition: Enabled: false Lint/DuplicateRegexpCharacterClassElement: Enabled: false Lint/DuplicateRequire: Enabled: false Lint/DuplicateRescueException: Enabled: false Lint/EmptyBlock: Enabled: false Lint/EmptyClass: Enabled: false Lint/EmptyConditionalBody: Enabled: false Lint/EmptyFile: Enabled: false Lint/ErbNewArguments: Enabled: false Lint/FloatComparison: Enabled: false Lint/HashCompareByIdentity: Enabled: false Lint/IdentityComparison: Enabled: false Lint/InterpolationCheck: Enabled: false Lint/MissingCopEnableDirective: Enabled: false Lint/MixedRegexpCaptureTypes: Enabled: false Lint/NestedPercentLiteral: Enabled: false Lint/NoReturnInBeginEndBlocks: Enabled: false Lint/NonDeterministicRequireOrder: Enabled: false Lint/OrderedMagicComments: Enabled: false Lint/OutOfRangeRegexpRef: Enabled: false Lint/RaiseException: Enabled: false Lint/RedundantCopEnableDirective: Enabled: false Lint/RedundantRequireStatement: Enabled: false Lint/RedundantSafeNavigation: Enabled: false Lint/RedundantWithIndex: Enabled: false Lint/RedundantWithObject: Enabled: false Lint/RegexpAsCondition: Enabled: false Lint/ReturnInVoidContext: Enabled: false Lint/SafeNavigationConsistency: Enabled: false Lint/SafeNavigationWithEmpty: Enabled: false Lint/SelfAssignment: Enabled: false Lint/SendWithMixinArgument: Enabled: false Lint/ShadowedArgument: Enabled: false Lint/StructNewOverride: Enabled: false Lint/ToEnumArguments: Enabled: false Lint/ToJSON: Enabled: false Lint/TopLevelReturnWithArgument: Enabled: false Lint/TrailingCommaInAttributeDeclaration: Enabled: false Lint/UnexpectedBlockArity: Enabled: false Lint/UnmodifiedReduceAccumulator: Enabled: false Lint/UnreachableLoop: Enabled: false Lint/UriEscapeUnescape: Enabled: false Lint/UriRegexp: Enabled: false Lint/UselessMethodDefinition: Enabled: false Lint/UselessTimes: Enabled: false Metrics/AbcSize: Enabled: false Metrics/BlockLength: Enabled: false Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: false Metrics/MethodLength: Enabled: false Metrics/ModuleLength: Enabled: false Metrics/ParameterLists: Enabled: false Metrics/PerceivedComplexity: Enabled: false Migration/DepartmentName: Enabled: false +Naming/AccessorMethodName: + Enabled: false Naming/BlockParameterName: Enabled: false Naming/HeredocDelimiterCase: Enabled: false Naming/HeredocDelimiterNaming: Enabled: false Naming/MemoizedInstanceVariableName: Enabled: false Naming/MethodParameterName: Enabled: false Naming/RescuedExceptionsVariableName: Enabled: false RSpec/Be: Enabled: false RSpec/Capybara/CurrentPathExpectation: Enabled: false RSpec/Capybara/FeatureMethods: Enabled: false RSpec/Capybara/VisibilityMatcher: Enabled: false RSpec/ContextMethod: Enabled: false RSpec/ContextWording: Enabled: false RSpec/DescribeClass: Enabled: false RSpec/EmptyHook: Enabled: false RSpec/EmptyLineAfterExample: Enabled: false RSpec/EmptyLineAfterExampleGroup: Enabled: false RSpec/EmptyLineAfterHook: Enabled: false RSpec/ExampleLength: Enabled: false RSpec/ExampleWithoutDescription: Enabled: false RSpec/ExpectChange: Enabled: false RSpec/ExpectInHook: Enabled: false RSpec/FactoryBot/AttributeDefinedStatically: Enabled: false RSpec/FactoryBot/CreateList: Enabled: false RSpec/FactoryBot/FactoryClassName: Enabled: false RSpec/HooksBeforeExamples: Enabled: false RSpec/ImplicitBlockExpectation: Enabled: false RSpec/ImplicitSubject: Enabled: false RSpec/LeakyConstantDeclaration: Enabled: false RSpec/LetBeforeExamples: Enabled: false RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: Enabled: false RSpec/MultipleMemoizedHelpers: Enabled: false RSpec/MultipleSubjects: Enabled: false RSpec/NestedGroups: Enabled: false RSpec/PredicateMatcher: Enabled: false RSpec/ReceiveCounts: Enabled: false RSpec/ReceiveNever: Enabled: false RSpec/RepeatedExampleGroupBody: Enabled: false RSpec/RepeatedExampleGroupDescription: Enabled: false RSpec/RepeatedIncludeExample: Enabled: false RSpec/ReturnFromStub: Enabled: false RSpec/SharedExamples: Enabled: false RSpec/StubbedMock: Enabled: false RSpec/UnspecifiedException: Enabled: false RSpec/VariableDefinition: Enabled: false RSpec/VoidExpect: Enabled: false RSpec/Yield: Enabled: false Security/Open: Enabled: false Style/AccessModifierDeclarations: Enabled: false Style/AccessorGrouping: Enabled: false Style/ArgumentsForwarding: Enabled: false Style/AsciiComments: Enabled: false Style/BisectedAttrAccessor: Enabled: false Style/CaseLikeIf: Enabled: false Style/ClassEqualityComparison: Enabled: false Style/CollectionCompact: Enabled: false Style/ColonMethodDefinition: Enabled: false Style/CombinableLoops: Enabled: false Style/CommentedKeyword: Enabled: false Style/Dir: Enabled: false Style/DocumentDynamicEvalDefinition: Enabled: false Style/DoubleCopDisableDirective: Enabled: false Style/EmptyBlockParameter: Enabled: false Style/EmptyLambdaParameter: Enabled: false Style/Encoding: Enabled: false Style/EvalWithLocation: Enabled: false Style/ExpandPathArguments: Enabled: false Style/ExplicitBlockArgument: Enabled: false Style/ExponentialNotation: Enabled: false Style/FloatDivision: Enabled: false Style/GlobalStdStream: Enabled: false Style/HashAsLastArrayItem: Enabled: false Style/HashLikeCase: Enabled: false Style/HashTransformKeys: Enabled: false Style/HashTransformValues: Enabled: false Style/IfUnlessModifier: Enabled: false Style/KeywordParametersOrder: Enabled: false Style/MinMax: Enabled: false Style/MixinUsage: Enabled: false Style/MultilineWhenThen: Enabled: false Style/NegatedIfElseCondition: Enabled: false Style/NegatedUnless: Enabled: false Style/NilLambda: Enabled: false Style/NumericPredicate: Enabled: false Style/OptionalBooleanParameter: Enabled: false Style/OrAssignment: Enabled: false Style/RandomWithOffset: Enabled: false Style/RedundantArgument: Enabled: false Style/RedundantAssignment: Enabled: false Style/RedundantCondition: Enabled: false Style/RedundantConditional: Enabled: false Style/RedundantFetchBlock: Enabled: false Style/RedundantFileExtensionInRequire: Enabled: false Style/RedundantRegexpCharacterClass: Enabled: false Style/RedundantRegexpEscape: Enabled: false Style/RedundantSelfAssignment: Enabled: false Style/RedundantSort: Enabled: false Style/RescueStandardError: Enabled: false Style/SingleArgumentDig: Enabled: false Style/SlicingWithRange: Enabled: false Style/SoleNestedConditional: Enabled: false Style/StderrPuts: Enabled: false Style/StringConcatenation: Enabled: false Style/Strip: Enabled: false Style/SwapValues: Enabled: false Style/SymbolProc: Enabled: false Style/TrailingBodyOnClass: Enabled: false Style/TrailingBodyOnMethodDefinition: Enabled: false Style/TrailingBodyOnModule: Enabled: false Style/TrailingCommaInHashLiteral: Enabled: false Style/TrailingMethodEndStatement: Enabled: false Style/UnpackFirst: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 36d6b1b..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,7 +0,0 @@ -GetText/DecorateString: - Enabled: false - -RSpec/InstanceVariable: - Enabled: true - Exclude: - - spec/acceptance/* \ No newline at end of file diff --git a/spec/acceptance/backup_spec.rb b/spec/acceptance/backup_spec.rb index 78448ec..a50c4d3 100644 --- a/spec/acceptance/backup_spec.rb +++ b/spec/acceptance/backup_spec.rb @@ -1,79 +1,81 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concat backup parameter' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'when puppet' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': backup => 'puppet', } concat::fragment { 'new file': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => 'new contents', } MANIFEST end it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do expect(apply_manifest(pp, catch_failures: true, debug: true).stdout).to match(%r{Filebucketed.*to puppet with sum.*}) apply_manifest(pp, catch_changes: true) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match %r{new contents} + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match %r{new contents} end end describe 'when .backup' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => 'backup extension', } MANIFEST end # XXX Puppet doesn't mention anything about filebucketing with a given # extension like .backup it 'applies the manifest twice no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match %r{backup extension} - expect(file("#{@basedir}/file.backup")).to be_file - expect(file("#{@basedir}/file.backup").content).to match %r{new contents} + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match %r{backup extension} + expect(file("#{basedir}/file.backup")).to be_file + expect(file("#{basedir}/file.backup").content).to match %r{new contents} end end # XXX The backup parameter uses validate_string() and thus can't be the # boolean false value, but the string 'false' has the same effect in Puppet 3 describe "when 'false'" do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => 'new contents', } MANIFEST end it 'applies the manifest twice with no "Filebucketed" stdout and no stderr' do apply_manifest(pp, catch_failures: true) do |r| expect(r.stdout).not_to match(%r{Filebucketed}) end apply_manifest(pp, catch_changes: true) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match %r{new contents} + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match %r{new contents} end end end diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index 2effba4..bfaf801 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,171 +1,173 @@ # frozen_string_literal: true require 'spec_helper_acceptance' case os[:family] when 'aix' username = 'root' groupname = 'system' when 'darwin' username = 'root' groupname = 'wheel' when 'windows' username = 'Administrator' groupname = 'Administrators' else username = 'root' groupname = 'root' end describe 'basic concat test' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'with owner/group root' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', order => '02', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file")).to be_owned_by username unless os[:family] == 'windows' - expect(file("#{@basedir}/file")).to be_grouped_into groupname unless os[:family] == 'windows' || os[:family] == 'darwin' - expect(file("#{@basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows' - expect(file("#{@basedir}/file").content).to match '1' - expect(file("#{@basedir}/file").content).to match '2' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file")).to be_owned_by username unless os[:family] == 'windows' + expect(file("#{basedir}/file")).to be_grouped_into groupname unless os[:family] == 'windows' || os[:family] == 'darwin' + expect(file("#{basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows' + expect(file("#{basedir}/file").content).to match '1' + expect(file("#{basedir}/file").content).to match '2' end end describe 'when present with path set' do let(:pp) do <<-MANIFEST concat { 'file': ensure => present, - path => '#{@basedir}/file', + path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': target => 'file', content => '1', order => '01', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows' - expect(file("#{@basedir}/file").content).to match '1' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows' + expect(file("#{basedir}/file").content).to match '1' end end describe 'with no fragments declared' do let(:pp) do <<-MANIFEST concat { 'file': ensure => present, - path => '#{@basedir}/file', + path => '#{basedir}/file', mode => '0644', } MANIFEST end it 'applies manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to eq '' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to eq '' end end describe 'when absent with path set' do let(:pp) do <<-MANIFEST concat { 'file': ensure => absent, - path => '#{@basedir}/file', + path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': target => 'file', content => '1', order => '01', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).not_to be_file + expect(file("#{basedir}/file")).not_to be_file end end describe 'when present with path that has special characters' do filename = (os[:family] == 'windows') ? 'file(1)' : 'file(1:2)' let(:pp) do <<-MANIFEST concat { '#{filename}': ensure => present, - path => '#{@basedir}/#{filename}', + path => '#{basedir}/#{filename}', mode => '0644', } concat::fragment { '1': target => '#{filename}', content => '1', order => '01', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/#{filename}")).to be_file - expect(file("#{@basedir}/#{filename}")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows' - expect(file("#{@basedir}/#{filename}").content).to match '1' + expect(file("#{basedir}/#{filename}")).to be_file + expect(file("#{basedir}/#{filename}")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows' + expect(file("#{basedir}/#{filename}").content).to match '1' end end describe 'with noop properly' do let(:pp) do <<-MANIFEST concat { 'file': ensure => present, - path => '#{@basedir}/file', + path => '#{basedir}/file', mode => '0644', noop => true, } concat::fragment { '1': target => 'file', content => '1', order => '01', } MANIFEST end it 'applies manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).not_to be_file + expect(file("#{basedir}/file")).not_to be_file end end end diff --git a/spec/acceptance/concurrency_spec.rb b/spec/acceptance/concurrency_spec.rb index f3e184a..2c86fc8 100644 --- a/spec/acceptance/concurrency_spec.rb +++ b/spec/acceptance/concurrency_spec.rb @@ -1,37 +1,39 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concurrency, with file recursive purge' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'when run should still create concat file' do let(:pp) do <<-MANIFEST - file { '#{@basedir}/bar': + file { '#{basedir}/bar': ensure => directory, purge => true, recurse => true, } concat { "foobar": ensure => 'present', - path => '#{@basedir}/bar/foobar', + path => '#{basedir}/bar/foobar', } concat::fragment { 'foo': target => 'foobar', content => 'foo', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/bar/foobar")).to be_file - expect(file("#{@basedir}/bar/foobar").content).to match 'foo' + expect(file("#{basedir}/bar/foobar")).to be_file + expect(file("#{basedir}/bar/foobar").content).to match 'foo' end end end diff --git a/spec/acceptance/force_spec.rb b/spec/acceptance/force_spec.rb index 47f179b..d6fd0d4 100644 --- a/spec/acceptance/force_spec.rb +++ b/spec/acceptance/force_spec.rb @@ -1,149 +1,151 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'force merge of file' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'when run should not force' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'yaml', force => false, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "bar"}', } MANIFEST end it 'applies manifest twice with stderr check' do expect(apply_manifest(pp, catch_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.") expect(apply_manifest(pp, catch_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.") - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match 'file exists' - expect(file("#{@basedir}/file").content).not_to match 'one: foo' - expect(file("#{@basedir}/file").content).not_to match 'one: bar' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match 'file exists' + expect(file("#{basedir}/file").content).not_to match 'one: foo' + expect(file("#{basedir}/file").content).not_to match 'one: bar' end end describe 'when run should not force by default' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'yaml', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "bar"}', } MANIFEST end it 'applies manifest twice with stderr check' do expect(apply_manifest(pp, catch_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.") expect(apply_manifest(pp, catch_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.") - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match 'file exists' - expect(file("#{@basedir}/file").content).not_to match 'one: foo' - expect(file("#{@basedir}/file").content).not_to match 'one: bar' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match 'file exists' + expect(file("#{basedir}/file").content).not_to match 'one: foo' + expect(file("#{basedir}/file").content).not_to match 'one: bar' end end describe 'when run should force' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'yaml', force => true, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "bar"}', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match 'one: foo' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match 'one: foo' end end describe 'when run should force merge nested arrays' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'json', force => true, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": [1]}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": [2]}', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to contain '{"one":\[1,2\]}' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to contain '{"one":\[1,2\]}' end end describe 'when run should not force on plain' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': force => true, format => plain, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "bar"}', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' end end end diff --git a/spec/acceptance/format_spec.rb b/spec/acceptance/format_spec.rb index 3b9adfb..f0fa429 100644 --- a/spec/acceptance/format_spec.rb +++ b/spec/acceptance/format_spec.rb @@ -1,216 +1,218 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'format of file' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'when run should default to plain' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "bar"}', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' end end describe 'when run should output to plain format' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => plain, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "bar"}', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' end end describe 'when run should output to yaml format' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'yaml', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"two": "bar"}', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match 'one: foo\Rtwo: bar' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match 'one: foo\Rtwo: bar' end end describe 'when run should output yaml arrays to yaml format' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'yaml', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => to_yaml([{ 'one.a' => 'foo', 'one.b' => 'bar' }]), } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => to_yaml([{ 'two.a' => 'dip', 'two.b' => 'doot' }]), } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '- one.a: foo\R one.b: bar\R- two.a: dip\R two.b: doot' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '- one.a: foo\R one.b: bar\R- two.a: dip\R two.b: doot' end end describe 'when run should output to json format' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'json', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"two": "bar"}', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '{"one":"foo","two":"bar"}' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '{"one":"foo","two":"bar"}' end end describe 'when run should output to json-array format' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'json-array', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"two": "bar"}', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '[{"one":"foo"},{"two":"bar"}]' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '[{"one":"foo"},{"two":"bar"}]' end end describe 'when run should output to json-pretty format' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'json-pretty', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"two": "bar"}', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '{\R "one": "foo",\R "two": "bar"\R}' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '{\R "one": "foo",\R "two": "bar"\R}' end end describe 'when run should output to json-array-pretty format' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': format => 'json-array-pretty', } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"one": "foo"}', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '{"two": "bar"}', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '[\n {\n "one": "foo"\n },\n {\n "two": "bar"\n }\n]' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '[\n {\n "one": "foo"\n },\n {\n "two": "bar"\n }\n]' end end end diff --git a/spec/acceptance/fragment_order_spec.rb b/spec/acceptance/fragment_order_spec.rb index 397bb85..e9533f0 100644 --- a/spec/acceptance/fragment_order_spec.rb +++ b/spec/acceptance/fragment_order_spec.rb @@ -1,100 +1,102 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concat::fragment order' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'with reverse order, alphabetical' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/foo': + concat { '#{basedir}/foo': order => 'alpha' } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string1', order => '15', } concat::fragment { '2': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string2', # default order 10 } concat::fragment { '3': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string3', order => '1', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).to match %r{string3string2string1} + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).to match %r{string3string2string1} end end describe 'with reverse order, numeric' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/foo': + concat { '#{basedir}/foo': order => 'numeric' } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string1', order => '15', } concat::fragment { '2': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string2', # default order 10 } concat::fragment { '3': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string3', order => '1', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).to match %r{string3string2string1} + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).to match %r{string3string2string1} end end describe 'with normal order' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string1', order => '01', } concat::fragment { '2': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string2', order => '02' } concat::fragment { '3': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string3', order => '03', } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).to match %r{string1string2string3} + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).to match %r{string1string2string3} end end end diff --git a/spec/acceptance/fragment_replace_spec.rb b/spec/acceptance/fragment_replace_spec.rb index 9d32610..600198c 100644 --- a/spec/acceptance/fragment_replace_spec.rb +++ b/spec/acceptance/fragment_replace_spec.rb @@ -1,184 +1,186 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'replacement of' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'file' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': replace => false, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', } - concat { '#{@basedir}/file2': + concat { '#{basedir}/file2': replace => true, } concat::fragment { 'file2_1': - target => '#{@basedir}/file2', + target => '#{basedir}/file2', content => '1', } concat::fragment { 'file2_2': - target => '#{@basedir}/file2', + target => '#{basedir}/file2', content => '2', } MANIFEST end it 'when file should not succeed' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match 'file exists' - expect(file("#{@basedir}/file").content).not_to match '1' - expect(file("#{@basedir}/file").content).not_to match '2' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match 'file exists' + expect(file("#{basedir}/file").content).not_to match '1' + expect(file("#{basedir}/file").content).not_to match '2' end it 'when file should succeed' do - expect(file("#{@basedir}/file2")).to be_file - expect(file("#{@basedir}/file2").content).not_to match 'file exists' - expect(file("#{@basedir}/file2").content).to match '1' - expect(file("#{@basedir}/file2").content).to match '2' + expect(file("#{basedir}/file2")).to be_file + expect(file("#{basedir}/file2").content).not_to match 'file exists' + expect(file("#{basedir}/file2").content).to match '1' + expect(file("#{basedir}/file2").content).to match '2' end end describe 'symlink', unless: (os[:family] == 'windows') do # XXX the core puppet file type will replace a symlink with a plain file # when using ensure => present and source => ... but it will not when using # ensure => present and content => ...; this is somewhat confusing behavior before(:all) do pp = <<-MANIFEST - file { '#{@basedir}': + file { '#{basedir}': ensure => directory, } - file { '#{@basedir}/file': + file { '#{basedir}/file': ensure => link, - target => '#{@basedir}/dangling', + target => '#{basedir}/dangling', } MANIFEST apply_manifest(pp) end let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': replace => false, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', } - concat { '#{@basedir}/file2': + concat { '#{basedir}/file2': replace => true, } concat::fragment { 'file2_1': - target => '#{@basedir}/file2', + target => '#{basedir}/file2', content => '1', } concat::fragment { 'file2_2': - target => '#{@basedir}/file2', + target => '#{basedir}/file2', content => '2', } MANIFEST end it 'when symlink should not succeed' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_linked_to "#{@basedir}/dangling" unless os[:family] == 'aix' || os[:family] == 'windows' - expect(file("#{@basedir}/dangling")).not_to be_file - expect(file("#{@basedir}/dangling")).not_to be_directory + expect(file("#{basedir}/file")).to be_linked_to "#{basedir}/dangling" unless os[:family] == 'aix' || os[:family] == 'windows' + expect(file("#{basedir}/dangling")).not_to be_file + expect(file("#{basedir}/dangling")).not_to be_directory end it 'when symlink should succeed' do - expect(file("#{@basedir}/file2")).to be_file - expect(file("#{@basedir}/file2").content).to match '1' - expect(file("#{@basedir}/file2").content).to match '2' + expect(file("#{basedir}/file2")).to be_file + expect(file("#{basedir}/file2").content).to match '1' + expect(file("#{basedir}/file2").content).to match '2' end end describe 'when directory should not succeed' do before(:all) do pp = <<-MANIFEST - file { '#{@basedir}': + file { '#{basedir}': ensure => directory, } - file { '#{@basedir}/file': + file { '#{basedir}/file': ensure => directory, } MANIFEST apply_manifest(pp) end let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': } + concat { '#{basedir}/file': } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', } MANIFEST end it 'applies the manifest twice with stderr' do expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{change from '?directory'? to '?file'? failed}) expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{change from '?directory'? to '?file'? failed}) - expect(file("#{@basedir}/file")).to be_directory + expect(file("#{basedir}/file")).to be_directory end end # XXX # when there are no fragments, and the replace param will only replace # files and symlinks, not directories. The semantics either need to be # changed, extended, or a new param introduced to control directory # replacement. describe 'when directory should succeed', pending: 'not yet implemented' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '1' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '1' end end end diff --git a/spec/acceptance/fragment_source_spec.rb b/spec/acceptance/fragment_source_spec.rb index 387f3dc..f364d37 100644 --- a/spec/acceptance/fragment_source_spec.rb +++ b/spec/acceptance/fragment_source_spec.rb @@ -1,145 +1,147 @@ # frozen_string_literal: true require 'spec_helper_acceptance' case os[:family] when 'aix' username = 'root' groupname = 'system' when 'darwin' username = 'root' groupname = 'wheel' when 'windows' username = 'Administrator' groupname = 'Administrators' else username = 'root' groupname = 'root' end describe 'concat::fragment source' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'when run should read file fragments from local system' do let(:pp) do <<-MANIFEST - file { '#{@basedir}/file1': + file { '#{basedir}/file1': content => "file1 contents\n" } - file { '#{@basedir}/file2': + file { '#{basedir}/file2': content => "file2 contents\n" } - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', - source => '#{@basedir}/file1', - require => File['#{@basedir}/file1'], + target => '#{basedir}/foo', + source => '#{basedir}/file1', + require => File['#{basedir}/file1'], } concat::fragment { '2': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string1 contents', } concat::fragment { '3': - target => '#{@basedir}/foo', - source => '#{@basedir}/file2', - require => File['#{@basedir}/file2'], + target => '#{basedir}/foo', + source => '#{basedir}/file2', + require => File['#{basedir}/file2'], } MANIFEST end it 'idempotent, file matches' do idempotent_apply(pp) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).to match 'file1 contents' - expect(file("#{@basedir}/foo").content).to match 'file2 contents' + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).to match 'file1 contents' + expect(file("#{basedir}/foo").content).to match 'file2 contents' end end describe 'when run should create files containing first match only.' do let(:pp) do <<-MANIFEST - file { '#{@basedir}/file1': + file { '#{basedir}/file1': content => "file1 contents\n" } - file { '#{@basedir}/file2': + file { '#{basedir}/file2': content => "file2 contents\n" } - concat { '#{@basedir}/result_file1': + concat { '#{basedir}/result_file1': owner => '#{username}', group => '#{groupname}', mode => '0644', } - concat { '#{@basedir}/result_file2': + concat { '#{basedir}/result_file2': owner => '#{username}', group => '#{groupname}', mode => '0644', } - concat { '#{@basedir}/result_file3': + concat { '#{basedir}/result_file3': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '#{@basedir}/result_file1', - source => [ '#{@basedir}/file1', '#{@basedir}/file2' ], - require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ], + target => '#{basedir}/result_file1', + source => [ '#{basedir}/file1', '#{basedir}/file2' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } concat::fragment { '2': - target => '#{@basedir}/result_file2', - source => [ '#{@basedir}/file2', '#{@basedir}/file1' ], - require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ], + target => '#{basedir}/result_file2', + source => [ '#{basedir}/file2', '#{basedir}/file1' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } concat::fragment { '3': - target => '#{@basedir}/result_file3', - source => [ '#{@basedir}/file1', '#{@basedir}/file2' ], - require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ], + target => '#{basedir}/result_file3', + source => [ '#{basedir}/file1', '#{basedir}/file2' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } MANIFEST end it 'idempotent, files match' do idempotent_apply(pp) - expect(file("#{@basedir}/result_file1")).to be_file - expect(file("#{@basedir}/result_file1").content).to match 'file1 contents' - expect(file("#{@basedir}/result_file1").content).not_to match 'file2 contents' + expect(file("#{basedir}/result_file1")).to be_file + expect(file("#{basedir}/result_file1").content).to match 'file1 contents' + expect(file("#{basedir}/result_file1").content).not_to match 'file2 contents' - expect(file("#{@basedir}/result_file2")).to be_file - expect(file("#{@basedir}/result_file2").content).to match 'file2 contents' - expect(file("#{@basedir}/result_file2").content).not_to match 'file1 contents' + expect(file("#{basedir}/result_file2")).to be_file + expect(file("#{basedir}/result_file2").content).to match 'file2 contents' + expect(file("#{basedir}/result_file2").content).not_to match 'file1 contents' - expect(file("#{@basedir}/result_file3")).to be_file - expect(file("#{@basedir}/result_file3").content).to match 'file1 contents' - expect(file("#{@basedir}/result_file3").content).not_to match 'file2 contents' + expect(file("#{basedir}/result_file3")).to be_file + expect(file("#{basedir}/result_file3").content).to match 'file1 contents' + expect(file("#{basedir}/result_file3").content).not_to match 'file2 contents' end end describe 'when run should fail if no match on source.' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/fail_no_source': + concat { '#{basedir}/fail_no_source': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '#{@basedir}/fail_no_source', - source => [ '#{@basedir}/nofilehere', '#{@basedir}/nothereeither' ], + target => '#{basedir}/fail_no_source', + source => [ '#{basedir}/nofilehere', '#{basedir}/nothereeither' ], order => '01', } MANIFEST end it 'applies the manifest with resource failures' do expect(apply_manifest(pp, catch_failures: true).stderr).to match(%r{Failed to generate additional resources using 'eval_generate'}) - expect(file("#{@basedir}/fail_no_source")).not_to be_directory + expect(file("#{basedir}/fail_no_source")).not_to be_directory end end end diff --git a/spec/acceptance/fragments_are_always_replaced_spec.rb b/spec/acceptance/fragments_are_always_replaced_spec.rb index aaae525..a86bd0b 100644 --- a/spec/acceptance/fragments_are_always_replaced_spec.rb +++ b/spec/acceptance/fragments_are_always_replaced_spec.rb @@ -1,103 +1,105 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concat::fragment replace' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'when run should create fragment files' do let(:pp1) do <<-MANIFEST - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'caller has replace unset run 1', } MANIFEST end let(:pp2) do <<-MANIFEST - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'caller has replace unset run 2', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp1) idempotent_apply(pp2) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).not_to match 'caller has replace unset run 1' - expect(file("#{@basedir}/foo").content).to match 'caller has replace unset run 2' + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).not_to match 'caller has replace unset run 1' + expect(file("#{basedir}/foo").content).to match 'caller has replace unset run 2' end end # should create fragment files describe 'when run should replace its own fragment files when caller has File { replace=>true } set' do let(:pp1) do <<-MANIFEST File { replace=>true } - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'caller has replace true set run 1', } MANIFEST end let(:pp2) do <<-MANIFEST File { replace=>true } - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'caller has replace true set run 2', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp1) idempotent_apply(pp2) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).not_to match 'caller has replace true set run 1' - expect(file("#{@basedir}/foo").content).to match 'caller has replace true set run 2' + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).not_to match 'caller has replace true set run 1' + expect(file("#{basedir}/foo").content).to match 'caller has replace true set run 2' end end # should replace its own fragment files when caller has File(replace=>true) set describe 'when run should replace its own fragment files even when caller has File { replace=>false } set' do let(:pp1) do <<-MANIFEST File { replace=>false } - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'caller has replace false set run 1', } MANIFEST end let(:pp2) do <<-MANIFEST File { replace=>false } - concat { '#{@basedir}/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'caller has replace false set run 2', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp1) idempotent_apply(pp2) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).not_to match 'caller has replace false set run 1' - expect(file("#{@basedir}/foo").content).to match 'caller has replace false set run 2' + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).not_to match 'caller has replace false set run 1' + expect(file("#{basedir}/foo").content).to match 'caller has replace false set run 2' end end # should replace its own fragment files even when caller has File(replace=>false) set end diff --git a/spec/acceptance/newline_spec.rb b/spec/acceptance/newline_spec.rb index 28b0e9f..9aeca47 100644 --- a/spec/acceptance/newline_spec.rb +++ b/spec/acceptance/newline_spec.rb @@ -1,56 +1,59 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concat ensure_newline parameter' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end + describe 'when false' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': ensure_newline => false, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '12' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '12' end end describe 'when true' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': ensure_newline => true, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match %r{1\r?\n2\r?\n} + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match %r{1\r?\n2\r?\n} end end end diff --git a/spec/acceptance/noop_spec.rb b/spec/acceptance/noop_spec.rb index bdd913f..53824cd 100644 --- a/spec/acceptance/noop_spec.rb +++ b/spec/acceptance/noop_spec.rb @@ -1,28 +1,31 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concat noop parameter', if: ['debian', 'redhat', 'ubuntu'].include?(os[:family]) do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end + describe 'with "/usr/bin/test -e %"' do let(:pp) do <<-MANIFEST - concat_file { '#{@basedir}/file': + concat_file { '#{basedir}/file': noop => false, } concat_fragment { 'content': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => 'content', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to contain 'content' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to contain 'content' end end end diff --git a/spec/acceptance/order_spec.rb b/spec/acceptance/order_spec.rb index fa0e1c7..5ff94bf 100644 --- a/spec/acceptance/order_spec.rb +++ b/spec/acceptance/order_spec.rb @@ -1,68 +1,71 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concat order' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end + describe 'sortby alpha' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/foo': + concat { '#{basedir}/foo': order => 'alpha' } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string1', order => '1', } concat::fragment { '2': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string2', order => '2', } concat::fragment { '10': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string10', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).to match %r{string1string10string2} + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).to match %r{string1string10string2} end end describe 'sortby numeric' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/foo': + concat { '#{basedir}/foo': order => 'numeric' } concat::fragment { '1': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string1', order => '1', } concat::fragment { '2': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string2', order => '2', } concat::fragment { '10': - target => '#{@basedir}/foo', + target => '#{basedir}/foo', content => 'string10', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/foo")).to be_file - expect(file("#{@basedir}/foo").content).to match %r{string1string2string10} + expect(file("#{basedir}/foo")).to be_file + expect(file("#{basedir}/foo").content).to match %r{string1string2string10} end end end diff --git a/spec/acceptance/pup_1963_spec.rb b/spec/acceptance/pup_1963_spec.rb index b34d131..b7181c3 100644 --- a/spec/acceptance/pup_1963_spec.rb +++ b/spec/acceptance/pup_1963_spec.rb @@ -1,72 +1,74 @@ # frozen_string_literal: true require 'spec_helper_acceptance' command = case os[:family] when 'windows' 'cmd.exe /c echo triggered' else 'echo triggered' end describe 'with metaparameters' do + attr_reader :basedir + before(:each) do @basedir = setup_test_directory end describe 'with subscribed resources' do let(:pp) do <<-MANIFEST concat { "foobar": ensure => 'present', - path => '#{@basedir}/foobar', + path => '#{basedir}/foobar', } concat::fragment { 'foo': target => 'foobar', content => 'foo', } exec { 'trigger': path => $::path, command => "#{command}", subscribe => Concat['foobar'], refreshonly => true, } MANIFEST end it 'applies the manifest twice with no changes second apply' do expect(apply_manifest(pp, catch_failures: true).stdout).to match(%r{Triggered 'refresh'}) expect(apply_manifest(pp, catch_changes: true).stdout).not_to match(%r{Triggered 'refresh'}) end end describe 'with resources to notify' do let(:pp) do <<-MANIFEST exec { 'trigger': path => $::path, command => "#{command}", refreshonly => true, } concat { "foobar": ensure => 'present', - path => '#{@basedir}/foobar', + path => '#{basedir}/foobar', notify => Exec['trigger'], } concat::fragment { 'foo': target => 'foobar', content => 'foo', } MANIFEST end it 'applies the manifest twice with no changes second apply' do expect(apply_manifest(pp, catch_failures: true).stdout).to match(%r{Triggered 'refresh'}) expect(apply_manifest(pp, catch_changes: true).stdout).not_to match(%r{Triggered 'refresh'}) end end end diff --git a/spec/acceptance/quoted_paths_spec.rb b/spec/acceptance/quoted_paths_spec.rb index f4440bc..8aaa20a 100644 --- a/spec/acceptance/quoted_paths_spec.rb +++ b/spec/acceptance/quoted_paths_spec.rb @@ -1,35 +1,37 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'quoted paths' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'with path with blanks' do let(:pp) do <<-MANIFEST - file { '#{@basedir}/concat test': + file { '#{basedir}/concat test': ensure => directory, } - concat { '#{@basedir}/concat test/foo': + concat { '#{basedir}/concat test/foo': } concat::fragment { '1': - target => '#{@basedir}/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string1', } concat::fragment { '2': - target => '#{@basedir}/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string2', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/concat test/foo")).to be_file - expect(file("#{@basedir}/concat test/foo").content).to match %r{string1string2} + expect(file("#{basedir}/concat test/foo")).to be_file + expect(file("#{basedir}/concat test/foo").content).to match %r{string1string2} end end end diff --git a/spec/acceptance/symbolic_name_spec.rb b/spec/acceptance/symbolic_name_spec.rb index 6684ad3..c8ee063 100644 --- a/spec/acceptance/symbolic_name_spec.rb +++ b/spec/acceptance/symbolic_name_spec.rb @@ -1,36 +1,38 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'symbolic name' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end let(:pp) do <<-MANIFEST concat { 'not_abs_path': - path => '#{@basedir}/file', + path => '#{basedir}/file', } concat::fragment { '1': target => 'not_abs_path', content => '1', order => '01', } concat::fragment { '2': target => 'not_abs_path', content => '2', order => '02', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match '1' - expect(file("#{@basedir}/file").content).to match '2' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match '1' + expect(file("#{basedir}/file").content).to match '2' end end diff --git a/spec/acceptance/validation_spec.rb b/spec/acceptance/validation_spec.rb index 3d08c16..6254540 100644 --- a/spec/acceptance/validation_spec.rb +++ b/spec/acceptance/validation_spec.rb @@ -1,29 +1,31 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'validation, concat validate_cmd parameter', if: ['debian', 'redhat', 'ubuntu'].include?(os[:family]) do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end context 'with "/usr/bin/test -e %"' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': validate_cmd => '/usr/bin/test -e %', } concat::fragment { 'content': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => 'content', } MANIFEST end it 'applies the manifest twice with no stderr' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to contain 'content' + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to contain 'content' end end end diff --git a/spec/acceptance/warn_header_spec.rb b/spec/acceptance/warn_header_spec.rb index 54deb58..f7ecfb4 100644 --- a/spec/acceptance/warn_header_spec.rb +++ b/spec/acceptance/warn_header_spec.rb @@ -1,86 +1,88 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'concat warn_header =>' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end describe 'applies the manifest twice with no stderr' do let(:pp) do <<-MANIFEST - concat { '#{@basedir}/file': + concat { '#{basedir}/file': warn => true, } concat::fragment { '1': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '#{@basedir}/file', + target => '#{basedir}/file', content => '2', order => '02', } - concat { '#{@basedir}/file2': + concat { '#{basedir}/file2': warn => false, } concat::fragment { 'file2_1': - target => '#{@basedir}/file2', + target => '#{basedir}/file2', content => '1', order => '01', } concat::fragment { 'file2_2': - target => '#{@basedir}/file2', + target => '#{basedir}/file2', content => '2', order => '02', } - concat { '#{@basedir}/file3': + concat { '#{basedir}/file3': warn => "# foo\n", } concat::fragment { 'file3_1': - target => '#{@basedir}/file3', + target => '#{basedir}/file3', content => '1', order => '01', } concat::fragment { 'file3_2': - target => '#{@basedir}/file3', + target => '#{basedir}/file3', content => '2', order => '02', } MANIFEST end it 'when true should enable default warning message' do idempotent_apply(pp) - expect(file("#{@basedir}/file")).to be_file - expect(file("#{@basedir}/file").content).to match %r{# This file is managed by Puppet\. DO NOT EDIT\.} - expect(file("#{@basedir}/file").content).to match %r{1} - expect(file("#{@basedir}/file").content).to match %r{2} + expect(file("#{basedir}/file")).to be_file + expect(file("#{basedir}/file").content).to match %r{# This file is managed by Puppet\. DO NOT EDIT\.} + expect(file("#{basedir}/file").content).to match %r{1} + expect(file("#{basedir}/file").content).to match %r{2} end it 'when false should not enable default warning message' do - expect(file("#{@basedir}/file2")).to be_file - expect(file("#{@basedir}/file2").content).not_to match %r{# This file is managed by Puppet\. DO NOT EDIT\.} - expect(file("#{@basedir}/file2").content).to match %r{1} - expect(file("#{@basedir}/file2").content).to match %r{2} + expect(file("#{basedir}/file2")).to be_file + expect(file("#{basedir}/file2").content).not_to match %r{# This file is managed by Puppet\. DO NOT EDIT\.} + expect(file("#{basedir}/file2").content).to match %r{1} + expect(file("#{basedir}/file2").content).to match %r{2} end it 'when foo should overide default warning message' do - expect(file("#{@basedir}/file3")).to be_file - expect(file("#{@basedir}/file3").content).to match %r{# foo} - expect(file("#{@basedir}/file3").content).to match %r{1} - expect(file("#{@basedir}/file3").content).to match %r{2} + expect(file("#{basedir}/file3")).to be_file + expect(file("#{basedir}/file3").content).to match %r{# foo} + expect(file("#{basedir}/file3").content).to match %r{1} + expect(file("#{basedir}/file3").content).to match %r{2} end end end diff --git a/spec/acceptance/warnings_spec.rb b/spec/acceptance/warnings_spec.rb index d25180e..5224275 100644 --- a/spec/acceptance/warnings_spec.rb +++ b/spec/acceptance/warnings_spec.rb @@ -1,28 +1,30 @@ # frozen_string_literal: true require 'spec_helper_acceptance' describe 'warnings' do + attr_reader :basedir + before(:all) do @basedir = setup_test_directory end context 'when concat::fragment target not found' do let(:pp) do <<-MANIFEST concat { 'file': - path => '#{@basedir}/file', + path => '#{basedir}/file', } concat::fragment { 'foo': - target => '#{@basedir}/bar', + target => '#{basedir}/bar', content => 'bar', } MANIFEST end it 'applies manifests, check stderr' do expect(apply_manifest(pp, catch_failures: true).stderr).to match 'not found in the catalog' expect(apply_manifest(pp, catch_failures: true).stderr).to match 'not found in the catalog' end end end