Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 210/support for jenkins folders #298

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added unit TCs for Job class changes
swapnils19 committed Apr 18, 2020
commit bd9e9c3d8377a972cdfcbd483ef6d79b97253bf7
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -43,3 +43,9 @@ jenkins_api_client.log

# Vagrant
.vagrant

# VS Code history folder
.history

# local gem file
*.gem
8 changes: 4 additions & 4 deletions lib/jenkins_api_client/job.rb
Original file line number Diff line number Diff line change
@@ -621,7 +621,7 @@ def get_console_output(job_name, build_num = 0, start = 0, mode = 'text')
# @return [Array<String>] the names of all jobs in jenkins
#
def list_all(folder_path = '')
response_json = @client.api_get_request(path_encode folder_path, "tree=jobs[name]")["jobs"]
response_json = @client.api_get_request(path_encode(folder_path), "tree=jobs[name]")["jobs"]
response_json.map { |job| job["name"] }.sort
end

@@ -646,9 +646,9 @@ def exists?(job_name)
# @return [Array<String>] filtered jobs
#
def list_by_status(status, jobs = [], folder_path = '')
jobs = list_all if jobs.empty?
jobs = list_all(folder_path) if jobs.empty?
@logger.info "Obtaining jobs matching status '#{status}'"
json_response = @client.api_get_request(path_encode folder_path, "tree=jobs[name,color]")
json_response = @client.api_get_request(path_encode(folder_path), "tree=jobs[name,color]")
filtered_jobs = []
json_response["jobs"].each do |job|
if color_to_status(job["color"]) == status &&
@@ -666,7 +666,7 @@ def list_by_status(status, jobs = [], folder_path = '')
#
# @return [Array<String>] jobs matching the given pattern
#
def list(filter, ignorecase = true, folder_path)
def list(filter, ignorecase = true, folder_path = '')
@logger.info "Obtaining jobs matching filter '#{filter}'"
response_json = @client.api_get_request(path_encode folder_path)
jobs = []
42 changes: 42 additions & 0 deletions spec/unit_tests/job_spec.rb
Original file line number Diff line number Diff line change
@@ -281,6 +281,14 @@
response.class.should == Array
response.size.should == @sample_json_response["jobs"].size
end

it 'accepts folder_path parameter to list all jobs from inside a folder' do
@client.should_receive(:api_get_request).and_return(
@sample_json_response)
response = @job.list_all('/job/folder')
response.class.should == Array
response.size.should eq @sample_json_response['jobs'].size
end
end

describe "#exists?" do
@@ -297,11 +305,24 @@
@sample_json_response)
@job.list_by_status("success").class.should == Array
end

it "accepts the status and returns the jobs in specified status" do
@client.should_receive(:api_get_request).and_return(
@sample_json_response)
@job.list_by_status("success", ["test_job"]).class.should == Array
end

it 'accepts the status, folder_path and returns jobs in specified status' do
@client.should_receive(:api_get_request).twice.and_return(
@sample_json_response)
@job.list_by_status('success', [], '/job/folder').class.should == Array
end

it 'accepts the status, folder_path and returns the jobs in specified status' do
@client.should_receive(:api_get_request).and_return(
@sample_json_response)
@job.list_by_status('success', ['test_job'], '/job/folder').class.should == Array
end
end

describe "#list" do
@@ -310,6 +331,12 @@
"jobs" => ["test_job"])
@job.list("filter").class.should == Array
end

it 'accepts a filter and returns all jobs matching the filter' do
@client.should_receive(:api_get_request).and_return(
'jobs' => ['test_job'])
@job.list('filter', true, '/job/folder').class.should == Array
end
end

describe "#list_all_with_details" do
@@ -320,6 +347,14 @@
response.class.should == Array
response.size.should == @sample_json_response["jobs"].size
end

it 'accepts folder_path and returns all jobs with details' do
@client.should_receive(:api_get_request).and_return(
@sample_json_response)
response = @job.list_all_with_details('/job/folder')
response.class.should == Array
response.size.should == @sample_json_response['jobs'].size
end
end

describe "#list_details" do
@@ -329,6 +364,13 @@
response = @job.list_details("test_job")
response.class.should == Hash
end

it 'accepts the job name with folder path and returns its details' do
@client.should_receive(:api_get_request).and_return(
@sample_json_response)
response = @job.list_details('test_job', '/job/folder')
response.class.should == Hash
end
end

describe "#get_upstream_projects" do