summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-12 16:17:31 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-12 16:17:31 -0500
commite90191af9300fda00cd29d609ac80daff00332cc (patch)
treecd211b9d28017ca246fe6253dcf6ff81462af0a6
parent10039b94c77d4543d3b256b0bbda855d57a17be1 (diff)
downloadpuppet-e90191af9300fda00cd29d609ac80daff00332cc.tar.gz
puppet-e90191af9300fda00cd29d609ac80daff00332cc.tar.xz
puppet-e90191af9300fda00cd29d609ac80daff00332cc.zip
more stuff for the interim commit
-rw-r--r--lib/puppet/network/controller.rb30
-rw-r--r--lib/puppet/network/http.rb18
-rw-r--r--spec/unit/network/controller.rb45
-rw-r--r--spec/unit/network/http.rb13
4 files changed, 106 insertions, 0 deletions
diff --git a/lib/puppet/network/controller.rb b/lib/puppet/network/controller.rb
new file mode 100644
index 000000000..7e4cca643
--- /dev/null
+++ b/lib/puppet/network/controller.rb
@@ -0,0 +1,30 @@
+class Puppet::Network::Controller
+ def initialize(args = {})
+ raise ArgumentError, ":indirection is required" unless args[:indirection]
+ @indirection = args[:indirection]
+ @klass = model_class_from_indirection_name(@indirection)
+ end
+
+ def find(args = {})
+ @klass.find(args)
+ end
+
+ def destroy(args = {})
+ @klass.destroy(args)
+ end
+
+ def search(args = {})
+ @klass.search(args)
+ end
+
+ def save(args = {})
+ instance = @klass.new(args)
+ instance.save
+ end
+
+ private
+
+ def model_class_from_indirection_name
+ Class.new # TODO : FIXME make this the indirection class
+ end
+end
diff --git a/lib/puppet/network/http.rb b/lib/puppet/network/http.rb
new file mode 100644
index 000000000..c46a73159
--- /dev/null
+++ b/lib/puppet/network/http.rb
@@ -0,0 +1,18 @@
+class Puppet::Network::HTTP
+ def self.new(args = {})
+ raise ArgumentError, ":server_type is required" unless args[:server_type]
+ obj = class_for_server_type(args[:server_type]).allocate
+ obj.send :initialize, args.delete_if {|k,v| k == :server_type }
+ obj
+ end
+
+ class << self
+ def class_for_server_type(server_type)
+ Class.new
+ # TODO: this will end up probably: { :webrick => ... }
+
+ end
+ private :class_for_server_type
+ end
+end
+
diff --git a/spec/unit/network/controller.rb b/spec/unit/network/controller.rb
new file mode 100644
index 000000000..9098b6e25
--- /dev/null
+++ b/spec/unit/network/controller.rb
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+#
+# Created by Rick Bradley on 2007-10-03.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/network/controller'
+
+describe Puppet::Network::Controller, "when initializing" do
+ it "should require an indirection name" do
+ Proc.new { Puppet::Network::Controller.new }.should raise_error(ArgumentError)
+ end
+end
+
+describe Puppet::Network::Controller, "after initialization" do
+ before do
+ @mock_model_class = mock('model class')
+ Puppet::Network::Controller.any_instance.stubs(:model_class_from_indirection_name).returns(@mock_model_class)
+ @controller = Puppet::Network::Controller.new(:indirection => :foo)
+ end
+
+ it "should delegate find to the indirection's model class's find" do
+ @mock_model_class.expects(:find).returns({:foo => :bar})
+ @controller.find.should == { :foo => :bar }
+ end
+
+ it "should delegate search to the indirection's model class's search" do
+ @mock_model_class.expects(:search).returns({:foo => :bar})
+ @controller.search.should == { :foo => :bar }
+ end
+
+ it "should delegate destroy to the indirection's model class's destroy" do
+ @mock_model_class.expects(:destroy).returns({:foo => :bar})
+ @controller.destroy.should == { :foo => :bar }
+ end
+
+ it "should delegate save to the indirection's model class's save" do
+ data = { :bar => :xyzzy }
+ mock_model_instance = mock('model instance')
+ @mock_model_class.expects(:new).with(data).returns(mock_model_instance)
+ mock_model_instance.expects(:save).returns({:foo => :bar})
+ @controller.save(data).should == { :foo => :bar }
+ end
+end \ No newline at end of file
diff --git a/spec/unit/network/http.rb b/spec/unit/network/http.rb
new file mode 100644
index 000000000..50ef92866
--- /dev/null
+++ b/spec/unit/network/http.rb
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+#
+# Created by Rick Bradley on 2007-10-03.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/network/http'
+
+describe Puppet::Network::HTTP do
+ it "should require a server type when initializing"
+ it "should return an instance of the http server class corresponding to the server type"
+end \ No newline at end of file