jenkins-plugin-runtime 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,218 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Jenkins::Launcher do
4
+ before :each do
5
+ @native = mock("native")
6
+ @starter = mock("starter")
7
+ @cmd_proc = mock("proc")
8
+ @native.stub(:launch).and_return(@starter)
9
+ @starter.stub(:start).and_return(@cmd_proc)
10
+ @launcher = Jenkins::Launcher.new(@native)
11
+ end
4
12
 
5
13
  it "can be instantiated" do
6
14
  Jenkins::Launcher.new
7
15
  end
16
+
17
+ describe "execute" do
18
+ it "passes a simple command to a native launcher" do
19
+ @starter.should_receive(:envs).with({})
20
+ @starter.should_receive(:cmdAsSingleString).with("ls")
21
+ @cmd_proc.should_receive(:join).and_return(0)
22
+ @launcher.execute("ls").should == 0
23
+ end
24
+
25
+ describe "environment argument" do
26
+ it "passes env to a native launcher" do
27
+ @starter.should_receive(:envs).with({"foo" => "bar"})
28
+ @starter.should_receive(:cmdAsSingleString).with("ls")
29
+ @cmd_proc.should_receive(:join).and_return(0)
30
+ @launcher.execute({"foo" => "bar"}, "ls").should == 0
31
+ end
32
+
33
+ it "stringifies env for a native launcher" do
34
+ @starter.should_receive(:envs).with({"foo" => "bar", "baz" => "1"})
35
+ @starter.should_receive(:cmdAsSingleString).with("ls")
36
+ @cmd_proc.should_receive(:join).and_return(0)
37
+ @launcher.execute({:foo => :bar, :baz => 1}, "ls").should == 0
38
+ end
39
+ end
40
+
41
+ describe "option argument" do
42
+ it "passes pwd to a native launcher" do
43
+ @starter.should_receive(:envs).with({})
44
+ @starter.should_receive(:pwd).with(".")
45
+ @starter.should_receive(:cmdAsSingleString).with("ls")
46
+ @cmd_proc.should_receive(:join).and_return(0)
47
+ @launcher.execute("ls", :chdir => ".").should == 0
48
+ end
49
+
50
+ it "passes an output stream to a native launcher" do
51
+ ous = mock("OutputStream")
52
+ ous.should_receive(:to_outputstream).and_return(ous)
53
+ @starter.should_receive(:envs).with({})
54
+ @starter.should_receive(:stdout).with(ous)
55
+ @starter.should_receive(:cmdAsSingleString).with("ls")
56
+ @cmd_proc.should_receive(:join).and_return(0)
57
+ @launcher.execute("ls", :out => ous).should == 0
58
+ end
59
+
60
+ it "passes native listener as an output stream to a native launcher" do
61
+ ous = Jenkins::Model::Listener.new
62
+ plugin = mock("Plugin")
63
+ Jenkins::Plugin.should_receive(:instance).and_return(plugin)
64
+ plugin.should_receive(:export).with(ous).and_return(ous)
65
+
66
+ @starter.should_receive(:envs).with({})
67
+ @starter.should_receive(:stdout).with(ous)
68
+ @starter.should_receive(:cmdAsSingleString).with("ls")
69
+ @cmd_proc.should_receive(:join).and_return(0)
70
+ @launcher.execute("ls", :out => ous).should == 0
71
+ end
72
+
73
+ it "passes an input stream to a native launcher" do
74
+ ins = mock("InputStream")
75
+ ins.should_receive(:to_inputstream).and_return(ins)
76
+ @starter.should_receive(:envs).with({})
77
+ @starter.should_receive(:stdin).with(ins)
78
+ @starter.should_receive(:cmdAsSingleString).with("ls")
79
+ @cmd_proc.should_receive(:join).and_return(0)
80
+ @launcher.execute("ls", :in => ins).should == 0
81
+ end
82
+
83
+ it "passes an error stream to a native launcher" do
84
+ ous = mock("InputStream")
85
+ ous.should_receive(:to_outputstream).and_return(ous)
86
+ @starter.should_receive(:envs).with({})
87
+ @starter.should_receive(:stderr).with(ous)
88
+ @starter.should_receive(:cmdAsSingleString).with("ls")
89
+ @cmd_proc.should_receive(:join).and_return(0)
90
+ @launcher.execute("ls", :err => ous).should == 0
91
+ end
92
+ end
93
+
94
+ describe "command argument" do
95
+ it "passes a command to a native launcher" do
96
+ @starter.should_receive(:envs).with({})
97
+ @starter.should_receive(:cmdAsSingleString).with("echo foo bar")
98
+ @cmd_proc.should_receive(:join).and_return(0)
99
+ @launcher.execute("echo foo bar").should == 0
100
+ end
101
+
102
+ it "passes a stringified command to a native launcher" do
103
+ @starter.should_receive(:envs).with({})
104
+ @starter.should_receive(:cmdAsSingleString).with("ls")
105
+ @cmd_proc.should_receive(:join).and_return(0)
106
+ @launcher.execute(:ls).should == 0
107
+ end
108
+
109
+ it "passes a command as Array to a native launcher" do
110
+ @starter.should_receive(:envs).with({})
111
+ @starter.should_receive(:cmds).with(["echo", "foo", "bar"])
112
+ @cmd_proc.should_receive(:join).and_return(0)
113
+ @launcher.execute("echo", "foo", "bar").should == 0
114
+ end
115
+ end
116
+
117
+ describe "argument processing" do
118
+ it "passes env, a command and options to a native launcher" do
119
+ ins = mock("InputStream")
120
+ ins.should_receive(:to_inputstream).and_return(ins)
121
+ ous = mock("OutputStream")
122
+ ous.should_receive(:to_outputstream).and_return(ous)
123
+ errs = mock("ErrorOutputStream")
124
+ errs.should_receive(:to_outputstream).and_return(errs)
125
+ @starter.should_receive(:envs).with({"FOO" => "BAR"})
126
+ @starter.should_receive(:cmds).with(["echo", "hello", "world"])
127
+ @starter.should_receive(:stdin).with(ins)
128
+ @starter.should_receive(:stdout).with(ous)
129
+ @starter.should_receive(:stderr).with(errs)
130
+
131
+ @cmd_proc.should_receive(:join).and_return(1)
132
+ @launcher.execute({"FOO" => "BAR"}, "echo", "hello", "world", :in => ins, :out => ous, :err => errs).should == 1
133
+ end
134
+
135
+ it "converts env with to_hash for passing through" do
136
+ env = mock("hashy")
137
+ env.should_receive(:to_hash).and_return(:FOO => :BAR)
138
+ @starter.should_receive(:envs).with({"FOO" => "BAR"})
139
+ @starter.should_receive(:cmds).with(["echo", "hello", "world"])
140
+ @cmd_proc.should_receive(:join).and_return(1)
141
+ @launcher.execute(env, "echo", "hello", "world").should == 1
142
+ end
143
+
144
+ it "converts options with to_hash for processing" do
145
+ ous = mock("OutputStream")
146
+ ous.should_receive(:to_outputstream).and_return(ous)
147
+ env = mock("hashy env")
148
+ env.should_receive(:to_hash).and_return(:FOO => :BAR)
149
+ opt = mock("hashy opt")
150
+ opt.should_receive(:to_hash).and_return(:chdir => ".", :out => ous)
151
+ @starter.should_receive(:envs).with({"FOO" => "BAR"})
152
+ @starter.should_receive(:cmds).with(["echo", "hello", "world"])
153
+ @starter.should_receive(:pwd).with(".")
154
+ @starter.should_receive(:stdout).with(ous)
155
+ @cmd_proc.should_receive(:join).and_return(1)
156
+ @launcher.execute(env, "echo", "hello", "world", opt).should == 1
157
+ end
158
+ end
159
+ end
160
+
161
+ describe "spawn" do
162
+ it "works like execute without waiting for command execution" do
163
+ ous = mock("OutputStream")
164
+ ous.should_receive(:to_outputstream).and_return(ous)
165
+ env = mock("hashy env")
166
+ env.should_receive(:to_hash).and_return(:FOO => :BAR)
167
+ opt = mock("hashy opt")
168
+ opt.should_receive(:to_hash).and_return(:chdir => ".", :out => ous)
169
+ @starter.should_receive(:envs).with({"FOO" => "BAR"})
170
+ @starter.should_receive(:cmds).with(["echo", "hello", "world"])
171
+ @starter.should_receive(:pwd).with(".")
172
+ @starter.should_receive(:stdout).with(ous)
173
+ @cmd_proc.should_receive(:join).and_return(2)
174
+ @launcher.spawn(env, "echo", "hello", "world", opt).join.should == 2
175
+ end
176
+ end
177
+
178
+ describe Jenkins::Launcher::Proc do
179
+
180
+ subject { Jenkins::Launcher::Proc.new(@cmd_proc) }
181
+
182
+ it "passes an alive? call to a native proc" do
183
+ @cmd_proc.should_receive(:isAlive).and_return(true)
184
+ subject.alive?.should == true
185
+ end
186
+
187
+ it "passes a join call to a native proc" do
188
+ @cmd_proc.should_receive(:join).and_return(0)
189
+ subject.join.should == 0
190
+ end
191
+
192
+ it "passes a kill call to a native proc" do
193
+ @cmd_proc.should_receive(:kill).and_return(:guard)
194
+ subject.kill.should be_nil
195
+ end
196
+
197
+ it "passes a stdin call to a native proc" do
198
+ ins = mock("InputStream")
199
+ ins.should_receive(:to_io).and_return(ins)
200
+ @cmd_proc.should_receive(:getStdin).and_return(ins)
201
+ subject.stdin.should == ins
202
+ end
203
+
204
+ it "passes a stdout call to a native proc" do
205
+ ous = mock("OutputStream")
206
+ ous.should_receive(:to_io).and_return(ous)
207
+ @cmd_proc.should_receive(:getStdout).and_return(ous)
208
+ subject.stdout.should == ous
209
+ end
210
+
211
+ it "passes a stderr call to a native proc" do
212
+ errs = mock("OutputStream")
213
+ errs.should_receive(:to_io).and_return(errs)
214
+ @cmd_proc.should_receive(:getStderr).and_return(errs)
215
+ subject.stderr.should == errs
216
+ end
217
+ end
8
218
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'jenkins/model/action'
2
+
3
3
  describe Jenkins::Model::Action do
4
4
 
5
5
  it "has the same display_name semantics as Model" do
@@ -35,8 +35,7 @@ describe Jenkins::Model::Action do
35
35
  private
36
36
 
37
37
  def new_action(&body)
38
- action = Class.new
39
- action.send(:include, Jenkins::Model::Action)
38
+ action = Class.new(Jenkins::Model::Action)
40
39
  action.class_eval(&body) if block_given?
41
40
  return action
42
41
  end
@@ -2,10 +2,29 @@ require 'spec_helper'
2
2
 
3
3
  describe Jenkins::Model::Build do
4
4
 
5
+ before :each do
6
+ @native = mock("AbstractBuild")
7
+ @subject = Jenkins::Model::Build.new(@native)
8
+ end
9
+
5
10
  it "can be instantiated" do
6
- Jenkins::Model::Build.new(mock(Java.hudson.model.AbstractBuild))
11
+ Jenkins::Model::Build.new
12
+ end
13
+
14
+ it "returns workspace path" do
15
+ fs = Jenkins::FilePath.new(nil)
16
+ fs.should_receive(:getRemote).and_return(".")
17
+ @native.should_receive(:getWorkspace).and_return(fs)
18
+ @subject.workspace.to_s.should == "."
7
19
  end
8
20
 
9
- # TODO: spec for build_var and env
10
- # Just a mocking and method invocation checks are enough?
21
+ it "returns build variables as Hash-like" do
22
+ @native.should_receive(:getBuildVariables).and_return("FOO" => "BAR")
23
+ @subject.build_var.should == {"FOO" => "BAR"}
24
+ end
25
+
26
+ it "returns environment variables as Hash-like" do
27
+ @native.should_receive(:getEnvironment).with(nil).and_return("FOO" => "BAR")
28
+ @subject.env.should == {"FOO" => "BAR"}
29
+ end
11
30
  end
@@ -9,23 +9,25 @@ describe Jenkins::Model::Listener do
9
9
  end
10
10
 
11
11
  it "logs messages" do
12
- @listener.log('Hi')
13
- @output.toString.should eql "Hi"
12
+ @listener.info('Hi')
13
+ @output.toString.should eql "Hi\n"
14
14
  end
15
15
 
16
16
  it "logs errors" do
17
17
  @listener.error('Oh no!')
18
- @output.toString.should match /^ERROR: Oh no!/
18
+ @output.toString.should match /^ERROR: Oh no/
19
19
  end
20
20
 
21
21
  it "logs fatal errors" do
22
22
  @listener.fatal('boom!')
23
- @output.toString.should match /^FATAL: boom!/
23
+ @output.toString.should match /^FATAL: boom/
24
24
  end
25
25
 
26
- it "logs hyperlinks" do
27
- @java.should_receive(:hyperlink).with("/foo/bar", "click here")
28
- @listener.hyperlink("/foo/bar", "click here")
26
+ it "logs if only severe" do
27
+ @listener.level = Logger::INFO
28
+ @listener.debug "debug"
29
+ @listener.info "info"
30
+ @output.toString.should == "info\n"
29
31
  end
30
32
  end
31
33
 
@@ -13,6 +13,17 @@ describe Jenkins::Plugin::Proxies::Builder do
13
13
  @object.should_receive(:prebuild).with(@build, @listener)
14
14
  @builder.prebuild(@jBuild, @jListener)
15
15
  end
16
+
17
+ it "returns true whatever Ruby side impl returns" do
18
+ @object.should_receive(:prebuild).and_return(false)
19
+ @builder.prebuild(@jBuild, @jListener).should == true
20
+ end
21
+
22
+ it "returns false when Ruby side impl raise an Error" do
23
+ @object.should_receive(:prebuild).and_raise(NoMethodError)
24
+ @jListener.should_receive(:error)
25
+ @builder.prebuild(@jBuild, @jListener).should == false
26
+ end
16
27
  end
17
28
 
18
29
  describe "perform" do
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jenkins::Plugin::Proxies::Publisher do
4
+ include ProxyHelper
5
+
6
+ before do
7
+ @object = mock(Jenkins::Tasks::Publisher)
8
+ @builder = Jenkins::Plugin::Proxies::Publisher.new(@plugin, @object)
9
+ end
10
+
11
+ describe "prebuild" do
12
+ it "calls through to its implementation" do
13
+ @object.should_receive(:prebuild).with(@build, @listener)
14
+ @builder.prebuild(@jBuild, @jListener)
15
+ end
16
+
17
+ it "returns true whatever Ruby side impl returns" do
18
+ @object.should_receive(:prebuild).and_return(false)
19
+ @builder.prebuild(@jBuild, @jListener).should == true
20
+ end
21
+
22
+ it "returns false when Ruby side impl raise an Error" do
23
+ @object.should_receive(:prebuild).and_raise(NoMethodError)
24
+ @jListener.should_receive(:error)
25
+ @builder.prebuild(@jBuild, @jListener).should == false
26
+ end
27
+ end
28
+
29
+ describe "perform" do
30
+ it "calls through to its implementation" do
31
+ @object.should_receive(:perform).with(@build, @launcher, @listener)
32
+ @builder.perform(@jBuild, @jLauncher, @jListener)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jenkins::Plugin::Proxies::RootAction do
4
+ include ProxyHelper
5
+
6
+ before do
7
+ @object = mock(Jenkins::Model::RootAction)
8
+ @root_action = Jenkins::Plugin::Proxies::RootAction.new(@plugin, @object)
9
+ end
10
+
11
+ describe "getDisplayName" do
12
+ it "calls through to its implementation" do
13
+ @object.should_receive(:display_name)
14
+ @root_action.getDisplayName
15
+ end
16
+ end
17
+
18
+ describe "getIconFileName" do
19
+ it "calls through to its implementation" do
20
+ @object.should_receive(:icon)
21
+ @root_action.getIconFileName
22
+ end
23
+ end
24
+
25
+ describe "getUrlName" do
26
+ it "calls through to its implementation" do
27
+ @object.should_receive(:url_path)
28
+ @root_action.getUrlName
29
+ end
30
+ end
31
+ end
@@ -41,7 +41,7 @@ describe Jenkins::Plugin::Proxies do
41
41
  end
42
42
 
43
43
  describe "and there is not an appropriate proxy class registered for it" do
44
- it "raises an exception on import" do
44
+ it "raises an exception on export" do
45
45
  expect {@proxies.export(@object)}.should raise_error
46
46
  end
47
47
  end
@@ -133,6 +133,22 @@ describe Jenkins::Plugin::Proxies do
133
133
 
134
134
  end
135
135
 
136
+ describe "importing an unmapped native java object" do
137
+ before do
138
+ @umappable = java.lang.Object.new
139
+ @import = @proxies.import(@umappable)
140
+ end
141
+ it "maps it do an opaque native java object structure" do
142
+ @import.native.should be @umappable
143
+ end
144
+ it "reuses the same opaque proxy on subsequent imports" do
145
+ @proxies.import(@umappable).should be @import
146
+ end
147
+ it "exports the object as the original java value" do
148
+ @proxies.export(@import).should be @umappable
149
+ end
150
+ end
151
+
136
152
  private
137
153
 
138
154
  def proxy_class
@@ -1,7 +1,72 @@
1
1
  require 'spec_helper'
2
+ require 'tmpdir'
2
3
 
3
4
  describe Jenkins::Plugin do
4
5
  it "is unbelievable that I don't have a spec for this class" do
5
6
  Jenkins::Plugin.instance_method(:initialize).should_not be_nil
6
7
  end
8
+
9
+ describe "when plugin loads models" do
10
+ include SpecHelper
11
+
12
+ it "only loads *.rb file" do
13
+ mktmpdir do |dir|
14
+ # - foo.rb
15
+ # - bar/
16
+ # - bar1.rb
17
+ # - bar2.rb
18
+ # - baz/
19
+ # - baz1.rb
20
+ # - baz2.rb
21
+ # - qux.rb
22
+ # - quux.rb
23
+ create_file(File.join(dir, "foo.rb"), "$T << :foo")
24
+ Dir.mkdir(File.join(dir, "bar"))
25
+ create_file(File.join(dir, "bar", "bar1.rb"), "$T << :bar1")
26
+ create_file(File.join(dir, "bar", "bar2.rb"), "$T << :bar2")
27
+ Dir.mkdir(File.join(dir, "bar", "baz"))
28
+ create_file(File.join(dir, "bar", "baz", "baz1.rb"), "$T << :baz1")
29
+ create_file(File.join(dir, "bar", "baz", "baz2.rb"), "$T << :baz2")
30
+ create_file(File.join(dir, "bar", "qux.rb"), "$T << :qux")
31
+ create_file(File.join(dir, "quux.rb"), "$T << :quux")
32
+ file = mock(:name => 'java.io.File')
33
+ file.stub(:getPath).and_return(dir)
34
+ peer = mock(:name => 'org.jenkinsci.ruby.RubyPlugin')
35
+ peer.stub(:getModelsPath).and_return(file)
36
+ plugin = Jenkins::Plugin.new(peer)
37
+
38
+ $T = []
39
+ plugin.load_models
40
+ foo = $T.index(:foo)
41
+ bar1 = $T.index(:bar1)
42
+ bar2 = $T.index(:bar2)
43
+ baz1 = $T.index(:baz1)
44
+ baz2 = $T.index(:baz2)
45
+ qux = $T.index(:qux)
46
+ quux = $T.index(:quux)
47
+
48
+ bar1.should > foo
49
+ bar1.should > quux
50
+
51
+ bar2.should > foo
52
+ bar2.should > quux
53
+
54
+ baz1.should > foo
55
+ baz1.should > bar1
56
+ baz1.should > bar2
57
+ baz1.should > qux
58
+ baz1.should > quux
59
+
60
+ baz2.should > foo
61
+ baz2.should > bar1
62
+ baz2.should > bar2
63
+ baz2.should > qux
64
+ baz2.should > quux
65
+
66
+ qux.should > foo
67
+ qux.should > quux
68
+ [foo, bar1, bar2, baz1, baz2, qux, quux].should_not include(-1)
69
+ end
70
+ end
71
+ end
7
72
  end