subordinate 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,22 @@
1
+ # Queue Spec
1
2
  require "spec_helper"
2
3
 
3
- # Queue Spec
4
4
  describe Subordinate::Client do
5
5
  before do
6
6
  Subordinate.reset!
7
7
  Subordinate.configure do |c|
8
- c.subdomain = ENV["SUBDOMAIN"]
9
- c.domain = ENV["DOMAIN"]
10
- c.port = ENV["PORT"]
8
+ c.subdomain = "jenkins"
9
+ c.domain = "example.com"
10
+ c.port = 8080
11
11
  c.ssl = false
12
12
  end
13
13
  end
14
- let(:subordinate) { Subordinate::Client.new(:username => ENV["USERNAME"], :api_token => ENV["TOKEN"]) }
15
14
 
16
- describe "#build_queue", :vcr do
15
+ let(:subordinate) { Subordinate::Client.new(:username => "someusername", :api_token => "sometoken") }
16
+
17
+ describe "#build_queue" do
18
+ before(:each) { stub_jenkins(:get, "/queue/api/json", "queue.json") }
19
+
17
20
  let(:current_response) { subordinate.build_queue }
18
21
 
19
22
  it "returns the build queue response" do
@@ -26,4 +29,4 @@ describe Subordinate::Client do
26
29
  end
27
30
  end
28
31
  end
29
- end
32
+ end
@@ -1,19 +1,22 @@
1
+ # System Spec
1
2
  require "spec_helper"
2
3
 
3
- # Client Spec
4
4
  describe Subordinate::Client do
5
5
  before do
6
6
  Subordinate.reset!
7
7
  Subordinate.configure do |c|
8
- c.subdomain = ENV["SUBDOMAIN"]
9
- c.domain = ENV["DOMAIN"]
10
- c.port = ENV["PORT"]
8
+ c.subdomain = "jenkins"
9
+ c.domain = "example.com"
10
+ c.port = 8080
11
11
  c.ssl = false
12
12
  end
13
13
  end
14
- let(:subordinate) { Subordinate::Client.new(:username => ENV["USERNAME"], :api_token => ENV["TOKEN"]) }
15
14
 
16
- describe "#root", :vcr do
15
+ let(:subordinate) { Subordinate::Client.new(:username => "someusername", :api_token => "sometoken") }
16
+
17
+ describe "#root" do
18
+ before(:each) { stub_jenkins(:get, "/api/json", "base.json") }
19
+
17
20
  let(:current_response) { subordinate.root }
18
21
 
19
22
  it "returns the root response", :vcr do
@@ -120,4 +123,4 @@ describe Subordinate::Client do
120
123
  subordinate.safe_restart.should == 302
121
124
  end
122
125
  end
123
- end
126
+ end
@@ -1,21 +1,23 @@
1
+ # View Spec
1
2
  require "spec_helper"
2
3
 
3
- # View Spec
4
4
  describe Subordinate::Client do
5
5
  before do
6
6
  Subordinate.reset!
7
7
  Subordinate.configure do |c|
8
- c.subdomain = ENV["SUBDOMAIN"]
9
- c.domain = ENV["DOMAIN"]
10
- c.port = ENV["PORT"]
8
+ c.subdomain = "jenkins"
9
+ c.domain = "example.com"
10
+ c.port = 8080
11
11
  c.ssl = false
12
12
  end
13
13
  end
14
14
 
15
- let(:subordinate) { Subordinate::Client.new(:username => ENV["USERNAME"], :api_token => ENV["TOKEN"]) }
15
+ let(:subordinate) { Subordinate::Client.new(:username => "someusername", :api_token => "sometoken") }
16
16
 
17
- describe "#view", :vcr do
18
- let(:current_response) { subordinate.view(ENV["VIEW"]) }
17
+ describe "#view" do
18
+ before(:each) { stub_jenkins(:get, "/view/someview/api/json", "view.json") }
19
+
20
+ let(:current_response) { subordinate.view("someview") }
19
21
 
20
22
  it "returns the view response" do
21
23
  current_response.should_not be_nil
@@ -44,7 +46,9 @@ describe Subordinate::Client do
44
46
  end
45
47
  end
46
48
 
47
- describe "#all_views", :vcr do
49
+ describe "#all_views" do
50
+ before(:each) { stub_jenkins(:get, "/api/json?tree=views%5Bname,url,jobs%5Bname,url%5D%5D", "views.json") }
51
+
48
52
  let(:current_response) { subordinate.all_views }
49
53
 
50
54
  it "returns the view response" do
@@ -74,19 +78,45 @@ describe Subordinate::Client do
74
78
 
75
79
  describe "#add_job_to_view" do
76
80
  it "responds with a success" do
77
- stub_request(:post, "#{subordinate.api_endpoint}/view/#{ENV["VIEW"]}/addJobToView?name=#{ENV['JOB']}").
78
- to_return(:status => 200, :body => "", :headers => {})
81
+ stub_jenkins(:post, "/view/someview/addJobToView?name=somejob", 200, "empty.json")
82
+
83
+ subordinate.add_job_to_view("someview", "somejob").status.should == 200
84
+ end
85
+
86
+ context "error" do
87
+ it "returns 404 when not found" do
88
+ stub_jenkins(:post, "/view/someview/addJobToView?name=somejob", 404, "empty.json")
89
+
90
+ subordinate.add_job_to_view("someview", "somejob").status.should == 404
91
+ end
92
+
93
+ it "returns 500 when server error" do
94
+ stub_jenkins(:post, "/view/someview/addJobToView?name=somejob", 500, "empty.json")
79
95
 
80
- subordinate.add_job_to_view(ENV["VIEW"], ENV["JOB"]).status.should == 200
96
+ subordinate.add_job_to_view("someview", "somejob").status.should == 500
97
+ end
81
98
  end
82
99
  end
83
100
 
84
101
  describe "#remove_job_from_view" do
85
102
  it "responds with a success" do
86
- stub_request(:post, "#{subordinate.api_endpoint}/view/#{ENV["VIEW"]}/removeJobFromView?name=#{ENV['JOB']}").
87
- to_return(:status => 200, :body => "", :headers => {})
103
+ stub_jenkins(:post, "/view/someview/removeJobFromView?name=somejob", 200, "empty.json")
104
+
105
+ subordinate.remove_job_from_view("someview", "somejob").status.should == 200
106
+ end
107
+
108
+ context "error" do
109
+ it "returns 404 when not found" do
110
+ stub_jenkins(:post, "/view/someview/removeJobFromView?name=somejob", 404, "empty.json")
88
111
 
89
- subordinate.remove_job_from_view(ENV["VIEW"], ENV["JOB"]).status.should == 200
112
+ subordinate.remove_job_from_view("someview", "somejob").status.should == 404
113
+ end
114
+
115
+ it "returns 500 when server error" do
116
+ stub_jenkins(:post, "/view/someview/removeJobFromView?name=somejob", 500, "empty.json")
117
+
118
+ subordinate.remove_job_from_view("someview", "somejob").status.should == 500
119
+ end
90
120
  end
91
121
  end
92
- end
122
+ end
@@ -5,9 +5,9 @@ describe Subordinate::Client do
5
5
  before do
6
6
  Subordinate.reset!
7
7
  Subordinate.configure do |c|
8
- c.subdomain = ENV["SUBDOMAIN"]
9
- c.domain = ENV["DOMAIN"]
10
- c.port = ENV["PORT"]
8
+ c.subdomain = "jenkins"
9
+ c.domain = "example.com"
10
+ c.port = 8080
11
11
  c.ssl = false
12
12
  end
13
13
  end
@@ -17,6 +17,8 @@ describe Subordinate::Client do
17
17
  let(:subdomain) { "awesome" }
18
18
  let(:port) { 2000 }
19
19
  let(:ssl) { false }
20
+ let(:username) { "someusername" }
21
+ let(:token) { "sometoken" }
20
22
 
21
23
  it "can be initialized" do
22
24
  Subordinate::Client.new.class.should == Subordinate::Client
@@ -26,34 +28,35 @@ describe Subordinate::Client do
26
28
  Subordinate.new.class.should == Subordinate::Client
27
29
  end
28
30
 
29
- it "works with basic username and api token", :vcr do
30
- Subordinate::Client.new(:username => ENV["USERNAME"], :api_token => ENV["TOKEN"]).root
31
+ it "works with basic username and api token" do
32
+ stub_jenkins(:get, "/api/json", "base.json")
33
+ Subordinate::Client.new(:username => username, :api_token => token).root
31
34
  .should_not
32
35
  raise_exception
33
36
  end
34
37
 
35
38
  it "generates an endpoint without username and api token" do
36
- client = Subordinate::Client.new(:api_key => ENV["API_KEY"] )
37
- client.api_endpoint.should_not include("#{ENV["USERNAME"]}:#{ENV["API_KEY"]}")
39
+ client = Subordinate::Client.new(:api_token => token )
40
+ client.api_endpoint.should_not include("#{username}:#{token}")
38
41
  end
39
42
 
40
43
  it "can be configured to use a new domain via options" do
41
- client = Subordinate::Client.new(:api_key => ENV["API_KEY"], :domain => domain )
44
+ client = Subordinate::Client.new(:api_token => token, :domain => domain )
42
45
  client.domain.should == domain
43
46
  end
44
47
 
45
48
  it "can be configured to use a new subdomain via options" do
46
- client = Subordinate::Client.new(:api_key => ENV["API_KEY"], :subdomain => subdomain )
49
+ client = Subordinate::Client.new(:api_token => token, :subdomain => subdomain )
47
50
  client.subdomain.should == subdomain
48
51
  end
49
52
 
50
53
  it "can be configured to use a new port via options" do
51
- client = Subordinate::Client.new(:api_key => ENV["API_KEY"], :port => port )
54
+ client = Subordinate::Client.new(:api_token => token, :port => port )
52
55
  client.port.should == port
53
56
  end
54
57
 
55
58
  it "can be configured to use a different ssl option via options" do
56
- client = Subordinate::Client.new(:api_key => ENV["API_KEY"], :ssl => ssl )
59
+ client = Subordinate::Client.new(:api_token => token, :ssl => ssl )
57
60
  client.ssl.should == ssl
58
61
  end
59
62
  end
@@ -1,13 +1,14 @@
1
+ # Configuration Spec
1
2
  require "spec_helper"
2
3
 
3
- # Configuration Spec
4
4
  describe Subordinate::Client do
5
5
  before do
6
6
  Subordinate.reset!
7
+
7
8
  Subordinate.configure do |c|
8
- c.subdomain = ENV["SUBDOMAIN"]
9
- c.domain = ENV["DOMAIN"]
10
- c.port = ENV["PORT"]
9
+ c.subdomain = "jenkins"
10
+ c.domain = "example.com"
11
+ c.port = 8080
11
12
  c.ssl = false
12
13
  end
13
14
  end
@@ -60,7 +61,7 @@ describe Subordinate::Client do
60
61
  describe "without a subdomain" do
61
62
  it "builds an endpoint without a subdomain" do
62
63
  client = Subordinate.new(:subdomain => nil)
63
- client.api_endpoint.should == "http://#{ENV["DOMAIN"]}:#{ENV["PORT"]}"
64
+ client.api_endpoint.should == "http://example.com:8080"
64
65
  end
65
66
  end
66
67
 
@@ -87,7 +88,7 @@ describe Subordinate::Client do
87
88
  describe "without a port" do
88
89
  it "builds an endpoint without a port" do
89
90
  client = Subordinate.new(:port => nil)
90
- client.api_endpoint.should == "http://#{ENV["SUBDOMAIN"]}.#{ENV["DOMAIN"]}"
91
+ client.api_endpoint.should == "http://jenkins.example.com"
91
92
  end
92
93
  end
93
94
 
@@ -116,4 +117,4 @@ describe Subordinate::Client do
116
117
  end
117
118
  end
118
119
  end
119
- end
120
+ end
@@ -0,0 +1,49 @@
1
+ {
2
+ "assignedLabels" : [
3
+ {
4
+
5
+ }
6
+ ],
7
+ "mode" : "NORMAL",
8
+ "nodeDescription" : "the master Jenkins node",
9
+ "nodeName" : "",
10
+ "numExecutors" : 2,
11
+ "description" : null,
12
+ "jobs" : [
13
+ {
14
+ "name" : "Mission-Control-Production",
15
+ "url" : "http://jenkins.missioncontrol.io:8080/job/Mission-Control-Production/",
16
+ "color" : "red"
17
+ },
18
+ {
19
+ "name" : "Mission-Control-Staging",
20
+ "url" : "http://jenkins.missioncontrol.io:8080/job/Mission-Control-Staging/",
21
+ "color" : "blue"
22
+ },
23
+ {
24
+ "name" : "Mission-Control-Staging-Testing",
25
+ "url" : "http://jenkins.missioncontrol.io:8080/job/Mission-Control-Staging-Testing/",
26
+ "color" : "red"
27
+ }
28
+ ],
29
+ "overallLoad" : {
30
+
31
+ },
32
+ "primaryView" : {
33
+ "name" : "All",
34
+ "url" : "http://jenkins.missioncontrol.io:8080/"
35
+ },
36
+ "quietingDown" : false,
37
+ "slaveAgentPort" : 0,
38
+ "unlabeledLoad" : {
39
+
40
+ },
41
+ "useCrumbs" : false,
42
+ "useSecurity" : true,
43
+ "views" : [
44
+ {
45
+ "name" : "All",
46
+ "url" : "http://jenkins.missioncontrol.io:8080/"
47
+ }
48
+ ]
49
+ }
@@ -0,0 +1,126 @@
1
+ {
2
+ "actions" : [
3
+ {
4
+ "causes" : [
5
+ {
6
+ "shortDescription" : "Started by an SCM change"
7
+ }
8
+ ]
9
+ },
10
+ {
11
+
12
+ },
13
+ {
14
+ "buildsByBranchName" : {
15
+ "origin/rc" : {
16
+ "buildNumber" : 363,
17
+ "buildResult" : null,
18
+ "marked" : {
19
+ "SHA1" : "28d38cb39d048c0ceaeff34d033e90a7886aa251",
20
+ "branch" : [
21
+ {
22
+ "SHA1" : "28d38cb39d048c0ceaeff34d033e90a7886aa251",
23
+ "name" : "origin/rc"
24
+ }
25
+ ]
26
+ },
27
+ "revision" : {
28
+ "SHA1" : "28d38cb39d048c0ceaeff34d033e90a7886aa251",
29
+ "branch" : [
30
+ {
31
+ "SHA1" : "28d38cb39d048c0ceaeff34d033e90a7886aa251",
32
+ "name" : "origin/rc"
33
+ }
34
+ ]
35
+ }
36
+ }
37
+ },
38
+ "lastBuiltRevision" : {
39
+ "SHA1" : "28d38cb39d048c0ceaeff34d033e90a7886aa251",
40
+ "branch" : [
41
+ {
42
+ "SHA1" : "28d38cb39d048c0ceaeff34d033e90a7886aa251",
43
+ "name" : "origin/rc"
44
+ }
45
+ ]
46
+ },
47
+ "remoteUrls" : [
48
+ "git://github.com/jenkinsci/jenkins"
49
+ ],
50
+ "scmName" : ""
51
+ },
52
+ {
53
+
54
+ },
55
+ {
56
+
57
+ },
58
+ {
59
+
60
+ },
61
+ {
62
+ "failCount" : 1,
63
+ "skipCount" : 5,
64
+ "totalCount" : 4513,
65
+ "urlName" : "testReport"
66
+ },
67
+ {
68
+
69
+ }
70
+ ],
71
+ "artifacts" : [
72
+ {
73
+ "displayPath" : "cli-1.531-SNAPSHOT-jar-with-dependencies.jar",
74
+ "fileName" : "cli-1.531-SNAPSHOT-jar-with-dependencies.jar",
75
+ "relativePath" : "cli/target/cli-1.531-SNAPSHOT-jar-with-dependencies.jar"
76
+ }
77
+ ],
78
+ "building" : false,
79
+ "description" : null,
80
+ "duration" : 3083928,
81
+ "estimatedDuration" : 4359595,
82
+ "executor" : null,
83
+ "fullDisplayName" : "jenkins_rc_branch #363",
84
+ "id" : "2013-09-09_21-32-40",
85
+ "keepLog" : false,
86
+ "number" : 363,
87
+ "result" : "UNSTABLE",
88
+ "timestamp" : 1378776760497,
89
+ "url" : "http://ci.jenkins-ci.org/view/Jenkins%20core/job/jenkins_rc_branch/363/",
90
+ "builtOn" : "remote-slave-6",
91
+ "changeSet" : {
92
+ "items" : [
93
+ {
94
+ "affectedPaths" : [
95
+ "core/src/main/resources/lib/form/textbox.jelly",
96
+ "core/src/main/resources/lib/form/expandableTextbox.jelly",
97
+ "core/src/main/resources/lib/form/advanced.jelly",
98
+ "core/src/main/resources/lib/form/textarea.jelly"
99
+ ],
100
+ "commitId" : "7ce4807087239bbe236cb34e9a8d183caffefe73",
101
+ "timestamp" : 1367431809000,
102
+ "author" : {
103
+ "absoluteUrl" : "http://ci.jenkins-ci.org/user/Jesse%20Glick",
104
+ "fullName" : "Jesse Glick"
105
+ },
106
+ "comment" : "[JENKINS-3107] Expand an Advanced section if some fields are already customized.\nInitial implementation handles only text fields, not e.g. checkboxes.\n",
107
+ "date" : "2013-05-01 14:10:09 -0400",
108
+ "id" : "7ce4807087239bbe236cb34e9a8d183caffefe73",
109
+ "msg" : "[JENKINS-3107] Expand an Advanced section if some fields are already customized.",
110
+ "paths" : [
111
+ {
112
+ "editType" : "edit",
113
+ "file" : "core/src/main/resources/lib/form/textarea.jelly"
114
+ }
115
+ ]
116
+ }
117
+ ],
118
+ "kind" : "git"
119
+ },
120
+ "culprits" : [
121
+ {
122
+ "absoluteUrl" : "http://ci.jenkins-ci.org/user/Jesse%20Glick",
123
+ "fullName" : "Jesse Glick"
124
+ }
125
+ ]
126
+ }