Permalink
Browse files

Add some basic tests for check_resource.rb

  • Loading branch information...
1 parent b8ad086 commit 202792611323c820a1a0c3dcc51fca81122c466d @rodjek rodjek committed Aug 18, 2011
Showing with 142 additions and 0 deletions.
  1. +1 −0 lib/puppet-lint/plugin.rb
  2. +130 −0 spec/puppet-lint/check_resources_spec.rb
  3. +11 −0 spec/spec_helper.rb
View
1 lib/puppet-lint/plugin.rb
@@ -18,6 +18,7 @@ def self.included(klass)
class PuppetLint::CheckPlugin
include PuppetLint::Plugin
+ attr_reader :warnings, :errors
def initialize
@warnings = []
View
130 spec/puppet-lint/check_resources_spec.rb
@@ -0,0 +1,130 @@
+require 'spec_helper'
+
+describe PuppetLint::Plugins::CheckResources do
+ subject do
+ klass = described_class.new
+ klass.test(code)
+ klass
+ end
+
+ describe '3 digit file mode' do
+ let(:code) { "file { 'foo': mode => 777 }" }
+
+ its(:warnings) { should include "mode should be represented as a 4 digit octal value on line 1" }
+ its(:errors) { should be_empty }
+ end
+
+ describe '4 digit file mode' do
+ let(:code) { "file { 'foo': mode => '0777' }" }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'ensure as only attr in a single line resource' do
+ let(:code) { "file { 'foo': ensure => present }" }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'ensure as only attr in a multi line resource' do
+ let(:code) { "
+ file { 'foo':
+ ensure => present,
+ }"
+ }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'ensure as second attr in a multi line resource' do
+ let(:code) { "
+ file { 'foo':
+ mode => '0000',
+ ensure => present,
+ }"
+ }
+
+ its(:warnings) { should include "ensure found on line 4 but it's not the first attribute" }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'ensure as first attr in a multi line resource' do
+ let(:code) { "
+ file { 'foo':
+ ensure => present,
+ mode => '0000',
+ }"
+ }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'quoted resource title on single line resource' do
+ let(:code) { "file { 'foo': }" }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'unquoted resource title on single line resource' do
+ let(:code) { "file { foo: }" }
+
+ its(:warnings) { should include "unquoted resource title on line 1" }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'quoted resource title on multi line resource' do
+ let(:code) { "
+ file { 'foo':
+ }"
+ }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'unquoted resource title on multi line resource' do
+ let(:code) { "
+ file { foo:
+ }"
+ }
+
+ its(:warnings) { should include "unquoted resource title on line 2" }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'condensed resources with quoted titles' do
+ let(:code) { "
+ file {
+ 'foo': ;
+ 'bar': ;
+ }"
+ }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'condensed resources with an unquoted title' do
+ let(:code) { "
+ file {
+ 'foo': ;
+ bar: ;
+ }"
+ }
+
+ its(:warnings) { should include "unquoted resource title on line 4" }
+ its(:errors) { should be_empty }
+ end
+
+ describe 'single line resource with an array of titles (all quoted)' do
+ let(:code) { "file { ['foo', 'bar']: }" }
+
+ its(:warnings) { should be_empty }
+ its(:errors) { should be_empty }
+ end
+end
View
11 spec/spec_helper.rb
@@ -0,0 +1,11 @@
+require 'puppet-lint'
+
+#class PuppetLint::Warning < Exception; end
+#class PuppetLint::Error < Exception; end
+#PuppetLint::CheckPlugin.any_instance.stub(:warn) do |arg|
+# raise PuppetLint::Warning
+#end
+
+#PuppetLint::CheckPlugin.any_instance.stub(:error) do |arg|
+# raise PuppetLint::Error
+#end

0 comments on commit 2027926

Please sign in to comment.