From ac6eebf93bdd3093bc069263c23d1399bbcab305 Mon Sep 17 00:00:00 2001 From: ameyavarade Date: Thu, 19 Dec 2013 18:50:29 +0530 Subject: [PATCH 1/4] Server list tests updated as per the fix of 10878 in knife-cloud. --- spec/functional/server_list_func_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/functional/server_list_func_spec.rb b/spec/functional/server_list_func_spec.rb index e4c00fdd..4bd30fdc 100644 --- a/spec/functional/server_list_func_spec.rb +++ b/spec/functional/server_list_func_spec.rb @@ -31,6 +31,7 @@ @node = TestResource.new({:id => "server-4", :name => "server-4", :chef_environment => "_default", :fqdn => "testfqdnnode.us", :run_list => [], :tags => [], :platform => "ubuntu", :platform_family => "debian"}) Chef::Node.stub(:list).and_return({"server-4" => @node}) instance.config[:chef_data] = true + @resources.each {|res| res.stub_chain(:attributes, :include?).and_return(true)} end it "lists formatted list of resources on chef data option set" do From f2da2f6bd22413127a5a26b20284f467a046e4f3 Mon Sep 17 00:00:00 2001 From: ameyavarade Date: Tue, 31 Dec 2013 15:33:35 +0530 Subject: [PATCH 2/4] Fixed rspec tests --- spec/functional/server_list_func_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/functional/server_list_func_spec.rb b/spec/functional/server_list_func_spec.rb index 4bd30fdc..f58c5e3c 100644 --- a/spec/functional/server_list_func_spec.rb +++ b/spec/functional/server_list_func_spec.rb @@ -13,7 +13,7 @@ ] instance.stub(:query_resource).and_return(@resources) instance.stub(:puts) - instance.stub(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new) + instance.stub(:create_service_instance).and_return(Chef::Knife::Cloud::FogService.new) instance.stub(:validate!) end From 21d931058f089847806bb0037e40f69fbf8d4a7c Mon Sep 17 00:00:00 2001 From: ameyavarade Date: Tue, 31 Dec 2013 15:44:39 +0530 Subject: [PATCH 3/4] Reverted old test fix. --- spec/functional/server_list_func_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/functional/server_list_func_spec.rb b/spec/functional/server_list_func_spec.rb index f58c5e3c..5820221a 100644 --- a/spec/functional/server_list_func_spec.rb +++ b/spec/functional/server_list_func_spec.rb @@ -31,7 +31,6 @@ @node = TestResource.new({:id => "server-4", :name => "server-4", :chef_environment => "_default", :fqdn => "testfqdnnode.us", :run_list => [], :tags => [], :platform => "ubuntu", :platform_family => "debian"}) Chef::Node.stub(:list).and_return({"server-4" => @node}) instance.config[:chef_data] = true - @resources.each {|res| res.stub_chain(:attributes, :include?).and_return(true)} end it "lists formatted list of resources on chef data option set" do From 125140b32be0476bee786358d07d15f1c1dd3b3e Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Wed, 8 Jan 2014 13:14:19 +0530 Subject: [PATCH 4/4] Removed redundant TestResource class code. --- spec/spec_helper.rb | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af5a8c11..67cc108c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,7 @@ require "securerandom" require 'knife-openstack/version' require 'test/knife-utils/test_bed' +require 'resource_spec_helper' def find_instance_id(instance_name, file) file.lines.each do |line| @@ -61,34 +62,3 @@ def init_openstack_test puts "Error while creating file - incorrect_openstack.pem" end end - -# TODO - we should use factory girl or fixtures for this as part of test utils. -# Creates a resource class that can dynamically add attributes to -# instances and set the values -module JSONModule - def to_json - hash = {} - self.instance_variables.each do |var| - hash[var] = self.instance_variable_get var - end - hash.to_json - end - def from_json! string - JSON.load(string).each do |var, val| - self.instance_variable_set var, val - end - end -end - -class TestResource - include JSONModule - def initialize(*args) - args.each do |arg| - arg.each do |key, value| - add_attribute = "class << self; attr_accessor :#{key}; end" - eval(add_attribute) - eval("@#{key} = value") - end - end - end -end