spice 0.0.1.alpha.2 → 0.0.2.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Spice
2
2
  class Cookbook < Spice::Chef
3
3
  def self.all(options={})
4
- connection.get("/cookbooks").map { |c| c[0] }
4
+ connection.get("/cookbooks")
5
5
  end
6
6
 
7
7
  def self.[](name)
@@ -24,7 +24,7 @@ module Spice
24
24
 
25
25
  def self.delete(options={})
26
26
  name = options.delete(:name)
27
- connection.delete("/cookbooks/#{name}")
27
+ connection.delete("/cookbooks/#{name}", options)
28
28
  end
29
29
  end
30
30
  end
@@ -24,7 +24,7 @@ module Spice
24
24
 
25
25
  def self.delete(options={})
26
26
  name = options.delete(:name)
27
- connection.delete("/data/#{name}")
27
+ connection.delete("/data/#{name}", options)
28
28
  end
29
29
  end
30
30
  end
data/lib/spice/node.rb CHANGED
@@ -24,7 +24,7 @@ module Spice
24
24
 
25
25
  def self.delete(options={})
26
26
  name = options.delete(:name)
27
- connection.delete("/nodes/#{name}")
27
+ connection.delete("/nodes/#{name}", options)
28
28
  end
29
29
  end
30
30
  end
data/lib/spice/role.rb ADDED
@@ -0,0 +1,30 @@
1
+ module Spice
2
+ class Role < Spice::Chef
3
+ def self.all(options={})
4
+ connection.get("/roles")
5
+ end
6
+
7
+ def self.[](name)
8
+ connection.get("/roles/#{name}")
9
+ end
10
+
11
+ def self.show(options={})
12
+ name = options.delete(:name)
13
+ connection.get("/roles/#{name}")
14
+ end
15
+
16
+ def self.create(options={})
17
+ connection.post("/roles", options)
18
+ end
19
+
20
+ def self.update(options={})
21
+ name = options.delete(:name)
22
+ connection.put("/roles/#{name}", options)
23
+ end
24
+
25
+ def self.delete(options={})
26
+ name = options.delete(:name)
27
+ connection.delete("/roles/#{name}", options)
28
+ end
29
+ end
30
+ end
data/lib/spice/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spice
2
- VERSION = "0.0.1.alpha.2"
2
+ VERSION = "0.0.2.beta"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,24 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'bundler'
4
+ Bundler.require
5
+
3
6
  require 'rspec'
7
+ require 'webmock/rspec'
8
+ require 'timecop'
9
+ require 'forgery'
4
10
  require 'spice'
11
+ require 'chef'
5
12
 
6
- require 'rest-client'
7
- require 'mixlib-authentication'
8
13
  # Requires supporting files with custom matchers and macros, etc,
9
14
  # in ./support/ and its subdirectories.
10
15
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
16
 
12
17
  RSpec.configure do |config|
13
-
18
+ config.before do
19
+ Timecop.freeze
20
+ end
21
+ config.after do
22
+ Timecop.return
23
+ end
14
24
  end
File without changes
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ module Spice
4
+ describe Chef do
5
+ describe '.connection' do
6
+ before { setup_chef_client }
7
+ it "returns an instance of Spice::Connection" do
8
+ Spice::Chef.connection.should be_an_instance_of(Spice::Connection)
9
+ end
10
+ end
11
+
12
+ describe '.clients' do
13
+ let(:clients) { Chef.clients }
14
+
15
+ before do
16
+ stub_request(:get, "http://localhost:4000/clients").
17
+ to_return(
18
+ :status => 200,
19
+ :body => '{"testclient":"http://localhost:4000/clients/testclient",
20
+ "goodclient":"http://localhost:4000/clients/goodclient"}',
21
+ :headers => {})
22
+ end
23
+ it "should return a list of all clients" do
24
+ clients.length.should == 2
25
+ end
26
+ it "should provide valid client" do
27
+ clients["testclient"].should == "http://localhost:4000/clients/testclient"
28
+ end
29
+ end
30
+
31
+ describe '.nodes' do
32
+ let(:nodes) { Chef.nodes }
33
+
34
+ before do
35
+ stub_request(:get, "http://localhost:4000/nodes").
36
+ to_return(
37
+ :status => 200,
38
+ :body => '{"testnode":"http://localhost:4000/nodes/testnode"}',
39
+ :headers => {}
40
+ )
41
+ end
42
+ it "should return a list of all nodes" do
43
+ nodes.length.should == 1
44
+ # nodes.first["testnode"].should == "http://localhost:4000/nodes/testnode"
45
+ end
46
+ it "should provide valid node" do
47
+ nodes["testnode"].should == "http://localhost:4000/nodes/testnode"
48
+ end
49
+ end
50
+
51
+ describe '.data_bags' do
52
+ let(:data_bags) { Chef.data_bags }
53
+ before do
54
+ stub_request(:get, "http://localhost:4000/data").
55
+ to_return(
56
+ :status => 200,
57
+ :body => '{"testdata":"http://localhost:4000/data/testdata"}',
58
+ :headers => {}
59
+ )
60
+ end
61
+ it "should return a list of all data bags" do
62
+ data_bags.length.should == 1
63
+ end
64
+ it "should provide valid data" do
65
+ data_bags["testdata"].should == "http://localhost:4000/data/testdata"
66
+ end
67
+ end
68
+
69
+ describe '.roles' do
70
+ let(:roles) { Chef.roles }
71
+ before do
72
+ stub_request(:get, "http://localhost:4000/roles").
73
+ to_return(
74
+ :status => 200,
75
+ :body => '{"testrole":"http://localhost:4000/roles/testrole"}',
76
+ :headers => {}
77
+ )
78
+ end
79
+ it "should return a list of all roles" do
80
+ roles.length.should == 1
81
+ end
82
+ it "should provide valid role" do
83
+ roles["testrole"].should == "http://localhost:4000/roles/testrole"
84
+ end
85
+ end
86
+
87
+ describe '.cookbooks' do
88
+ let(:cookbooks) { Chef.cookbooks }
89
+ before do
90
+ stub_request(:get, "http://localhost:4000/cookbooks").
91
+ to_return(
92
+ :status => 200,
93
+ :body => '{"testcookbook":"http://localhost:4000/cookbooks/testcookbook"}',
94
+ :headers => {}
95
+ )
96
+ end
97
+ it "should return a list of all cookbooks" do
98
+ cookbooks.length.should == 1
99
+ end
100
+ it "should provide valid cookbook" do
101
+ cookbooks["testcookbook"].should == "http://localhost:4000/cookbooks/testcookbook"
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ module Spice
4
+ describe Client do
5
+ describe ".list" do
6
+ # setup_authentication
7
+ let(:chef) { setup_chef_client }
8
+ it "returns a list of clients" do
9
+ VCR.use_cassette 'client/list', :record => :new_episodes do
10
+ # chef.get_rest("/clients")
11
+ end
12
+ end
13
+ end
14
+
15
+ describe ".show" do
16
+ # VCR.use_cassette 'client/show', :record => :new_episodes do
17
+ # Client.show(:name => "testclient")
18
+ # end
19
+ let(:chef) { setup_chef_client }
20
+ it "returns a valid client" do
21
+ VCR.use_cassette 'client/show', :record => :new_episodes do
22
+ # chef.get_rest("/clients/admin")
23
+ end
24
+ end
25
+ it "returns nothing when a client is not found" do
26
+ VCR.use_cassette 'client/show_not_found', :record => :new_episodes do
27
+ # chef.get_rest("/clients/badclient")
28
+ end
29
+ end
30
+ end
31
+
32
+ describe ".create" do
33
+ let(:chef) { setup_chef_client }
34
+ it "creates a valid non-admin client" do
35
+ VCR.use_cassette 'client/create_nonadmin', :record => :new_episodes do
36
+ # chef.post_rest("/clients", JSON.generate(:name => "lkjasdf", :admin => false))
37
+ Client.create(:name => "kijasf", :admin => false)
38
+ end
39
+ end
40
+ # it "creates a valid admin client" do
41
+ # VCR.use_cassette 'client/create', :record => :new_episodes do
42
+ # chef.post_rest("/clients", JSON.parse(:name => "testclient", :admin => true))
43
+ # end
44
+ # end
45
+ it "does not create a client that already exists"
46
+ end
47
+ #
48
+ # describe ".update" do
49
+ # setup_authentication
50
+ #
51
+ # let(:name) { Forgery::Name.first_name.downcase.to_s }
52
+ # before { Client.create(:name => name) }
53
+ # VCR.use_cassette 'client/update', :record => :new_episodes do
54
+ # Client.update(:name => "name")
55
+ # end
56
+ # end
57
+ #
58
+ # describe ".delete" do
59
+ # setup_authentication
60
+ #
61
+ # let(:name) { Forgery::Name.first_name.downcase.to_s }
62
+ # before { Client.create(:name => name) }
63
+ #
64
+ # VCR.use_cassette 'client/delete', :record => :new_episodes do
65
+ # Client.delete(:name => name)
66
+ # end
67
+ # end
68
+ end
69
+ end
File without changes
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Spice
4
+ describe Cookbook do
5
+ describe ".list" do
6
+ VCR.use_cassette 'cookbook/list', :record => :new_episodes do
7
+ Cookbook.list
8
+ end
9
+ end
10
+
11
+ describe ".show" do
12
+ VCR.use_cassette 'cookbook/show', :record => :new_episodes do
13
+ Cookbook.show(:name => "testcookbook")
14
+ end
15
+ end
16
+
17
+ describe ".create" do
18
+ VCR.use_cassette 'cookbook/create', :record => :new_episodes do
19
+ Cookbook.create(:name => "testcookbook")
20
+ end
21
+ end
22
+
23
+ describe ".update" do
24
+ VCR.use_cassette 'cookbook/update', :record => :new_episodes do
25
+ Cookbook.update(:name => "testcookbook")
26
+ end
27
+ end
28
+
29
+ describe ".delete" do
30
+ VCR.use_cassette 'cookbook/delete', :record => :new_episodes do
31
+ Cookbook.delete(:name => "testcookbook")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Spice
4
+ describe DataBag do
5
+ describe ".list" do
6
+ VCR.use_cassette 'data/list', :record => :new_episodes do
7
+ DataBag.list
8
+ end
9
+ end
10
+
11
+ describe ".show" do
12
+ VCR.use_cassette 'data/show', :record => :new_episodes do
13
+ DataBag.show(:name => "testdata")
14
+ end
15
+ end
16
+
17
+ describe ".create" do
18
+ VCR.use_cassette 'data/create', :record => :new_episodes do
19
+ DataBag.create(:name => "testdata")
20
+ end
21
+ end
22
+
23
+ describe ".update" do
24
+ VCR.use_cassette 'data/update', :record => :new_episodes do
25
+ DataBag.update(:name => "testdata")
26
+ end
27
+ end
28
+
29
+ describe ".delete" do
30
+ VCR.use_cassette 'data/delete', :record => :new_episodes do
31
+ DataBag.delete(:name => "testdata")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Spice
4
+ describe Node do
5
+ describe ".list" do
6
+ VCR.use_cassette 'node/list', :record => :new_episodes do
7
+ Node.list
8
+ end
9
+ end
10
+
11
+ describe ".show" do
12
+ VCR.use_cassette 'node/show', :record => :new_episodes do
13
+ Node.show(:name => "testnode")
14
+ end
15
+ end
16
+
17
+ describe ".create" do
18
+ VCR.use_cassette 'node/create', :record => :new_episodes do
19
+ Node.create(:name => "testnode")
20
+ end
21
+ end
22
+
23
+ describe ".update" do
24
+ VCR.use_cassette 'node/update', :record => :new_episodes do
25
+ Node.update(:name => "testnode")
26
+ end
27
+ end
28
+
29
+ describe ".delete" do
30
+ VCR.use_cassette 'node/delete', :record => :new_episodes do
31
+ Node.delete(:name => "testnode")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Spice
4
+ describe Role do
5
+ describe ".list" do
6
+ VCR.use_cassette 'role/list', :record => :new_episodes do
7
+ Role.list
8
+ end
9
+ end
10
+
11
+ describe ".show" do
12
+ VCR.use_cassette 'role/show', :record => :new_episodes do
13
+ Role.show(:name => "testrole")
14
+ end
15
+ end
16
+
17
+ describe ".create" do
18
+ VCR.use_cassette 'role/create', :record => :new_episodes do
19
+ Role.create(:name => "testrole")
20
+ end
21
+ end
22
+
23
+ describe ".update" do
24
+ VCR.use_cassette 'role/update', :record => :new_episodes do
25
+ Role.update(:name => "testrole")
26
+ end
27
+ end
28
+
29
+ describe ".delete" do
30
+ VCR.use_cassette 'role/delete', :record => :new_episodes do
31
+ Role.delete(:name => "testrole")
32
+ end
33
+ end
34
+ end
35
+ end
data/spec/spice_spec.rb CHANGED
@@ -1,7 +1,129 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Spice" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
4
+ describe ".default_host" do
5
+ it "should default to 'localhost'" do
6
+ Spice.default_host.should == "localhost"
7
+ end
8
+ it "should not be settable" do
9
+ lambda { Spice.default_host = "chef.example.com" }.should raise_error
10
+ end
11
+ # @default_host || "localhost"
12
+ end
13
+
14
+ describe ".default_port" do
15
+ it "should default to '4000'" do
16
+ Spice.default_port.should == "4000"
17
+ end
18
+ it "should not be settable" do
19
+ lambda { Spice.default_port = "9000" }.should raise_error
20
+ end
21
+ end
22
+
23
+ describe ".default_scheme" do
24
+ it "should default to 'http'" do
25
+ Spice.default_scheme.should == "http"
26
+ end
27
+ it "should not be settable" do
28
+ lambda { Spice.default_scheme = "ftp" }.should raise_error
29
+ end
30
+ end
31
+
32
+ describe ".host" do
33
+ it "should default to 'localhost' if not set" do
34
+ Spice.host.should == "localhost"
35
+ end
36
+ it "should be settable" do
37
+ Spice.host = "chef.example.com"
38
+ Spice.host.should == "chef.example.com"
39
+ end
40
+ end
41
+
42
+ describe ".port" do
43
+ it "should default to '4000' if not set" do
44
+ Spice.port.should == "4000"
45
+ end
46
+ it "should be settable" do
47
+ Spice.port = "9000"
48
+ Spice.port.should == "9000"
49
+ end
50
+ end
51
+
52
+ describe ".scheme" do
53
+ it "should default to 'http' if not set" do
54
+ Spice.scheme.should == "http"
55
+ end
56
+ it "should be settable" do
57
+ Spice.scheme = 'https'
58
+ Spice.scheme.should == 'https'
59
+ end
60
+ end
61
+
62
+ describe ".client_name" do
63
+ it "should not have a default" do
64
+ Spice.client_name.should be_nil
65
+ end
66
+ it "should be settable" do
67
+ Spice.client_name = "testclient"
68
+ Spice.client_name.should == "testclient"
69
+ end
70
+ end
71
+
72
+ describe ".key_file" do
73
+ it "should not have a default" do
74
+ Spice.key_file.should be_nil
75
+ end
76
+ it "should be settable" do
77
+ Spice.key_file = "/tmp/keyfile.pem"
78
+ Spice.key_file.should == File.read("/tmp/keyfile.pem")
79
+ end
80
+ it "should raise exception if it does not exist" do
81
+ lambda { Spice.key_file = "/tmp/badkey.pem" }.should raise_error(Errno::ENOENT)
82
+ end
83
+ end
84
+
85
+ describe ".connection" do
86
+ it "should not have a default" do
87
+ Spice.connection.should be_nil
88
+ end
89
+ end
90
+
91
+ describe ".reset!" do
92
+ before do
93
+ Spice.host = "chef.example.com"
94
+ Spice.port = "9000"
95
+ Spice.scheme = "https"
96
+ Spice.key_file = "/tmp/keyfile.pem"
97
+ Spice.client_name = "testduder"
98
+ end
99
+ it "should reset Spice.host" do
100
+ Spice.reset!
101
+ Spice.host.should == "localhost"
102
+ end
103
+ it "should reset Spice.port" do
104
+ Spice.reset!
105
+ Spice.port.should == "4000"
106
+ end
107
+ it "should reset Spice.scheme" do
108
+ Spice.reset!
109
+ Spice.scheme.should == "http"
110
+ end
111
+ it "should unset Spice.key_file" do
112
+ Spice.reset!
113
+ Spice.key_file.should be_nil
114
+ end
115
+ it "should unset Spice.connection" do
116
+ Spice.reset!
117
+ Spice.connection.should be_nil
118
+ end
119
+ end
120
+ describe ".connect!" do
121
+ it "should create a connection object" do
122
+ Spice.connect!
123
+ Spice.connection.should be_a_kind_of(Spice::Connection)
124
+ end
125
+ it "connection should contain a host" do
126
+ Spice.connection.host.should == "localhost"
127
+ end
6
128
  end
7
129
  end