/
runner_spec.rb
145 lines (120 loc) · 5.58 KB
/
runner_spec.rb
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
# Copyright (c) 2009-2012 VMware, Inc.
require "spec_helper"
describe Bosh::Cli::Runner do
before(:all) do
@out = StringIO.new
Bosh::Cli::Config.output = @out
end
def test_cmd(args, namespace, action, cmd_args = [])
runner = Bosh::Cli::Runner.new(args)
runner.prepare
runner.dispatch
runner.namespace.should == namespace
runner.action.should == action
runner.args.should == cmd_args
end
it "has a set of default global options" do
runner = Bosh::Cli::Runner.new(["do", "some", "stuff"])
runner.parse_options!
runner.options[:verbose].should == nil
runner.options[:colorize].should == true
runner.options[:director_checks].should == true
runner.options[:quiet].should == nil
runner.options[:non_interactive].should == nil
end
it "allows overriding global options" do
runner = Bosh::Cli::Runner.new(["--verbose", "--no-color",
"--skip-director-checks", "--quiet",
"--non-interactive", "release",
"upload", "/path"])
runner.parse_options!
runner.options[:verbose].should == true
runner.options[:colorize].should == false
runner.options[:director_checks].should == false
runner.options[:quiet].should == true
runner.options[:non_interactive].should == true
end
it "dispatches commands to appropriate methods (nu school)" do
test_cmd(["version"], :misc, :version)
test_cmd(["status"], :misc, :status)
test_cmd(["target"], :misc, :show_target)
test_cmd(["target", "test"], :misc, :set_target, ["test"])
test_cmd(["target", "test", "alias"], :misc, :set_target, ["test", "alias"])
test_cmd(["deploy"], :deployment, :perform)
test_cmd(["deployment"], :deployment, :show_current)
test_cmd(["deployment", "test"], :deployment, :set_current, ["test"])
test_cmd(["delete", "deployment", "foo"], :deployment, :delete, ["foo"])
test_cmd(["delete", "stemcell", "a", "1"], :stemcell, :delete, ["a", "1"])
test_cmd(["delete", "release", "a"], :release, :delete, ["a"])
test_cmd(["delete", "release", "a", "--force"],
:release, :delete, ["a", "--force"])
test_cmd(["delete", "release", "a", "2.2.1", "--force"],
:release, :delete, ["a", "2.2.1", "--force"])
test_cmd(["create", "user", "admin"], :user, :create, ["admin"])
test_cmd(["create", "user", "admin", "12321"],
:user, :create, ["admin", "12321"])
test_cmd(["create", "release"], :release, :create)
test_cmd(["reset", "release"], :release, :reset)
test_cmd(["create", "package", "bla"], :package, :create, ["bla"])
test_cmd(["login", "admin", "12321"], :misc, :login, ["admin", "12321"])
test_cmd(["logout"], :misc, :logout)
test_cmd(["purge"], :misc, :purge_cache)
test_cmd(["init", "release"], :release, :init)
test_cmd(["init", "release", "/path"], :release, :init, ["/path"])
test_cmd(["upload", "release", "/path"], :release, :upload, ["/path"])
test_cmd(["upload", "release"], :release, :upload)
test_cmd(["upload", "stemcell", "/path"], :stemcell, :upload, ["/path"])
test_cmd(["generate", "package", "foo"], :package, :generate, ["foo"])
test_cmd(["generate", "job", "baz"], :job, :generate, ["baz"])
test_cmd(["verify", "release", "/path"], :release, :verify, ["/path"])
test_cmd(["verify", "stemcell", "/path"], :stemcell, :verify, ["/path"])
test_cmd(["stemcells"], :stemcell, :list)
test_cmd(["releases"], :release, :list)
test_cmd(["deployments"], :deployment, :list)
test_cmd(["tasks"], :task, :list_running)
test_cmd(["task", "500"], :task, :track, ["500"])
test_cmd(["tasks"], :task, :list_running)
test_cmd(["tasks", "recent"], :task, :list_recent)
test_cmd(["tasks", "recent", "42"], :task, :list_recent, ["42"])
test_cmd(%w(blobs), :blob_management, :status)
test_cmd(%w(add blob foo bar), :blob_management, :add, %w(foo bar))
test_cmd(%w(upload blobs), :blob_management, :upload)
test_cmd(%w(sync blobs), :blob_management, :sync)
end
it "cancels running task and quits when ctrl-c is issued " +
"and user agrees to quit" do
runner = Bosh::Cli::Runner.new(["any", "command"])
runner.runner = {}
runner.runner.stub(:task_running?).and_return(true)
runner.stub(:kill_current_task?).and_return(true)
runner.runner.should_receive(:cancel_current_task).once
lambda { runner.handle_ctrl_c }.should raise_error SystemExit
end
it "quits when ctrl-c is issued and there is no task running" do
runner = Bosh::Cli::Runner.new(["any", "command"])
runner.runner = {}
runner.runner.stub(:task_running?).and_return(false)
lambda { runner.handle_ctrl_c }.should raise_error SystemExit
end
it "doesn't quit when user issues ctrl-c but does not want to quit" do
runner = Bosh::Cli::Runner.new(["any", "command"])
runner.runner = {}
runner.runner.stub(:task_running?).and_return(true)
runner.stub(:kill_current_task?).and_return(false)
lambda { runner.handle_ctrl_c }.should_not raise_error SystemExit
end
it "loads custom plugins" do
plugin_path = spec_asset("plugins")
$:.unshift(plugin_path)
begin
test_cmd(["banner", "foo"], :echo, :banner, ["foo"])
test_cmd(["say", "bar"], :echo, :say_color, ["bar"])
test_cmd(["say", "baz", "--color", "red"],
:echo, :say_color, ["baz", "--color", "red"])
test_cmd(["ruby", "version"], :ruby, :ruby_version)
test_cmd(["ruby", "config", "arch"], :ruby, :ruby_config, ["arch"])
ensure
$:.shift.should == plugin_path
end
end
end