jenkins_api_client 1.4.5 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/jenkins_api_client.gemspec +15 -136
  3. data/lib/jenkins_api_client/version.rb +2 -2
  4. metadata +6 -180
  5. data/.gitignore +0 -41
  6. data/.jenkins.yml +0 -9
  7. data/.travis.yml +0 -15
  8. data/CHANGELOG.md +0 -391
  9. data/CONTRIBUTORS.md +0 -3
  10. data/Gemfile +0 -20
  11. data/LICENCE +0 -21
  12. data/README.md +0 -454
  13. data/Rakefile +0 -107
  14. data/Vagrantfile +0 -83
  15. data/config/login.yml.example +0 -27
  16. data/jenkins_api_client_class_diagram.png +0 -0
  17. data/scripts/login_with_irb.rb +0 -54
  18. data/scripts/login_with_pry.rb +0 -54
  19. data/spec/func_tests/client_spec.rb +0 -109
  20. data/spec/func_tests/job_spec.rb +0 -669
  21. data/spec/func_tests/node_spec.rb.pending +0 -217
  22. data/spec/func_tests/plugin_spec.rb +0 -148
  23. data/spec/func_tests/spec_helper.rb +0 -41
  24. data/spec/func_tests/system_spec.rb +0 -84
  25. data/spec/func_tests/user_spec.rb +0 -49
  26. data/spec/func_tests/view_spec.rb +0 -276
  27. data/spec/unit_tests/build_queue_spec.rb +0 -152
  28. data/spec/unit_tests/client_spec.rb +0 -471
  29. data/spec/unit_tests/fake_http_response.rb +0 -9
  30. data/spec/unit_tests/fixtures/files/available_plugins.json +0 -1
  31. data/spec/unit_tests/fixtures/files/computer_sample.xml +0 -17
  32. data/spec/unit_tests/fixtures/files/installed_plugins.json +0 -1
  33. data/spec/unit_tests/fixtures/files/job_sample.xml +0 -16
  34. data/spec/unit_tests/fixtures/files/updatable_plugins.json +0 -1
  35. data/spec/unit_tests/job_spec.rb +0 -783
  36. data/spec/unit_tests/node_spec.rb +0 -342
  37. data/spec/unit_tests/plugin_settings/colllection_spec.rb +0 -62
  38. data/spec/unit_tests/plugin_settings/hipchat_spec.rb +0 -44
  39. data/spec/unit_tests/plugin_settings/workspace_cleanup_spec.rb +0 -31
  40. data/spec/unit_tests/plugin_spec.rb +0 -165
  41. data/spec/unit_tests/spec_helper.rb +0 -19
  42. data/spec/unit_tests/system_spec.rb +0 -76
  43. data/spec/unit_tests/user_spec.rb +0 -144
  44. data/spec/unit_tests/view_spec.rb +0 -149
  45. data/travis/hudson.model.UpdateCenter.xml +0 -7
  46. data/travis/jenkins_config.xml +0 -63
  47. data/travis/jenkins_config_with_crumb.xml +0 -67
  48. data/travis/setup.sh +0 -23
  49. data/travis/setup_crumb.sh +0 -11
  50. data/travis/spec.yml +0 -14
  51. data/travis/user_config.xml +0 -29
@@ -1,31 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- describe JenkinsApi::Client::PluginSettings::WorkspaceCleanup do
4
- describe '#configure' do
5
- context 'given a Nokogiri::XML::Builder object' do
6
- let(:xml_doc) { Nokogiri::XML("<?xml version=\"1.0\"?>\n<buildWrappers>\n</buildWrappers>\n") }
7
-
8
- it 'adds workspace cleanup configuration to the buildWrappers' do
9
- workspace_cleanup_settings = JenkinsApi::Client::PluginSettings::WorkspaceCleanup.new
10
- workspace_cleanup_settings.configure(xml_doc)
11
-
12
- expect(xml_doc.at_css('buildWrappers deleteDirs').content).to eql('false')
13
- expect(xml_doc.at_css('buildWrappers cleanupParameter').content).to eql('')
14
- expect(xml_doc.at_css('buildWrappers externalDelete').content).to eql('')
15
- end
16
-
17
- it 'uses params if given' do
18
- workspace_cleanup_settings = JenkinsApi::Client::PluginSettings::WorkspaceCleanup.new({
19
- :delete_dirs => true,
20
- :cleanup_parameter => 'foo',
21
- :external_delete => 'bar',
22
- })
23
- workspace_cleanup_settings.configure(xml_doc)
24
-
25
- expect(xml_doc.at_css('buildWrappers deleteDirs').content).to eql('true')
26
- expect(xml_doc.at_css('buildWrappers cleanupParameter').content).to eql('foo')
27
- expect(xml_doc.at_css('buildWrappers externalDelete').content).to eql('bar')
28
- end
29
- end
30
- end
31
- end
@@ -1,165 +0,0 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
- require "json"
3
-
4
- describe JenkinsApi::Client::PluginManager do
5
- context "With properly initialized Client" do
6
- before do
7
- mock_logger = Logger.new "/dev/null"
8
- @client = double
9
- @client.should_receive(:logger).and_return(mock_logger)
10
- @plugin = JenkinsApi::Client::PluginManager.new(@client)
11
- @installed_plugins = load_json_from_fixture("installed_plugins.json")
12
- @available_plugins = load_json_from_fixture("available_plugins.json")
13
- @updatable_plugins = load_json_from_fixture("updatable_plugins.json")
14
- end
15
-
16
- describe "InstanceMethods" do
17
- describe "#initialize" do
18
- it "initializes by receiving an instane of client object" do
19
- mock_logger = Logger.new "/dev/null"
20
- @client.should_receive(:logger).and_return(mock_logger)
21
- expect(
22
- lambda { JenkinsApi::Client::PluginManager.new(@client) }
23
- ).not_to raise_error
24
- end
25
- end
26
-
27
- describe "#list_installed" do
28
- it "lists all installed plugins in jenkins" do
29
- @client.should_receive(:api_get_request).
30
- with("/pluginManager", "tree=plugins[shortName,version]").
31
- and_return(@installed_plugins)
32
- plugins = @plugin.list_installed
33
- plugins.class.should == Hash
34
- plugins.size.should == @installed_plugins["plugins"].size
35
- end
36
- supported_filters = [
37
- :active, :bundled, :deleted, :downgradable, :enabled,
38
- :hasUpdate, :pinned
39
- ]
40
- supported_filters.each do |filter|
41
- it "lists all installed plugins matching filter '#{filter}'" do
42
- @client.should_receive(:api_get_request).
43
- with("/pluginManager",
44
- "tree=plugins[shortName,version,#{filter}]"
45
- ).and_return(@installed_plugins)
46
- @plugin.list_installed(filter => true).class.should == Hash
47
- end
48
- end
49
- it "lists all installed plugins matching multiple filters" do
50
- @client.should_receive(:api_get_request).
51
- with("/pluginManager",
52
- "tree=plugins[shortName,version,bundled,deleted]").
53
- and_return(@installed_plugins)
54
- @plugin.list_installed(:bundled => true, :deleted => true).class.
55
- should == Hash
56
- end
57
- it "raises an error if unsupported filter is specified" do
58
- expect(
59
- lambda { @plugin.list_installed(:unsupported => true) }
60
- ).to raise_error(ArgumentError)
61
- end
62
- end
63
-
64
- describe "#list_available" do
65
- it "lists all available plugins in jenkins update center" do
66
- @client.should_receive(:api_get_request).
67
- with("/updateCenter/coreSource", "tree=availables[name,version]").
68
- and_return(@available_plugins)
69
- @plugin.list_available.class.should == Hash
70
- end
71
- end
72
-
73
- describe "#list_updates" do
74
- it "lists all available plugin updates in jenkins update center" do
75
- @client.should_receive(:api_get_request).
76
- with("/updateCenter/coreSource", "tree=updates[name,version]").
77
- and_return(@updatable_plugins)
78
- @plugin.list_updates.class.should == Hash
79
- end
80
- end
81
-
82
- describe "#install" do
83
- it "installs a single plugin given as a string" do
84
- @client.should_receive(:api_post_request).
85
- with("/pluginManager/install",
86
- {"plugin.awesome-plugin.default" => "on"}
87
- )
88
- @plugin.install("awesome-plugin")
89
- end
90
- it "installs multiple plugins given as an array" do
91
- @client.should_receive(:api_post_request).
92
- with("/pluginManager/install",
93
- {
94
- "plugin.awesome-plugin-1.default" => "on",
95
- "plugin.awesome-plugin-2.default" => "on",
96
- "plugin.awesome-plugin-3.default" => "on"
97
- }
98
- )
99
- @plugin.install([
100
- "awesome-plugin-1",
101
- "awesome-plugin-2",
102
- "awesome-plugin-3"
103
- ])
104
- end
105
- end
106
-
107
- describe "#uninstall" do
108
- it "uninstalls a single plugin given as a string" do
109
- @client.should_receive(:api_post_request).
110
- with("/pluginManager/plugin/awesome-plugin/doUninstall")
111
- @plugin.uninstall("awesome-plugin")
112
- end
113
- it "uninstalls multiple plugins given as array" do
114
- plugins = ["awesome-plugin-1", "awesome-plugin-2", "awesome-plugin-3"]
115
- plugins.each do |plugin|
116
- @client.should_receive(:api_post_request).
117
- with("/pluginManager/plugin/#{plugin}/doUninstall")
118
- end
119
- @plugin.uninstall(plugins)
120
- end
121
- end
122
-
123
- describe "#enable" do
124
- it "enables a single plugin given as a string" do
125
- @client.should_receive(:api_post_request).
126
- with("/pluginManager/plugin/awesome-plugin/makeEnabled")
127
- @plugin.enable("awesome-plugin")
128
- end
129
- it "enables multiple plugins given as array" do
130
- plugins = ["awesome-plugin-1", "awesome-plugin-2", "awesome-plugin-3"]
131
- plugins.each do |plugin|
132
- @client.should_receive(:api_post_request).
133
- with("/pluginManager/plugin/#{plugin}/makeEnabled")
134
- end
135
- @plugin.enable(plugins)
136
- end
137
- end
138
-
139
- describe "#disable" do
140
- it "disables a single plugin given as a string" do
141
- @client.should_receive(:api_post_request).
142
- with("/pluginManager/plugin/awesome-plugin/makeDisabled")
143
- @plugin.disable("awesome-plugin")
144
- end
145
- it "disabless multiple plugins given as array" do
146
- plugins = ["awesome-plugin-1", "awesome-plugin-2", "awesome-plugin-3"]
147
- plugins.each do |plugin|
148
- @client.should_receive(:api_post_request).
149
- with("/pluginManager/plugin/#{plugin}/makeDisabled")
150
- end
151
- @plugin.disable(plugins)
152
- end
153
- end
154
-
155
- describe "#restart_required?" do
156
- it "checks if restart is required after plugin install/uninstall" do
157
- @client.should_receive(:api_get_request).
158
- with("/updateCenter", "tree=restartRequiredForCompletion").
159
- and_return({"restartRequiredForCompletion" => true})
160
- @plugin.restart_required?.should == true
161
- end
162
- end
163
- end
164
- end
165
- end
@@ -1,19 +0,0 @@
1
- require File.expand_path('../../../lib/jenkins_api_client', __FILE__)
2
- require 'logger'
3
- require 'json'
4
-
5
- RSpec.configure do |config|
6
- config.before(:each) do
7
- end
8
- end
9
-
10
- def load_json_from_fixture(file_name)
11
- JSON.load(
12
- File.read(
13
- File.expand_path(
14
- "../fixtures/files/#{file_name}",
15
- __FILE__
16
- )
17
- )
18
- )
19
- end
@@ -1,76 +0,0 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
- require File.expand_path('../fake_http_response', __FILE__)
3
-
4
- describe JenkinsApi::Client::System do
5
- context "With properly initialized Client" do
6
- before do
7
- mock_logger = Logger.new "/dev/null"
8
- mock_timeout = 300
9
- @client = double
10
- @client.should_receive(:logger).and_return(mock_logger)
11
- @client.should_receive(:timeout).and_return(mock_timeout)
12
- @system = JenkinsApi::Client::System.new(@client)
13
- end
14
-
15
- describe "InstanceMethods" do
16
- describe "#initialize" do
17
- it "initializes by receiving an instance of client object" do
18
- mock_logger = Logger.new "/dev/null"
19
- mock_timeout = 300
20
- @client.should_receive(:logger).and_return(mock_logger)
21
- @client.should_receive(:timeout).and_return(mock_timeout)
22
- expect(
23
- lambda{ JenkinsApi::Client::System.new(@client) }
24
- ).not_to raise_error
25
- end
26
- end
27
-
28
- describe "#quiet_down" do
29
- it "sends a request to put the server in quiet down mode" do
30
- @client.should_receive(:api_post_request).with("/quietDown")
31
- @system.quiet_down
32
- end
33
- end
34
-
35
- describe "#cancel_quiet_down" do
36
- it "sends a request to take the server away from quiet down mode" do
37
- @client.should_receive(:api_post_request).with("/cancelQuietDown")
38
- @system.cancel_quiet_down
39
- end
40
- end
41
-
42
- describe "#restart" do
43
- it "sends a safe restart request to the server" do
44
- @client.should_receive(:api_post_request).with("/safeRestart")
45
- @system.restart(false)
46
- end
47
- it "sends a force restart request to the server" do
48
- @client.should_receive(:api_post_request).with("/restart")
49
- @system.restart(true)
50
- end
51
- end
52
-
53
- describe "#reload" do
54
- it "sends a reload request to the server" do
55
- @client.should_receive(:api_post_request).with("/reload")
56
- @system.reload
57
- end
58
- end
59
-
60
- describe "#list_users" do
61
- it "sends a request to list the users" do
62
- @client.should_receive(:api_get_request).with("/asynchPeople")
63
- @system.list_users
64
- end
65
- end
66
-
67
- describe "#wait_for_ready" do
68
- it "exits if the response body doesn't have the wait message" do
69
- @client.should_receive(:get_root).and_return(FakeResponse.new)
70
- @system.wait_for_ready
71
- end
72
- end
73
-
74
- end
75
- end
76
- end
@@ -1,144 +0,0 @@
1
- # encoding: UTF-8
2
- require File.expand_path('../spec_helper', __FILE__)
3
-
4
- describe JenkinsApi::Client::User do
5
- context "With properly initialized Client" do
6
- ADMIN_CONFIGURE_TEXT = <<__ADMIN_CONFIGURE
7
- <!DOCTYPE html><html><head resURL="/static/70901acb" data-rooturl="" data-resurl="/static/70901acb">
8
- <title>User ‘admin’ Configuration [Jenkins]</title>
9
- <link rel="stylesheet" href="/static/70901acb/css/layout-common.css" type="text/css" />
10
- <link rel="stylesheet" href="/static/70901acb/css/style.css" type="text/css" />
11
- <input name="_.fullName" type="text" class="setting-input " value="admin" />/td></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">Description</td><td class="setting-main"><textarea name="_.description" rows="5" class="setting-input "></textarea><div class="textarea-handle"></div></td><td class="setting-help"><a helpURL="/help/user/description.html" href="#" class="help-button"><img src="/static/70901acb/images/16x16/help.png" alt="Help for feature: Description" style="width: 16px; height: 16px; " class="icon-help icon-sm" /></a></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="help-area"><td></td><td colspan="2"><div class="help">Loading...</div></td><td></td></tr><link rel='stylesheet' href='/adjuncts/70901acb/lib/form/section_.css' type='text/css' /><script src='/adjuncts/70901acb/lib/form/section_.js' type='text/javascript'></script><tr name="userProperty0" style="display:none" class="row-set-start row-group-start"></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">API Token</div></td></tr><tr name="userProperty1" style="display:none" class="row-set-start row-group-start"></tr><tr><td></td><td></td><td><script src='/adjuncts/70901acb/lib/form/advanced/advanced.js' type='text/javascript'></script><div style="text-align:left" class="advancedLink"><span style="display: none" id="id245"><img src="/static/70901acb/images/24x24/notepad.png" tooltip="One or more fields in this block have been edited." style="width: 24px; height: 24px; vertical-align: baseline" class="icon-notepad icon-md" /></span> <input type="button" value="Show API Token..." class="advanced-button advancedButton" /></div><table class="advancedBody"><tbody><tr><td class="setting-leftspace"> </td><td class="setting-name">User ID</td><td class="setting-main"><input readonly="readonly" name="_." type="text" class="setting-input " value="admin" /></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">API Token</td><td class="setting-main"><input readonly="readonly" name="_.apiToken" id="apiToken" type="text" class="setting-input " value="12345678" /></td><td class="setting-help"><a helpURL="/descriptor/jenkins.security.ApiTokenProperty/help/apiToken" href="#" class="help-button"><img src="/static/70901acb/images/16x16/help.png" alt="Help for feature: API Token" style="width: 16px; height: 16px; " class="icon-help icon-sm" /></a></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="help-area"><td></td><td colspan="2"><div class="help">Loading...</div></td><td></td></tr><tr><td class="setting-leftspace"> </td><td class="setting-name"></td><td class="setting-main"><div style="float:right"><input onclick="validateButton('/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/changeToken','',this)" type="button" value="Change API Token" class="yui-button validate-button" /></div><div style="display:none;"><img src="/static/70901acb/images/spinner.gif" />
12
- <input name="email.address" type="text" class="setting-input " value="" /></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr><td colspan="2"></td><td class="setting-description">Your e-mail address, like <tt>joe.chin@sun.com</tt></td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">My Views</div></td></tr><tr name="userProperty4" style="display:none" class="row-set-start row-group-start"></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">Default View</td><td class="setting-main">
13
- <input checkUrl="'/user/admin/my-views/viewExistsCheck?value='+encodeURIComponent(this.value)+'&amp;exists=true'" name="_.primaryViewName" type="text" class="setting-input validated " value="" /></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr><td colspan="2"></td><td class="setting-description">The view selected by default when navigating to the users private views</td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">SSH Public Keys</div></td></tr><tr name="userProperty7" style="display:none" class="row-set-start row-group-start"></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">SSH Public Keys</td><td class="setting-main"><textarea name="_.authorizedKeys" rows="5" class="setting-input "></textarea><div class="textarea-handle"></div></td><td class="setting-help"><a helpURL="/descriptor/org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl/help/authorizedKeys" href="#" class="help-button"><img src="/static/70901acb/images/16x16/help.png" alt="Help for feature: SSH Public Keys" style="width: 16px; height: 16px; " class="icon-help icon-sm" /></a></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="help-area"><td></td><td colspan="2"><div class="help">Loading...</div></td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">Setting for search</div></td></tr><tr name="userProperty8" style="display:none" class="row-set-start row-group-start"></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">Case-sensitivity</td><td class="setting-main"><input name="insensitiveSearch" type="checkbox" class=" " /><label class="attach-previous">Insensitive search tool</label></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div id="bottom-sticker"><div class="bottom-sticker-inner"><input name="Submit" type="submit" value="Save" class="submit-button primary" /><script src='/adjuncts/70901acb/lib/form/apply/apply.js' type='text/javascript'></script><input type="hidden" name="core:apply" value="" /><input name="Apply" type="button" value="Apply" class="apply-button applyButton" /></div></div></td></tr></table></form><script src='/adjuncts/70901acb/lib/form/confirm.js' type='text/javascript'></script></div></div><footer><div class="container-fluid"><div class="row"><div class="col-md-6" id="footer"></div><div class="col-md-18"><span class="page_generated">Page generated: Sep 10, 2016 12:54:41 AM UTC</span><span class="rest_api"><a href="api/">REST API</a></span><span class="jenkins_ver"><a href="http://jenkins-ci.org/">Jenkins ver. 2.7.4</a></span></div></div></div></footer></body></html>
14
- __ADMIN_CONFIGURE
15
-
16
- FRED_TXT = <<__FRED
17
- {
18
- "absoluteUrl" : "https://myjenkins.example.com/jenkins/user/fred",
19
- "description" : "",
20
- "fullName" : "Fred Flintstone",
21
- "id" : "fred",
22
- "property" : [
23
- {
24
- },
25
- {
26
- },
27
- {
28
- "address" : "fred@slaterockandgravel.com"
29
- },
30
- {
31
- },
32
- {
33
- },
34
- {
35
- "insensitiveSearch" : false
36
- }
37
- ]
38
- }
39
- __FRED
40
-
41
- WILMA_TXT = <<__WILMA
42
- {
43
- "absoluteUrl" : "https://myjenkins.example.com/jenkins/user/wilma",
44
- "description" : "",
45
- "fullName" : "wilma",
46
- "id" : "wilma",
47
- "property" : [
48
- {
49
- },
50
- {
51
- },
52
- {
53
- },
54
- {
55
- },
56
- {
57
- },
58
- {
59
- }
60
- ]
61
- }
62
- __WILMA
63
-
64
- FRED_JSON = JSON.parse(FRED_TXT)
65
- WILMA_JSON = JSON.parse(WILMA_TXT)
66
- PEOPLE_JSON = JSON.parse(<<__PEEPS
67
- {
68
- "users" : [
69
- {
70
- "lastChange" : 1375293464494,
71
- "project" : {
72
- "name" : "a project",
73
- "url" : "a url to a project"
74
- },
75
- "user" : {
76
- "absoluteUrl" : "a url to a user",
77
- "fullName" : "Fred Flintstone"
78
- }
79
- }
80
- ]
81
- }
82
- __PEEPS
83
- )
84
-
85
- USERLIST_JSON = JSON.parse(<<__USERLIST
86
- {
87
- "fred": #{FRED_TXT}
88
- }
89
- __USERLIST
90
- )
91
-
92
- before do
93
- mock_logger = Logger.new "/dev/null"
94
- mock_timeout = 300
95
- @client = double
96
- @client.should_receive(:logger).and_return(mock_logger)
97
- @client.should_receive(:timeout).and_return(mock_timeout)
98
- @client.stub(:api_get_request).with('/asynchPeople').and_return(PEOPLE_JSON)
99
- @client.stub(:api_get_request).with('/user/Fred%20Flintstone').and_return(FRED_JSON)
100
- @client.stub(:api_get_request).with('/user/fred').and_return(FRED_JSON)
101
- @client.stub(:api_get_request).with('/user/wilma').and_return(WILMA_JSON)
102
- @client.stub(:api_get_request).with('/user/admin/configure', nil, '').and_return(ADMIN_CONFIGURE_TEXT)
103
- @user = JenkinsApi::Client::User.new(@client)
104
- end
105
-
106
- describe "InstanceMethods" do
107
- describe "#initialize" do
108
- it "initializes by receiving an instance of client object" do
109
- mock_logger = Logger.new "/dev/null"
110
- mock_timeout = 300
111
- @client.should_receive(:logger).and_return(mock_logger)
112
- @client.should_receive(:timeout).and_return(mock_timeout)
113
- expect(
114
- lambda{ JenkinsApi::Client::User.new(@client) }
115
- ).not_to raise_error
116
- end
117
- end
118
-
119
- describe "#list" do
120
- it "sends a request to list the users" do
121
- @user.list.should eq(USERLIST_JSON)
122
- end
123
- end
124
-
125
- describe "#get" do
126
- it "returns dummy user if user cannot be found" do
127
- # This is artifact of Jenkins - It'll create a user to match the name you give it - even on a fetch
128
- @user.get("wilma").should eq(WILMA_JSON)
129
- end
130
-
131
- it "returns valid user if user can be found" do
132
- @user.get("fred").should eq(FRED_JSON)
133
- end
134
- end
135
-
136
- describe "#get_api_token" do
137
- it "returns the user's API token" do
138
- @user.get_api_token('admin').should eq('12345678')
139
- end
140
- end
141
-
142
- end
143
- end
144
- end
@@ -1,149 +0,0 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- describe JenkinsApi::Client::View do
4
- context "With properly initialized Client" do
5
- before do
6
- mock_logger = Logger.new "/dev/null"
7
- @client = double
8
- @client.should_receive(:logger).and_return(mock_logger)
9
- @view = JenkinsApi::Client::View.new(@client)
10
- @sample_views_json = {
11
- "views" => [
12
- {"name" => "test_view"},
13
- {"name" => "test_view2"}
14
- ]
15
- }
16
- @sample_view_json = {
17
- "jobs" => [
18
- {"name" => "test_job"},
19
- {"name" => "test_job2"}
20
- ]
21
- }
22
- end
23
-
24
- describe "InstanceMethods" do
25
- describe "#initialize" do
26
- it "initializes by receiving an instance of client object" do
27
- mock_logger = Logger.new "/dev/null"
28
- @client.should_receive(:logger).and_return(mock_logger)
29
- expect(
30
- lambda { JenkinsApi::Client::View.new(@client) }
31
- ).not_to raise_error
32
- end
33
- end
34
-
35
- describe "#create" do
36
- it "creates a view by accepting a name" do
37
- @client.should_receive(:api_post_request)
38
- @view.create("test_view")
39
- end
40
- end
41
-
42
- describe "#delete" do
43
- it "deletes the view with the given name" do
44
- @client.should_receive(:api_post_request).with("/view/test_view/doDelete")
45
- @view.delete("test_view")
46
- end
47
- end
48
-
49
- describe "#list" do
50
- it "lists all views" do
51
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
52
- response = @view.list
53
- response.class.should == Array
54
- response.size.should == 2
55
- end
56
-
57
- it "lists views matching specific filter" do
58
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
59
- response = @view.list("test_view2")
60
- response.class.should == Array
61
- response.size.should == 1
62
- end
63
-
64
- it "lists views matching specific filter and matches case" do
65
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
66
- response = @view.list("TEST_VIEW", false)
67
- response.class.should == Array
68
- response.size.should == 0
69
- end
70
- end
71
-
72
- describe "#exists?" do
73
- it "returns true a view that exists" do
74
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
75
- @view.exists?("test_view2").should == true
76
- end
77
-
78
- it "returns false for non-existent view" do
79
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
80
- @view.exists?("i_am_not_there").should == false
81
- end
82
- end
83
-
84
- describe "#list_jobs" do
85
- it "lists all jobs in the given view" do
86
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
87
- @client.should_receive(:api_get_request).with("/view/test_view").and_return(@sample_view_json)
88
- response = @view.list_jobs("test_view")
89
- response.class.should == Array
90
- response.size.should == 2
91
- end
92
-
93
- it "raises an error if called on a non-existent view" do
94
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
95
- expect(
96
- lambda { @view.list_jobs("i_am_not_there") }
97
- ).to raise_error
98
- end
99
- end
100
-
101
- describe "#list_jobs_with_details" do
102
- it "lists all jobs with details in the given view" do
103
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
104
- @client.should_receive(:api_get_request).with("/view/test_view").and_return(
105
- @sample_view_json)
106
- response = @view.list_jobs_with_details("test_view")
107
- response.class.should == Array
108
- response.size.should == @sample_view_json["jobs"].size
109
- end
110
-
111
- it "raises an error if called on a non-existent view" do
112
- @client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
113
- expect(
114
- lambda { @view.list_jobs_with_details("i_am_not_there") }
115
- ).to raise_error
116
- end
117
- end
118
-
119
- describe "#add_job" do
120
- it "adds the specified job to the specified view" do
121
- @client.should_receive(:api_post_request)
122
- @view.add_job("test_view", "test_job3")
123
- end
124
- end
125
-
126
- describe "#remove_job" do
127
- it "removes the specified job to the specified view" do
128
- @client.should_receive(:api_post_request)
129
- @view.remove_job("test_view", "test_job")
130
- end
131
- end
132
-
133
- describe "#get_config" do
134
- it "obtains the config from the server for the specified view" do
135
- @client.should_receive(:get_config).with("/view/test_view")
136
- @view.get_config("test_view")
137
- end
138
- end
139
-
140
- describe "#post_config" do
141
- it "posts the config to the server for the specified view" do
142
- @client.should_receive(:post_config).with("/view/test_view/config.xml", "<view>test_view</view>")
143
- @view.post_config("test_view", "<view>test_view</view>")
144
- end
145
- end
146
-
147
- end
148
- end
149
- end