Repository navigation
Expand file tree
/
Copy pathcookbook_show_spec.rb
More file actions
163 lines (148 loc) · 5.96 KB
/
Copy pathcookbook_show_spec.rb
File metadata and controls
163 lines (148 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# rename to cookbook not coookbook
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
describe Chef::Knife::CookbookShow do
before(:each) do
@knife = Chef::Knife::CookbookShow.new
@knife.config = { }
@knife.name_args = [ "cookbook_name" ]
@rest = mock(Chef::REST, :null_object => true)
@knife.stub!(:rest).and_return(@rest)
@knife.stub!(:pretty_print).and_return(true)
@knife.stub!(:output).and_return(true)
end
describe "run" do
describe "with 1 argument: versions" do
it "should show the raw cookbook data" do
@response = ["0.1.0"]
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name").and_return(@response)
@knife.should_receive(:output).with(@response)
@knife.run
end
end
describe "with 2 arguments: name and version" do
before(:each) do
@knife.name_args << "0.1.0"
@response = { "0.1.0" => { "recipes" => {"default.rb" => ""} } }
end
it "should show the specific part of a cookbook" do
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@response)
@knife.should_receive(:output).with(@response)
@knife.run
end
end
# 3-argument needed
describe "with 4 arguments: name, version, segment and filename" do
before(:each) do
@knife.name_args = [ "cookbook_name", "0.1.0", "recipes", "default.rb" ]
@cookbook_response = {
"recipes" => [
{
:name => "default.rb",
:path => "recipes/default.rb",
:checksum => "1234"
}
]
}
@response = "Example recipe text"
end
it "should print the raw result of the request (likely a file!)" do
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0/files/1234").and_return(@response)
@knife.should_receive(:pretty_print).with(@response)
@knife.run
end
end
describe "with 4 arguments: name, version, segment and filename -- with specificity" do
before(:each) do
@knife.name_args = [ "cookbook_name", "0.1.0", "files", "afile.rb" ]
@cookbook_response = {
"files" => [
{
:name => "afile.rb",
:path => "files/host-examplehost.example.org/afile.rb",
:checksum => "1111",
:specificity => "host-examplehost.example.org"
},
{
:name => "afile.rb",
:path => "files/ubuntu-9.10/afile.rb",
:checksum => "2222",
:specificity => "ubuntu-9.10"
},
{
:name => "afile.rb",
:path => "files/ubuntu/afile.rb",
:checksum => "3333",
:specificity => "ubuntu"
},
{
:name => "afile.rb",
:path => "files/default/afile.rb",
:checksum => "4444",
:specificity => "default"
},
]
}
@response = "Example recipe text"
end
describe "with --fqdn" do
it "should pass the fqdn" do
@knife.config[:platform] = "example_platform"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "examplehost.example.org"
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0/files/1111").and_return(@response)
@knife.should_receive(:pretty_print).with(@response)
@knife.run
end
end
describe "and --platform" do
it "should pass the platform" do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "differenthost.example.org"
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0/files/3333").and_return(@response)
@knife.should_receive(:pretty_print).with(@response)
@knife.run
end
end
describe "and --platform-version" do
it "should pass the platform" do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "9.10"
@knife.config[:fqdn] = "differenthost.example.org"
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0/files/2222").and_return(@response)
@knife.should_receive(:pretty_print).with(@response)
@knife.run
end
end
describe "with none of the arguments, it should use the default" do
it "should pass them all" do
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
@rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0/files/4444").and_return(@response)
@knife.should_receive(:pretty_print).with(@response)
@knife.run
end
end
end
end
end