summaryrefslogtreecommitdiff
path: root/spec/unit/node
AgeCommit message (Collapse)AuthorFilesLines
2012-08-08Avoid stubbing Thread::new due to issues in newer mochaPatrick Carlisle1-5/+5
In mocha >= 0.11.0, unstubbing a method is done by defining a method that calls the original method. Somehow this indirection causes issues when Thread::new is stubbed, and the new thread does not have proper access to local variables. This patch fixes this from both ends, by not stubbing Thread::new and not using local variables in the test that was failing.
2012-07-23Reduce stubs and expectations on settingsPatrick Carlisle2-7/+4
Many tests set stubs or expectations on configuration values. This is unnecessary, as settings are reset before each test. Because creating a stub stubs out the entire value method on settings, stubbing any individual setting interferes with retrieving any other setting. This makes for weird errors and fragile tests. This commit changes most cases to just set each setting directly. Expectations on settings were often used to verify that a setting is used. This is not a good way of testing this, since it checks that the value is accessed but not that it is actually used correctly. Most expecations on settings are better expressed by changing the setting and then verifying a returned value.
2012-07-05Refactor module to require path and environment argsPatrick Carlisle1-5/+5
2012-07-02(maint) Standardize on /usr/bin/env ruby -S rspecJeff McCune2-2/+2
Without this patch some spec files are using `ruby -S rspec` and others are using `rspec`. We should standardize on a single form of the interpreter used for spec files. `ruby -S rspec` is the best choice because it correctly informs editors such as Vim with Syntastic that the file is a Ruby file rather than an Rspec file.
2012-05-11Merge branch '2.7.x'Patrick Carlisle1-4/+9
2012-05-09Significantly improve compilation performance when using modulesNick Lewis1-4/+9
When autoloading classes/defines, the typeloader constructs a set of possible locations for the class, based on its name. Effectively, it will look in the canonical locations corresponding to each namespace in the fully-qualified name. So for each namespace, it will ask the environment for a Puppet::Module instance for that module, to ask it which of the module's potentially manifests match the class it's looking for. To answer that request, the environment instantiates a Puppet::Module. This amounts to potentially thousands of Puppet::Module instances being created, because it does this many times (based on nesting of the class name) per include/autoload/import. When Puppet::Module instances are created, they parse and load their metadata.json file, in part to validate their use. This implies that each compilation results in metadata.json being parsed thousands of times, which is extremely slow (and obviously provides no actual benefit). Fortunately, the environment object already keeps a list of Puppet::Module instances for every module in its modulepath. The fix applied here is simply to change the environment such that it provides modules by looking them up in its cached list, resulting in up to an order of magnitude improvement in compilation time.
2012-04-10Merge branch '2.7.x'Patrick Carlisle1-0/+3
* 2.7.x: (maint) Remove unnecessary step from puppet module build help (#13659) Convert fact values to string when searching database (#13649) Restrict module name matching (#13643) Make the use of FileUtils.rm_rf secure (#13642) Move search notice message (#13639) Don't send errors directly to stderr (#13638) Add SemVer#pre function (#3581) Stop forking around: Add fork helper method (#13397) fix gem provider ensure=>latest bug (#12101) Make Puppet::Util::absolute_path? usable in autoloader (#12101) Add shared context for specs to imitate windows or posix Conflicts: lib/puppet/util.rb spec/unit/util_spec.rb
2012-04-09Merge branch '2.7.x'Patrick Carlisle1-1/+13
* 2.7.x: (#9167) Do not send email when nothing changes [#13686] Fix directoryservices ShadowHashData code Fixup tests to work on CentOS 5 fix bug in Util#symbolizehash! (#13567) Fix create_resources name parameter bug (#13636) Update Module Face copyright date (#13737) Swap build_tree and format_tree method names (#9167) Do not send email when nothing changes Add Module Tool Make core changes needed for the puppet module tool (#13367) Patch SemVer to permit ranges including pre-release components. Monkey patch FileUtils.mv in Ruby 1.8.5 (#1076) Show warning if an empty group is specified Maint: Remove unused mock objects in user spec Maint: Use real objects in user spec Maint: Add a real provider class to user spec Maint: Remove unused variable in user spec Conflicts: lib/puppet/util/monkey_patches.rb spec/unit/type/resources_spec.rb spec/unit/type/user_spec.rb
2012-04-05(#13649) Restrict module name matchingKelsey Hightower1-0/+3
Before this patch the regex used to match valid module names in `Puppet::Node::Environment#modules_by_path` matches invalid module names. This patch replaces the current regex pattern with one more accurate. This patch also includes updated specs to cover this change in behavior.
2012-03-29Make core changes needed for the puppet module toolMatt Robinson1-1/+13
This includes changes to portions of the Puppet code base that have some use by other parts of Puppet than the module tool, but are necessary for the module tool work.
2012-02-23Merge branch '2.7.x'Patrick Carlisle1-66/+159
* 2.7.x: (63 commits) Maint: Fix bad copy and paste (#12725) Fix puppet agent --listen on Windows (#11740) Wait on the handle from the PROCESS_INFORMATION structure (#12564) Stub CHILDSTATUS in all test cases, not just failure cases. Updating CHANGELOG and lib/puppet.rb for 2.7.11 (#12412) Mark symbolic file modes test as pending on Windows Symbolic file mode test fixes when no mode change happens. Fix spec ordering failure on environment Updating CHANGELOG and lib/puppet.rb for 2.7.11 Disable specs that use replace_file on Windows Disable replace_file on Windows Remove unnecessary fallbacks in change_{user,group} Document uid/gid-related methods in Puppet::Util Copy owner/group in replace_file (#12463) eliminate `secure_open` in favour of `replace_file` (#12460) use `replace_file` for the .k5login file (#12462) user_role_add: use `replace_file` for /etc/shadow (#12463) add secure `replace_file` to Puppet::Util (#12459) drop supplementary groups when permanently dropping UID (#12458) default to users primary group, not root, in `asuser` ... Conflicts: lib/puppet/application/queue.rb lib/puppet/provider/package/openbsd.rb lib/puppet/util.rb spec/unit/network/http/webrick_spec.rb spec/unit/util_spec.rb test/lib/puppettest/servertest.rb
2012-02-20Fix spec ordering failure on environmentMatt Robinson1-0/+14
The module_requirements method was sorting the requirements, but only as it went along, not for the entire list of requirements that got put in the data structure. This caused intermittent test failures since sometimes the results would come out in a different order than the specs asserted. This moves the sort to happen *after* the data is all in.
2012-02-15Fix a test that tries to create a dir with '*' in the nameMatt Robinson1-1/+1
Windows has a bigger list of reserved characters that can't be used in directory names than Linux does, so a spec failed that tried to create an invalid module dir actually created an invalid Windows dir. http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions The following reserved characters: < (less than) > (greater than) : (colon) " (double quote) / (forward slash) \ (backslash) | (vertical bar or pipe) ? (question mark) * (asterisk) The main point of the failing spec was to show the restrictions on module directory names, which is /^[-\w]+$/, so I'm just going to use an '=' in the spec since Windows doesn't reserve that.
2012-02-15(#12256) module_requirements should include versionsKelsey Hightower1-2/+19
Before this patch module requirements do not include version numbers. Since modules with the same name, but different version numbers, can be installed at the same time -- in different parts of the modulepath, there is no way to tell which module has the dependency. This patch fixes this issue by changing the data structure that represents module requirements from a two item Array to a Hash with three keys: name, version, and version_requirement. This patch includes updated spec tests related to this change.
2012-02-15Update module and environment with functionality for the module toolMatt Robinson1-66/+128
Being able to figure out what other modules depend on a module is useful for resolving contraints when installing and preventing uninstalls of modules that are still required. And being able to tell if a module has local changes is useful to prevent accidentally losing those changes when upgrading or uninstalling a module.
2012-02-02(#12309) move execution-related methods from Util to Util::ExecutionChris Price1-1/+1
There are still deprecated stubs for execpipe, execfail, and execute in Puppet::Util for backwards compatibility. rspecs are all passing, but would still like to go through and check for deprecation warnings that were triggered by this changeset (and fix them, obviously). get spec tests running against Puppet::Util -> Util::Execution refactor
2012-01-18Merge branch '2.7.x'Daniel Pittman1-58/+76
2012-01-13(#11803) Add modules_by_path method to environmentsMatt Robinson1-0/+32
There's already a modules method on environments that returns your modules, but only the first one in the module path. For example, if you have a modulepath with multiple directories, and a module is in both directories, you only ever info back about the module in the first directory in the modulepath. For the `module list` command we need to show details about all the modules split up by path.
2012-01-13(#11802) Make Puppet::Module able to find module in specific pathMatt Robinson1-2/+2
For the `module list` command we want to be able to tell about all the modules in multiple directories of an environment's modulepath. Currently, if we have a module with the same name in two different directories of the modulepath it's impossible to get information on it since Puppet::Module.new takes a name and environment will always assume the path for the module is in the first directory of the environment's modulepath. This change allows the module's path to be passed in so that you can instantiate a Puppet::Module for any module location.
2012-01-13maint: Cleanup environment_specMatt Robinson1-53/+41
A test environment was being setup repeatedly so I just moved it into a let block. I also used real modulepaths on the environments instead of stubbing the value since it's shorter and easier to read.
2012-01-13maint: Fix Puppet::Node::Environment::Helper specsMatt Robinson1-5/+3
These specs were creating environments when they didn't need to, and not testing what the description said. The test to show that a string was accepted passed an environment object.
2011-08-19Don't use non-1.8.5-compatible methods 'Object#tap' and 'Dir.mktmpdir'Nick Lewis1-1/+1
These methods aren't available until Ruby 1.8.6 (Dir.mktmpdir) and Ruby 1.8.7 (Object#tap). Reviewed-By: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit 61df3f7c39d74b82e37f48c3519293406036e1e9)
2011-08-19Fix issue with forward and backslashes in Windows pathsJosh Cooper1-1/+1
The environment validates its modulepath and manifestdir settings, but it uses Dir.getwd to convert a relative path into an absolute path. The problem is that on Windows, Dir.getwd returns a path with backslashes. (Interestingly this only happens when puppet is loaded, not in irb for example.) And since we do not yet support backslashes in Windows paths or UNC paths, the directory is not included in the environment. For the time being, I am using File.expand_path to normalize the path. It has the side-effect of converting backslashes to forward slashes. This is sufficient to work around backslashes in Dir.getwd. In the near future, I will be refactoring how paths are split, validated, tested, etc, and I have a REMIND in place to fix the environment. But as a result of this change it exposed a bug in our rdoc parser dealing with the finding the root of a path. The parser assumed that the root was '/', but caused an infinite loop when passed a Windows path. I added a test for this case, which is only run on Windows, because on Unix File.dirname("C:/") == '.'. After all of that, I had to disable one of the rdoc spec tests, because it attempted to reproduce a specific bug, which caused rdoc to try to create a directory of the form: C:/.../files/C:/.... Of course, this fails because ':' is not a valid filename character on Windows. Paired-with: Nick Lewis <nick@puppetlabs.com> Reviewed-by: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit 9279d0954eb20d75e18a666fd572b5492e157608)
2011-08-19Rework Puppet::Util::Cacher to only expire using TTLsNick Lewis2-30/+8
We have removed every usage of cached_attr in which the attribute needs to be manually expired. Thus, the only meaningful behavior provided by Puppet::Util::Cacher is expiration based on TTLs. This commit reworks the cacher to only support that behavior. Rather than accepting an options hash, of which :ttl is the only available option, cached_attr now requires a second argument, which is the TTL. TTLs are now used to compute expirations, which are stored and used for expiring values. Previously, we stored a timestamp and used it and the TTL to determine whether the attribute was expired. This had the potentially undesirable side effect that the lifetime of a cached attribute could be extended after its insertion by modifying the TTL setting for the cache. Now, the lifetime of an attribute is determined when it is set, and is thereafter immutable, aside from deliberately re-setting the expiration for that particular attribute. Reviewed-By: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit d198fedf65e472b384666fc9ae3bef487852068a) Conflicts: spec/integration/node/facts_spec.rb spec/unit/node_spec.rb
2011-08-19Fix tests with "relative" paths on WindowsJosh Cooper1-4/+9
Absolute paths on Unix, e.g. /foo/bar, are not absolute on Windows, which breaks many test cases. This commit adds a method to PuppetSpec::Files.make_absolute that makes the path absolute in test cases. On Unix (Puppet.features.posix?) it is a no-op. On Windows, (Puppet.features.microsoft_windows?) the drive from the current working directory is prepended. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit 462a95e3d077b1915a919399b846068816c84583) Conflicts: spec/unit/parser/functions/extlookup_spec.rb
2011-07-26Fix issue with forward and backslashes in Windows pathsJosh Cooper1-1/+1
The environment validates its modulepath and manifestdir settings, but it uses Dir.getwd to convert a relative path into an absolute path. The problem is that on Windows, Dir.getwd returns a path with backslashes. (Interestingly this only happens when puppet is loaded, not in irb for example.) And since we do not yet support backslashes in Windows paths or UNC paths, the directory is not included in the environment. For the time being, I am using File.expand_path to normalize the path. It has the side-effect of converting backslashes to forward slashes. This is sufficient to work around backslashes in Dir.getwd. In the near future, I will be refactoring how paths are split, validated, tested, etc, and I have a REMIND in place to fix the environment. But as a result of this change it exposed a bug in our rdoc parser dealing with the finding the root of a path. The parser assumed that the root was '/', but caused an infinite loop when passed a Windows path. I added a test for this case, which is only run on Windows, because on Unix File.dirname("C:/") == '.'. After all of that, I had to disable one of the rdoc spec tests, because it attempted to reproduce a specific bug, which caused rdoc to try to create a directory of the form: C:/.../files/C:/.... Of course, this fails because ':' is not a valid filename character on Windows. Paired-with: Nick Lewis <nick@puppetlabs.com> Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
2011-07-21Don't use non-1.8.5-compatible methods 'Object#tap' and 'Dir.mktmpdir'Nick Lewis1-1/+1
These methods aren't available until Ruby 1.8.6 (Dir.mktmpdir) and Ruby 1.8.7 (Object#tap). Reviewed-By: Jacob Helwig <jacob@puppetlabs.com>
2011-07-21Rework Puppet::Util::Cacher to only expire using TTLsNick Lewis2-30/+8
We have removed every usage of cached_attr in which the attribute needs to be manually expired. Thus, the only meaningful behavior provided by Puppet::Util::Cacher is expiration based on TTLs. This commit reworks the cacher to only support that behavior. Rather than accepting an options hash, of which :ttl is the only available option, cached_attr now requires a second argument, which is the TTL. TTLs are now used to compute expirations, which are stored and used for expiring values. Previously, we stored a timestamp and used it and the TTL to determine whether the attribute was expired. This had the potentially undesirable side effect that the lifetime of a cached attribute could be extended after its insertion by modifying the TTL setting for the cache. Now, the lifetime of an attribute is determined when it is set, and is thereafter immutable, aside from deliberately re-setting the expiration for that particular attribute. Reviewed-By: Jacob Helwig <jacob@puppetlabs.com>
2011-07-19Fix tests with "relative" paths on WindowsJosh Cooper1-4/+9
Absolute paths on Unix, e.g. /foo/bar, are not absolute on Windows, which breaks many test cases. This commit adds a method to PuppetSpec::Files.make_absolute that makes the path absolute in test cases. On Unix (Puppet.features.posix?) it is a no-op. On Windows, (Puppet.features.microsoft_windows?) the drive from the current working directory is prepended. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
2011-07-15Making Fact json handling more resilientLuke Kanies1-0/+14
We were failing if any values were nil, and values were often nil, at least in testing. We now only include non-nil values, and we handle nil values just fine. Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Nick Lewis <nick@puppetlabs.com>
2011-04-21Revert "Fixing Facts pson methods more resilient"Max Martin1-24/+6
This reverts commit 07a7a68a25eb9b21189751c27f90f972224ea533. The JSON patch series has caused problems with the inventory service, and further discussion is needed to decide how to serialize objects to PSON with regards to future compatibility. Conflicts: spec/unit/node/facts_spec.rb Paired-with:Matt Robinson <matt@puppetlabs.com>
2011-04-15maint: Fix the missed failure from the previous commitNick Lewis1-1/+1
There were two times being used, and the previous fix only fixed one of them. Reviewed-By: Jacob Helwig
2011-04-15maint: Fix a broken Puppet::Node::Facts specNick Lewis1-1/+1
This was breaking in other timezones because it was comparing to a string literal representation of a time, which really varies between timezones.
2011-04-14Adding json-specific matchersLuke Kanies1-5/+8
These make the JSON tests much easier to read and write. They're the first custom matchers that I can find, so they're breaking a bit of new ground, but the JSON tests were pretty hard to read and there was a lot of duplication, so it seemed worth it. Note that for some reason they're not working on Facts - it seems to get immediately turned into a full instance by the JSON parsing subsystem, and I've no idea why. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com> Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2011-04-14Fixing Facts pson methods more resilientLuke Kanies1-1/+19
They were currently failing if any values were nil, which happened a lot. We also prefer not to include nil values, since it muddies the json unnecessarily. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com> Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2011-04-13Revert "(#6928) Removed --ignoreimport"Nick Lewis1-0/+8
This reverts commit 24a277c5e805ce16e0b86e17e6cb2fbe1945ae07. Despite not needing --ignoreimport as an option anymore, it's still used internally and has to stay.
2011-04-13(#6928) Removed --ignoreimportNick Lewis1-8/+0
This was only used with --parseonly, which is gone. Paired-With: Jesse Wolfe
2011-04-13maint: clean up the spec test headers in bulk.Daniel Pittman2-4/+2
We now use a shebang of: #!/usr/bin/env rspec This enables the direct execution of spec tests again, which was lost earlier during the transition to more directly using the rspec2 runtime environment.
2011-04-08maint: just require 'spec_helper', thanks rspec2Daniel Pittman2-2/+2
rspec2 automatically sets a bunch of load-path stuff we were by hand, so we can just stop. As a side-effect we can now avoid a whole pile of stupid things to try and include the spec_helper.rb file... ...and then we can stop protecting spec_helper from evaluating twice, since we now require it with a consistent name. Yay. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-04-07Merge branch '2.6.x' into nextMax Martin1-15/+25
* 2.6.x: (maint) Indentation fixes (#6490) Add plugin initialization callback system to core Fix #4339 - Locally save the last report to $lastrunreport Fix #4339 - Save a last run report summary to $statedir/last_run_summary.yaml Fixed #3127 - removed legacy debug code Fixed #3127 - Fixed gem selection regex (#5437) Invalidate cached TypeCollection when there was an error parsing (#6937) Adjust formatting of recurse's desc (#6937) Document the recurse parameter of File type. (#6893) Document the cron type in the case of specials. (#5670) Don't trigger refresh from a failed resource Fixed #6554 - Missing $haveftool if/else conditional in install.rb breaking Ruby 1.9 Conflicts (Manually resolved): lib/puppet/application/agent.rb lib/puppet/application/apply.rb lib/puppet/configurer.rb lib/puppet/resource/type_collection.rb lib/puppet/type/file.rb spec/integration/configurer_spec.rb spec/unit/application/agent_spec.rb spec/unit/application/apply_spec.rb spec/unit/configurer_spec.rb spec/unit/indirector/report/yaml_spec.rb spec/unit/resource/type_collection_spec.rb Paired-with: Nick Lewis
2011-04-01(#5437) Invalidate cached TypeCollection when there was an error parsingJacob Helwig1-14/+15
The caching of the TypeCollection in Puppet::Node::Environment would cause parse errors to occur (and be reported) only once and never again, until the file had changed on disk. This would also cause empty catalogs to be sent down to the agents further hiding the problem. Now, when a file fails to parse, it will be re-parsed every time on every following compilation, causing the parse error to be reported every time, and preventing sending down empty catalogs to agents. Paired-with: Nick Lewis <nick@puppetlabs.com>
2011-03-25(#5477) Allow watch_file to watch non-existent files, especially site.ppJesse Wolfe1-16/+13
The watch_file mechanism would refuse to monitor paths to files that didn't exist. This patch makes it possible to watch a file that hasn't been created yet, so when it is created, you manifests will get reparsed. Paired-With: Max Martin <max@puppetlabs.com> Reviewed-By: Jacob Helwig <jacob@puppetlabs.com>
2011-03-04(#5148) Fix failing spec due to timezoneNick Lewis1-1/+1
Time.parse(...) will yield a string in the local timezone. So when this spec was run in a non -0700 timezone, it was failing, because it was comparing a string in local time to a string in -0700. This fixes it to compare to the local string representation of the time.
2011-03-04(#5148) Add support for PSON to factsNick Lewis1-0/+24
Previously, facts could be fetched via the REST API in PSON, but came back as the to_s representation of a Ruby object, rather than as proper PSON data. This patch adds to_pson and from_pson to facts, so they can be properly used with PSON.
2010-12-06maint: Use expand_path when requiring spec_helper or puppettestMatt Robinson2-2/+2
Doing a require to a relative path can cause files to be required more than once when they're required from different relative paths. If you expand the path fully, this won't happen. Ruby 1.9 also requires that you use expand_path when doing these requires. Paired-with: Jesse Wolfe
2010-11-30Maint: Modified tests of indirector.save to call the indirection directly.Paul Berry1-1/+1
This change replaces calls to <model object>.save with calls to <model class>.indirection.save(<model object>). This makes the use of the indirector explicit rather than implicit so that it will be easier to search for all indirector call sites using grep. This is an intermediate refactor on the way towards allowing indirector calls to be explicitly routed to multiple termini. This patch affects tests only; the next patch will make the corresponding change to the code.
2010-11-29Maint: Refactor tests to use <class>.indirection.<method>Paul Berry1-6/+0
Replaced uses of the find, search, destroy, and expire methods on model classes with direct calls to the indirection objects. This change affects tests only.
2010-10-28(#5148) Fix failing spec due to timezoneNick Lewis1-1/+1
Time.parse(...) will yield a string in the local timezone. So when this spec was run in a non -0700 timezone, it was failing, because it was comparing a string in local time to a string in -0700. This fixes it to compare to the local string representation of the time.
2010-10-28(#5148) Add support for PSON to factsNick Lewis1-0/+24
Previously, facts could be fetched via the REST API in PSON, but came back as the to_s representation of a Ruby object, rather than as proper PSON data. This patch adds to_pson and from_pson to facts, so they can be properly used with PSON.
2010-08-17Merge remote branch 'paul/4472-4483-4496-4521-4522'Jesse Wolfe1-4/+55
a.k.a. "make_taller_trees"