From 9a4832efa1890ef91681da6cd6fc5d4601773a63 Mon Sep 17 00:00:00 2001 From: Rich Siegel Date: Fri, 6 Dec 2013 01:35:36 +0000 Subject: [PATCH 1/2] wtf --- .../wsusgroup/{wsusgroup.rb => wsusgrp.rb} | 4 +-- .../puppet/provider/wsusgroup/wsusgrp_spec.rb | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) rename lib/puppet/provider/wsusgroup/{wsusgroup.rb => wsusgrp.rb} (87%) create mode 100644 spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb diff --git a/lib/puppet/provider/wsusgroup/wsusgroup.rb b/lib/puppet/provider/wsusgroup/wsusgrp.rb similarity index 87% rename from lib/puppet/provider/wsusgroup/wsusgroup.rb rename to lib/puppet/provider/wsusgroup/wsusgrp.rb index f6ed954..1f819db 100644 --- a/lib/puppet/provider/wsusgroup/wsusgroup.rb +++ b/lib/puppet/provider/wsusgroup/wsusgrp.rb @@ -1,6 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', 'wsus') - -Puppet::Type.type(:wsusgroup).provide(:wsusgroup, :parent => Puppet::Provider::Wsus) do +Puppet::Type.type(:wsusgroup).provide :wsusgrp, :parent => Puppet::Provider do desc "WSUS group" commands :poshexec => diff --git a/spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb b/spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb new file mode 100644 index 0000000..93b7adc --- /dev/null +++ b/spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby +require File.dirname(__FILE__) + '/../../../../spec_helper' +require 'puppet' +require 'puppet/type' +require 'puppet/provider/wsusgroup/wsusgrp' + +provider_class = Puppet::Type.type(:wsusgroup).provider(:wsusgrp) + +describe provider_class do + before do + @resource = stub("resource", :name => "foo") + @provider = provider_class.new(@resource) + end + + + describe "when an instance" do + before do + @instance = provider_class.new(:wsusgroup) + end + + it "should have a method for creating the instance" do + @instance.should respond_to(:create) + end + + it "should have a method for removing the instance" do + @instance.should respond_to(:destroy) + end + + it "should indicate when the instance already exists" do + @instance = provider_class.new(:ensure => :present) + @instance.exists?.should be_true + end + end +end From ca792d83dabc5327d8bd554e5af13ba1b1e49a96 Mon Sep 17 00:00:00 2001 From: Rich Siegel Date: Fri, 6 Dec 2013 17:00:04 +0000 Subject: [PATCH 2/2] more foobar --- .../wsusgroup/{wsusgrp.rb => wsusgroup.rb} | 4 +- spec/spec_helper.rb | 1 + .../provider/wsusgroup/wsusgroup_spec.rb | 51 +++++++++++++++++++ .../puppet/provider/wsusgroup/wsusgrp_spec.rb | 34 ------------- 4 files changed, 54 insertions(+), 36 deletions(-) rename lib/puppet/provider/wsusgroup/{wsusgrp.rb => wsusgroup.rb} (83%) create mode 100644 spec/unit/puppet/provider/wsusgroup/wsusgroup_spec.rb delete mode 100644 spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb diff --git a/lib/puppet/provider/wsusgroup/wsusgrp.rb b/lib/puppet/provider/wsusgroup/wsusgroup.rb similarity index 83% rename from lib/puppet/provider/wsusgroup/wsusgrp.rb rename to lib/puppet/provider/wsusgroup/wsusgroup.rb index 1f819db..f19cf95 100644 --- a/lib/puppet/provider/wsusgroup/wsusgrp.rb +++ b/lib/puppet/provider/wsusgroup/wsusgroup.rb @@ -1,4 +1,4 @@ -Puppet::Type.type(:wsusgroup).provide :wsusgrp, :parent => Puppet::Provider do +Puppet::Type.type(:wsusgroup).provide :wsusgroup do desc "WSUS group" commands :poshexec => @@ -10,7 +10,7 @@ 'powershell.exe' end - @@connstr= "import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)" + @@connstr= 'import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)' def exists? rc=false diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 854c616..3bc2886 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,7 @@ def horizontal_rule(width = 5) 'mocha/setup', # http://gofreerange.com/mocha/docs/Mocha/Configuration.html 'jumanjiman_spec_helper', 'puppet', + 'rspec', ] begin gems.each {|gem| require gem} diff --git a/spec/unit/puppet/provider/wsusgroup/wsusgroup_spec.rb b/spec/unit/puppet/provider/wsusgroup/wsusgroup_spec.rb new file mode 100644 index 0000000..3c89d5d --- /dev/null +++ b/spec/unit/puppet/provider/wsusgroup/wsusgroup_spec.rb @@ -0,0 +1,51 @@ +#! /usr/bin/env ruby +require File.dirname(__FILE__) + '/../../../../spec_helper' +require 'puppet' +require 'puppet/type' +require 'puppet/provider/wsusgroup/wsusgroup' + +provider = Puppet::Type.type(:wsusgroup).provider(:wsusgroup) + +describe provider do + + let(:poshexec) { + if File.exists?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe" + elsif File.exists?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" + else + 'powershell.exe' + end + } + + before :each do + @resource = Puppet::Type.type(:wsusgroup).new( + :name => "wsusgroup", + :ensure => :present, + :server => "server.example.com" + ) + @provider = provider.new(@resource) + provider.stubs(:healthcheck) + end + + context "when an instance" do + it "should have a method for creating the instance" do + @provider.should respond_to(:create) + end + + it "should have a method for removing the instance" do + @provider.should respond_to(:destroy) + end + + it "should have an exists? method" do + @provider.should respond_to(:exists?) + end + end + + context "#create" do + it "should execute wsusgroup create" do + @provider.expects(:wsusgroup).with('create', poshexec) + @provider.create + end + end +end diff --git a/spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb b/spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb deleted file mode 100644 index 93b7adc..0000000 --- a/spec/unit/puppet/provider/wsusgroup/wsusgrp_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env ruby -require File.dirname(__FILE__) + '/../../../../spec_helper' -require 'puppet' -require 'puppet/type' -require 'puppet/provider/wsusgroup/wsusgrp' - -provider_class = Puppet::Type.type(:wsusgroup).provider(:wsusgrp) - -describe provider_class do - before do - @resource = stub("resource", :name => "foo") - @provider = provider_class.new(@resource) - end - - - describe "when an instance" do - before do - @instance = provider_class.new(:wsusgroup) - end - - it "should have a method for creating the instance" do - @instance.should respond_to(:create) - end - - it "should have a method for removing the instance" do - @instance.should respond_to(:destroy) - end - - it "should indicate when the instance already exists" do - @instance = provider_class.new(:ensure => :present) - @instance.exists?.should be_true - end - end -end