Commit b87ca750 authored by Valery Sizov's avatar Valery Sizov

fix specs. Stage 7

parent 88b3195e
......@@ -11,7 +11,7 @@ module Ci
lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_url(project)}\">#{project.name}</a> - ")
if commit.matrix?
lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_ref_commit_url(project, commit.ref, commit.sha)}\">Commit ##{commit.id}</a></br>")
lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_ref_commits_url(project, commit.ref, commit.sha)}\">Commit ##{commit.id}</a></br>")
else
first_build = commit.builds_without_retry.first
lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_build_url(project, first_build)}\">Build '#{first_build.name}' ##{first_build.id}</a></br>")
......
......@@ -46,10 +46,10 @@ module Ci
def attachment_message
out = "<#{Ci::RoutesHelper.ci_project_url(project)}|#{project_name}>: "
if commit.matrix?
out << "Commit <#{Ci::RoutesHelper.ci_project_ref_commit_url(project, commit.ref, commit.sha)}|\##{commit.id}> "
out << "Commit <#{Ci::RoutesHelper.ci_project_ref_commits_url(project, commit.ref, commit.sha)}|\##{commit.id}> "
else
build = commit.builds_without_retry.first
out << "Build <#{Ci::RoutesHelper.ci_project_build_url(project, build)}|\##{build.id}> "
out << "Build <#{Ci::RoutesHelper.ci_project_build_path(project, build)}|\##{build.id}> "
end
out << "(<#{commit_sha_link}|#{commit.short_sha}>) "
out << "of <#{commit_ref_link}|#{commit.ref}> "
......
require 'spec_helper'
describe "Admin Builds" do
let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit }
let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit }
before do
skip_admin_auth
skip_ci_admin_auth
login_as :user
end
describe "GET /admin/builds" do
before do
build
visit admin_builds_path
visit ci_admin_builds_path
end
it { expect(page).to have_content "All builds" }
......@@ -22,23 +22,23 @@ describe "Admin Builds" do
describe "Tabs" do
it "shows all builds" do
build = FactoryGirl.create :build, commit: commit, status: "pending"
build1 = FactoryGirl.create :build, commit: commit, status: "running"
build2 = FactoryGirl.create :build, commit: commit, status: "success"
build3 = FactoryGirl.create :build, commit: commit, status: "failed"
build = FactoryGirl.create :ci_build, commit: commit, status: "pending"
build1 = FactoryGirl.create :ci_build, commit: commit, status: "running"
build2 = FactoryGirl.create :ci_build, commit: commit, status: "success"
build3 = FactoryGirl.create :ci_build, commit: commit, status: "failed"
visit admin_builds_path
visit ci_admin_builds_path
expect(page.all(".build-link").size).to eq(4)
end
it "shows pending builds" do
build = FactoryGirl.create :build, commit: commit, status: "pending"
build1 = FactoryGirl.create :build, commit: commit, status: "running"
build2 = FactoryGirl.create :build, commit: commit, status: "success"
build3 = FactoryGirl.create :build, commit: commit, status: "failed"
build = FactoryGirl.create :ci_build, commit: commit, status: "pending"
build1 = FactoryGirl.create :ci_build, commit: commit, status: "running"
build2 = FactoryGirl.create :ci_build, commit: commit, status: "success"
build3 = FactoryGirl.create :ci_build, commit: commit, status: "failed"
visit admin_builds_path
visit ci_admin_builds_path
within ".nav.nav-tabs" do
click_on "Pending"
......@@ -51,12 +51,12 @@ describe "Admin Builds" do
end
it "shows running builds" do
build = FactoryGirl.create :build, commit: commit, status: "pending"
build1 = FactoryGirl.create :build, commit: commit, status: "running"
build2 = FactoryGirl.create :build, commit: commit, status: "success"
build3 = FactoryGirl.create :build, commit: commit, status: "failed"
build = FactoryGirl.create :ci_build, commit: commit, status: "pending"
build1 = FactoryGirl.create :ci_build, commit: commit, status: "running"
build2 = FactoryGirl.create :ci_build, commit: commit, status: "success"
build3 = FactoryGirl.create :ci_build, commit: commit, status: "failed"
visit admin_builds_path
visit ci_admin_builds_path
within ".nav.nav-tabs" do
click_on "Running"
......
......@@ -4,14 +4,14 @@ describe "Admin Events" do
let(:event) { FactoryGirl.create :admin_event }
before do
skip_admin_auth
skip_ci_admin_auth
login_as :user
end
describe "GET /admin/events" do
before do
event
visit admin_events_path
visit ci_admin_events_path
end
it { expect(page).to have_content "Events" }
......
require 'spec_helper'
describe "Admin Projects" do
let(:project) { FactoryGirl.create :project }
let(:project) { FactoryGirl.create :ci_project }
before do
skip_admin_auth
skip_ci_admin_auth
login_as :user
end
describe "GET /admin/projects" do
before do
project
visit admin_projects_path
visit ci_admin_projects_path
end
it { expect(page).to have_content "Projects" }
......
......@@ -2,16 +2,16 @@ require 'spec_helper'
describe "Admin Runners" do
before do
skip_admin_auth
skip_ci_admin_auth
login_as :user
end
describe "Runners page" do
before do
runner = FactoryGirl.create(:runner)
commit = FactoryGirl.create(:commit)
FactoryGirl.create(:build, commit: commit, runner_id: runner.id)
visit admin_runners_path
runner = FactoryGirl.create(:ci_runner)
commit = FactoryGirl.create(:ci_commit)
FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id)
visit ci_admin_runners_path
end
it { page.has_text? "Manage Runners" }
......@@ -20,8 +20,8 @@ describe "Admin Runners" do
describe 'search' do
before do
FactoryGirl.create :runner, description: 'foo'
FactoryGirl.create :runner, description: 'bar'
FactoryGirl.create :ci_runner, description: 'foo'
FactoryGirl.create :ci_runner, description: 'bar'
fill_in 'search', with: 'foo'
click_button 'Search'
......@@ -33,12 +33,12 @@ describe "Admin Runners" do
end
describe "Runner show page" do
let(:runner) { FactoryGirl.create :runner }
let(:runner) { FactoryGirl.create :ci_runner }
before do
FactoryGirl.create(:project, name: "foo")
FactoryGirl.create(:project, name: "bar")
visit admin_runner_path(runner)
FactoryGirl.create(:ci_project, name: "foo")
FactoryGirl.create(:ci_project, name: "bar")
visit ci_admin_runner_path(runner)
end
describe 'runner info' do
......
require 'spec_helper'
describe "Events" do
let(:project) { FactoryGirl.create :project }
let(:project) { FactoryGirl.create :ci_project }
let(:event) { FactoryGirl.create :admin_event, project: project }
before do
......@@ -11,7 +11,7 @@ describe "Events" do
describe "GET /project/:id/events" do
before do
event
visit project_events_path(project)
visit ci_project_events_path(project)
end
it { expect(page).to have_content "Events" }
......
......@@ -7,7 +7,7 @@ describe "Lint" do
it "Yaml parsing", js: true do
content = File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
visit lint_path
visit ci_lint_path
fill_in "content", with: content
click_on "Validate"
within "table" do
......@@ -19,7 +19,7 @@ describe "Lint" do
end
it "Yaml parsing with error", js: true do
visit lint_path
visit ci_lint_path
fill_in "content", with: ""
click_on "Validate"
expect(page).to have_content("Status: syntax is incorrect")
......
......@@ -7,8 +7,8 @@ describe "Runners" do
describe "specific runners" do
before do
@project = FactoryGirl.create :project
@project2 = FactoryGirl.create :project
@project = FactoryGirl.create :ci_project
@project2 = FactoryGirl.create :ci_project
stub_js_gitlab_calls
# all projects should be authorized for user
......@@ -17,22 +17,22 @@ describe "Runners" do
OpenStruct.new({ id: @project2.gitlab_id })
])
@shared_runner = FactoryGirl.create :shared_runner
@specific_runner = FactoryGirl.create :specific_runner
@specific_runner2 = FactoryGirl.create :specific_runner
@shared_runner = FactoryGirl.create :ci_shared_runner
@specific_runner = FactoryGirl.create :ci_specific_runner
@specific_runner2 = FactoryGirl.create :ci_specific_runner
@project.runners << @specific_runner
@project2.runners << @specific_runner2
end
it "places runners in right places" do
visit project_runners_path(@project)
visit ci_project_runners_path(@project)
expect(page.find(".available-specific-runners")).to have_content(@specific_runner2.display_name)
expect(page.find(".activated-specific-runners")).to have_content(@specific_runner.display_name)
expect(page.find(".available-shared-runners")).to have_content(@shared_runner.display_name)
end
it "enables specific runner for project" do
visit project_runners_path(@project)
visit ci_project_runners_path(@project)
within ".available-specific-runners" do
click_on "Enable for this project"
......@@ -44,7 +44,7 @@ describe "Runners" do
it "disables specific runner for project" do
@project2.runners << @specific_runner
visit project_runners_path(@project)
visit ci_project_runners_path(@project)
within ".activated-specific-runners" do
click_on "Disable for this project"
......@@ -54,7 +54,7 @@ describe "Runners" do
end
it "removes specific runner for project if this is last project for that runners" do
visit project_runners_path(@project)
visit ci_project_runners_path(@project)
within ".activated-specific-runners" do
click_on "Remove runner"
......@@ -66,12 +66,12 @@ describe "Runners" do
describe "shared runners" do
before do
@project = FactoryGirl.create :project
@project = FactoryGirl.create :ci_project
stub_js_gitlab_calls
end
it "enables shared runners" do
visit project_runners_path(@project)
visit ci_project_runners_path(@project)
click_on "Enable shared runners"
......@@ -81,14 +81,14 @@ describe "Runners" do
describe "show page" do
before do
@project = FactoryGirl.create :project
@project = FactoryGirl.create :ci_project
stub_js_gitlab_calls
@specific_runner = FactoryGirl.create :specific_runner
@specific_runner = FactoryGirl.create :ci_specific_runner
@project.runners << @specific_runner
end
it "shows runner information" do
visit project_runners_path(@project)
visit ci_project_runners_path(@project)
click_on @specific_runner.short_sha
......
require 'spec_helper'
describe 'Variables' do
describe 'Triggers' do
before do
login_as :user
@project = FactoryGirl.create :project
@project = FactoryGirl.create :ci_project
stub_js_gitlab_calls
visit project_triggers_path(@project)
visit ci_project_triggers_path(@project)
end
context 'create a trigger' do
......
......@@ -7,12 +7,12 @@ describe "Variables" do
describe "specific runners" do
before do
@project = FactoryGirl.create :project
@project = FactoryGirl.create :ci_project
stub_js_gitlab_calls
end
it "creates variable", js: true do
visit project_variables_path(@project)
visit ci_project_variables_path(@project)
click_on "Add a variable"
fill_in "Key", with: "SECRET_KEY"
fill_in "Value", with: "SECRET_VALUE"
......
......@@ -4,14 +4,14 @@ describe "Charts" do
context "build_times" do
before do
@project = FactoryGirl.create(:project)
@commit = FactoryGirl.create(:commit, project: @project)
FactoryGirl.create(:build, commit: @commit)
@project = FactoryGirl.create(:ci_project)
@commit = FactoryGirl.create(:ci_commit, project: @project)
FactoryGirl.create(:ci_build, commit: @commit)
end
it 'should return build times in minutes' do
chart = Charts::BuildTime.new(@project)
chart.build_times.should == [2]
chart = Ci::Charts::BuildTime.new(@project)
expect(chart.build_times).to eq([2])
end
end
end
require 'spec_helper'
describe Ci::GitlabCiYamlProcessor do
describe "#builds_for_ref" do
let(:type) { 'test' }
it "returns builds if no branch specified" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref(type, "master").size.should == 1
config_processor.builds_for_stage_and_ref(type, "master").first.should == {
stage: "test",
except: nil,
name: :rspec,
only: nil,
script: "pwd\nrspec",
tags: [],
options: {},
allow_failure: false
}
module Ci
describe GitlabCiYamlProcessor do
describe "#builds_for_ref" do
let(:type) { 'test' }
it "returns builds if no branch specified" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref(type, "master").first).to eq({
stage: "test",
except: nil,
name: :rspec,
only: nil,
script: "pwd\nrspec",
tags: [],
options: {},
allow_failure: false
})
end
it "does not return builds if only has another branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", only: ["deploy"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
end
it "does not return builds if only has regexp with another branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", only: ["/^deploy$/"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
end
it "returns builds if only has specified this branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", only: ["master"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
end
it "does not build tags" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", except: ["tags"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref(type, "0-1", true).size).to eq(0)
end
it "returns builds if only has a list of branches including specified" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", type: type, only: ["master", "deploy"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
end
it "returns build only for specified type" do
config = YAML.dump({
before_script: ["pwd"],
build: { script: "build", type: "build", only: ["master", "deploy"] },
rspec: { script: "rspec", type: type, only: ["master", "deploy"] },
staging: { script: "deploy", type: "deploy", only: ["master", "deploy"] },
production: { script: "deploy", type: "deploy", only: ["master", "deploy"] },
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref("production", "deploy").size).to eq(0)
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("deploy", "deploy").size).to eq(2)
end
end
it "does not return builds if only has another branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", only: ["deploy"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref(type, "master").size.should == 0
end
it "does not return builds if only has regexp with another branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", only: ["/^deploy$/"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref(type, "master").size.should == 0
end
it "returns builds if only has specified this branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", only: ["master"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref(type, "master").size.should == 1
end
it "does not build tags" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", except: ["tags"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref(type, "0-1", true).size.should == 0
end
it "returns builds if only has a list of branches including specified" do
config = YAML.dump({
before_script: ["pwd"],
rspec: { script: "rspec", type: type, only: ["master", "deploy"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref(type, "deploy").size.should == 1
end
it "returns build only for specified type" do
config = YAML.dump({
before_script: ["pwd"],
build: { script: "build", type: "build", only: ["master", "deploy"] },
rspec: { script: "rspec", type: type, only: ["master", "deploy"] },
staging: { script: "deploy", type: "deploy", only: ["master", "deploy"] },
production: { script: "deploy", type: "deploy", only: ["master", "deploy"] },
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref("production", "deploy").size.should == 0
config_processor.builds_for_stage_and_ref(type, "deploy").size.should == 1
config_processor.builds_for_stage_and_ref("deploy", "deploy").size.should == 2
end
end
describe "Image and service handling" do
it "returns image and service when defined" do
config = YAML.dump({
image: "ruby:2.1",
services: ["mysql"],
before_script: ["pwd"],
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref("test", "master").size.should == 1
config_processor.builds_for_stage_and_ref("test", "master").first.should == {
except: nil,
stage: "test",
name: :rspec,
only: nil,
script: "pwd\nrspec",
tags: [],
options: {
image: "ruby:2.1",
services: ["mysql"]
},
allow_failure: false
}
end
it "returns image and service when overridden for job" do
config = YAML.dump({
image: "ruby:2.1",
services: ["mysql"],
before_script: ["pwd"],
rspec: { image: "ruby:2.5", services: ["postgresql"], script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_stage_and_ref("test", "master").size.should == 1
config_processor.builds_for_stage_and_ref("test", "master").first.should == {
except: nil,
stage: "test",
name: :rspec,
only: nil,
script: "pwd\nrspec",
tags: [],
options: {
image: "ruby:2.5",
services: ["postgresql"]
},
allow_failure: false
}
end
end
describe "Variables" do
it "returns variables when defined" do
variables = {
var1: "value1",
var2: "value2",
}
config = YAML.dump({
variables: variables,
before_script: ["pwd"],
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.variables.should == variables
end
end
describe "Error handling" do
it "indicates that object is invalid" do
expect{GitlabCiYamlProcessor.new("invalid_yaml\n!ccdvlf%612334@@@@")}.to raise_error(GitlabCiYamlProcessor::ValidationError)
end
it "returns errors if tags parameter is invalid" do
config = YAML.dump({ rspec: { script: "test", tags: "mysql" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings")
end
it "returns errors if before_script parameter is invalid" do
config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script should be an array of strings")
end
it "returns errors if image parameter is invalid" do
config = YAML.dump({ image: ["test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image should be a string")
end
it "returns errors if job image parameter is invalid" do
config = YAML.dump({ rspec: { script: "test", image: ["test"] } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string")
end
it "returns errors if services parameter is not an array" do
config = YAML.dump({ services: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
end
it "returns errors if services parameter is not an array of strings" do
config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
end
it "returns errors if job services parameter is not an array" do
config = YAML.dump({ rspec: { script: "test", services: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
end
it "returns errors if job services parameter is not an array of strings" do
config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
end
it "returns errors if there are unknown parameters" do
config = YAML.dump({ extra: "bundle update" })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
end
it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do
config = YAML.dump({ extra: { services: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
end
it "returns errors if there is no any jobs defined" do
config = YAML.dump({ before_script: ["bundle update"] })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job")
end
it "returns errors if job allow_failure parameter is not an boolean" do
config = YAML.dump({ rspec: { script: "test", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean")
end
it "returns errors if job stage is not a string" do
config = YAML.dump({ rspec: { script: "test", type: 1, allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
it "returns errors if job stage is not a pre-defined stage" do
config = YAML.dump({ rspec: { script: "test", type: "acceptance", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
it "returns errors if job stage is not a defined stage" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test")
end
it "returns errors if stages is not an array" do
config = YAML.dump({ types: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
end
it "returns errors if stages is not an array of strings" do
config = YAML.dump({ types: [true, "test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
describe "Image and service handling" do
it "returns image and service when defined" do
config = YAML.dump({
image: "ruby:2.1",
services: ["mysql"],
before_script: ["pwd"],
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
except: nil,
stage: "test",
name: :rspec,
only: nil,
script: "pwd\nrspec",
tags: [],
options: {
image: "ruby:2.1",
services: ["mysql"]
},
allow_failure: false
})
end
it "returns image and service when overridden for job" do
config = YAML.dump({
image: "ruby:2.1",
services: ["mysql"],
before_script: ["pwd"],
rspec: { image: "ruby:2.5", services: ["postgresql"], script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
except: nil,
stage: "test",
name: :rspec,
only: nil,
script: "pwd\nrspec",
tags: [],
options: {
image: "ruby:2.5",
services: ["postgresql"]
},
allow_failure: false
})
end
end
it "returns errors if variables is not a map" do
config = YAML.dump({ variables: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
describe "Variables" do
it "returns variables when defined" do
variables = {
var1: "value1",
var2: "value2",
}
config = YAML.dump({
variables: variables,
before_script: ["pwd"],
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
expect(config_processor.variables).to eq(variables)
end
end
it "returns errors if variables is not a map of key-valued strings" do
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
describe "Error handling" do
it "indicates that object is invalid" do
expect{GitlabCiYamlProcessor.new("invalid_yaml\n!ccdvlf%612334@@@@")}.to raise_error(GitlabCiYamlProcessor::ValidationError)
end
it "returns errors if tags parameter is invalid" do
config = YAML.dump({ rspec: { script: "test", tags: "mysql" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings")
end
it "returns errors if before_script parameter is invalid" do
config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script should be an array of strings")
end
it "returns errors if image parameter is invalid" do
config = YAML.dump({ image: ["test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image should be a string")
end
it "returns errors if job image parameter is invalid" do
config = YAML.dump({ rspec: { script: "test", image: ["test"] } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string")
end
it "returns errors if services parameter is not an array" do
config = YAML.dump({ services: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
end
it "returns errors if services parameter is not an array of strings" do
config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
end
it "returns errors if job services parameter is not an array" do
config = YAML.dump({ rspec: { script: "test", services: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
end
it "returns errors if job services parameter is not an array of strings" do
config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
end
it "returns errors if there are unknown parameters" do
config = YAML.dump({ extra: "bundle update" })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
end
it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do
config = YAML.dump({ extra: { services: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
end
it "returns errors if there is no any jobs defined" do
config = YAML.dump({ before_script: ["bundle update"] })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job")
end
it "returns errors if job allow_failure parameter is not an boolean" do
config = YAML.dump({ rspec: { script: "test", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean")
end
it "returns errors if job stage is not a string" do
config = YAML.dump({ rspec: { script: "test", type: 1, allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
it "returns errors if job stage is not a pre-defined stage" do
config = YAML.dump({ rspec: { script: "test", type: "acceptance", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
it "returns errors if job stage is not a defined stage" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test")
end
it "returns errors if stages is not an array" do
config = YAML.dump({ types: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
end
it "returns errors if stages is not an array of strings" do
config = YAML.dump({ types: [true, "test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
end
it "returns errors if variables is not a map" do
config = YAML.dump({ variables: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
end
it "returns errors if variables is not a map of key-valued strings" do
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
end
end
end
end
......@@ -169,7 +169,7 @@ describe Ci::MailService do
end
it do
Build.retry(build)
Ci::Build.retry(build)
should_email(commit.git_author_email)
should_email("jeroen@example.com")
mail.execute(build) if mail.can_execute?(build)
......
require 'spec_helper'
describe Ci::SlackMessage do
subject { SlackMessage.new(commit) }
subject { Ci::SlackMessage.new(commit) }
let(:project) { FactoryGirl.create :ci_project }
......@@ -43,7 +43,7 @@ describe Ci::SlackMessage do
end
context "Several builds" do
let(:commit) { FactoryGirl.create(:commit_with_two_jobs, project: project) }
let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs, project: project) }
context 'when all matrix builds succeeded' do
let(:color) { 'good' }
......
......@@ -30,7 +30,7 @@ describe Ci::SlackService do
end
describe "Execute" do
let(:slack) { SlackService.new }
let(:slack) { Ci::SlackService.new }
let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' }
......@@ -50,7 +50,7 @@ describe Ci::SlackService do
it "should call Slack API" do
slack.execute(build)
SlackNotifierWorker.drain
Ci::SlackNotifierWorker.drain
expect(WebMock).to have_requested(:post, webhook_url).once
end
......
......@@ -22,7 +22,7 @@ require 'spec_helper'
describe Ci::Runner do
describe '#display_name' do
it 'should return the description if it has a value' do
runner = FactoryGirl.build(:runner, description: 'Linux/Ruby-1.9.3-p448')
runner = FactoryGirl.build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
expect(runner.display_name).to eq 'Linux/Ruby-1.9.3-p448'
end
......@@ -32,7 +32,7 @@ describe Ci::Runner do
end
it 'should return the token if the description is an empty string' do
runner = FactoryGirl.build(:runner, description: '')
runner = FactoryGirl.build(:ci_runner, description: '')
expect(runner.display_name).to eq runner.token
end
end
......
......@@ -25,7 +25,7 @@ describe Ci::Service do
describe "Test Button" do
before do
@service = Service.new
@service = Ci::Service.new
end
describe "Testable" do
......
require 'spec_helper'
describe Ci::CreateProjectService do
let(:service) { CreateProjectService.new }
let(:service) { Ci::CreateProjectService.new }
let(:current_user) { double.as_null_object }
let(:project_dump) { YAML.load File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) }
before { allow_any_instance_of(Network).to receive_messages(enable_ci: true) }
describe :execute do
context 'valid params' do
let(:project) { service.execute(current_user, project_dump, 'http://localhost/projects/:project_id') }
......@@ -23,7 +21,7 @@ describe Ci::CreateProjectService do
context "forking" do
it "uses project as a template for settings and jobs" do
origin_project = FactoryGirl.create(:project)
origin_project = FactoryGirl.create(:ci_project)
origin_project.shared_runners_enabled = true
origin_project.public = true
origin_project.allow_git_fetch = true
......
require 'spec_helper'
describe Ci::CreateTriggerRequestService do
let(:service) { CreateTriggerRequestService.new }
let(:project) { FactoryGirl.create :project }
let(:trigger) { FactoryGirl.create :trigger, project: project }
let(:service) { Ci::CreateTriggerRequestService.new }
let(:project) { FactoryGirl.create :ci_project }
let(:trigger) { FactoryGirl.create :ci_trigger, project: project }
describe :execute do
context 'valid params' do
subject { service.execute(project, trigger, 'master') }
before do
@commit = FactoryGirl.create :commit, project: project
@commit = FactoryGirl.create :ci_commit, project: project
end
it { expect(subject).to be_kind_of(TriggerRequest) }
it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
it { expect(subject.commit).to eq(@commit) }
end
......@@ -27,7 +27,7 @@ describe Ci::CreateTriggerRequestService do
subject { service.execute(project, trigger, 'master') }
before do
FactoryGirl.create :commit_without_jobs, project: project
FactoryGirl.create :ci_commit_without_jobs, project: project
end
it { expect(subject).to be_nil }
......@@ -37,13 +37,13 @@ describe Ci::CreateTriggerRequestService do
subject { service.execute(project, trigger, 'master') }
before do
@commit1 = FactoryGirl.create :commit, committed_at: 2.hour.ago, project: project
@commit2 = FactoryGirl.create :commit, committed_at: 1.hour.ago, project: project
@commit3 = FactoryGirl.create :commit, committed_at: 3.hour.ago, project: project
@commit1 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project
@commit2 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project
@commit3 = FactoryGirl.create :ci_commit, committed_at: 3.hour.ago, project: project
end
context 'retries latest one' do
it { expect(subject).to be_kind_of(TriggerRequest) }
it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
it { expect(subject).to be_persisted }
it { expect(subject.commit).to eq(@commit2) }
end
......
require 'spec_helper'
describe Ci::EventService do
let(:project) { FactoryGirl.create :project, name: "GitLab / gitlab-shell" }
let(:project) { FactoryGirl.create :ci_project, name: "GitLab / gitlab-shell" }
let(:user) { double(username: "root", id: 1) }
before do
......@@ -10,25 +10,25 @@ describe Ci::EventService do
describe :remove_project do
it "creates event" do
EventService.new.remove_project(user, project)
Ci::EventService.new.remove_project(user, project)
expect(Event.admin.last.description).to eq("Project \"GitLab / gitlab-shell\" has been removed by root")
expect(Ci::Event.admin.last.description).to eq("Project \"GitLab / gitlab-shell\" has been removed by root")
end
end
describe :create_project do
it "creates event" do
EventService.new.create_project(user, project)
Ci::EventService.new.create_project(user, project)
expect(Event.admin.last.description).to eq("Project \"GitLab / gitlab-shell\" has been created by root")
expect(Ci::Event.admin.last.description).to eq("Project \"GitLab / gitlab-shell\" has been created by root")
end
end
describe :change_project_settings do
it "creates event" do
EventService.new.change_project_settings(user, project)
Ci::EventService.new.change_project_settings(user, project)
expect(Event.last.description).to eq("User \"root\" updated projects settings")
expect(Ci::Event.last.description).to eq("User \"root\" updated projects settings")
end
end
end
require 'spec_helper'
describe Ci::WebHookService do
let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit }
let(:hook) { FactoryGirl.create :web_hook, project: project }
let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit }
let(:hook) { FactoryGirl.create :ci_web_hook, project: project }
describe :execute do
it "should execute successfully" do
stub_request(:post, hook.url).to_return(status: 200)
expect(WebHookService.new.build_end(build)).to be_truthy
expect(Ci::WebHookService.new.build_end(build)).to be_truthy
end
end
......@@ -31,6 +31,6 @@ describe Ci::WebHookService do
end
def build_data(build)
WebHookService.new.send :build_data, build
Ci::WebHookService.new.send :build_data, build
end
end
......@@ -44,4 +44,8 @@ module LoginHelpers
def logout_direct
page.driver.submit :delete, '/users/sign_out', {}
end
def skip_ci_admin_auth
allow_any_instance_of(Ci::Admin::ApplicationController).to receive_messages(authenticate_admin!: true)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment