summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-03-12 09:59:16 +0000
committerThom May <thom@may.lt>2015-03-12 10:20:09 +0000
commit0c6f95f45207f9f7da6f83d38babd47a1dcd5ebf (patch)
tree4dc8d66c02c13613b445182b2dace215d4ae0eec /spec
parent1112130eb05d7d824404ab530cd9407a1ef92995 (diff)
downloadchef-0c6f95f45207f9f7da6f83d38babd47a1dcd5ebf.tar.gz
Add tests for knife status
Add failing tests for custom queries and environment filtering
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/knife/status_spec.rb61
1 files changed, 58 insertions, 3 deletions
diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb
index 2522bc61b1..0a638530d7 100644
--- a/spec/unit/knife/status_spec.rb
+++ b/spec/unit/knife/status_spec.rb
@@ -24,15 +24,70 @@ describe Chef::Knife::Status do
n.automatic_attrs["fqdn"] = "foobar"
n.automatic_attrs["ohai_time"] = 1343845969
end
- query = double("Chef::Search::Query")
- allow(query).to receive(:search).and_yield(node)
- allow(Chef::Search::Query).to receive(:new).and_return(query)
+ allow(Time).to receive(:now).and_return(123456)
+ @query = double("Chef::Search::Query")
+ allow(@query).to receive(:search).and_yield(node)
+ allow(Chef::Search::Query).to receive(:new).and_return(@query)
@knife = Chef::Knife::Status.new
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
+ it "should default to searching for everything" do
+ expect(@query).to receive(:search).with(:node, "*:*")
+ @knife.run
+ end
+
+ it "should filter healthy nodes" do
+ @knife.config[:hide_healthy] = true
+ expect(@query).to receive(:search).with(:node, "NOT ohai_time:[119856 TO 123456]")
+ @knife.run
+ end
+
+ it "should filter by environment" do
+ @knife.config[:environment] = "production"
+ expect(@query).to receive(:search).with(:node, "chef_environment:production")
+ @knife.run
+ end
+
+ it "should filter by environment and health" do
+ @knife.config[:environment] = "production"
+ @knife.config[:hide_healthy] = true
+ expect(@query).to receive(:search).with(:node, "chef_environment:production AND NOT ohai_time:[119856 TO 123456]")
+ @knife.run
+ end
+
+ context "with a custom query" do
+ before :each do
+ @knife.instance_variable_set(:@name_args, ["name:my_custom_name"])
+ end
+
+ it "should allow a custom query to be specified" do
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name")
+ @knife.run
+ end
+
+ it "should filter healthy nodes" do
+ @knife.config[:hide_healthy] = true
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name AND NOT ohai_time:[119856 TO 123456]")
+ @knife.run
+ end
+
+ it "should filter by environment" do
+ @knife.config[:environment] = "production"
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name AND chef_environment:production")
+ @knife.run
+ end
+
+ it "should filter by environment and health" do
+ @knife.config[:environment] = "production"
+ @knife.config[:hide_healthy] = true
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name AND chef_environment:production AND NOT ohai_time:[119856 TO 123456]")
+ @knife.run
+ end
+ end
+
it "should not colorize output unless it's writing to a tty" do
@knife.run
expect(@stdout.string.match(/foobar/)).not_to be_nil