-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move fixtures to support, add specs for LocalGit and UserDefinedTags
- Loading branch information
1 parent
fe7573d
commit 0b57a4c
Showing
33 changed files
with
120 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
RSpec.describe ::Datadog::CI::Ext::Environment::LocalGit do | ||
let(:env) { {} } | ||
let(:environment_variables) { {} } | ||
|
||
describe "#tags" do | ||
subject(:extracted_tags) do | ||
ClimateControl.modify(environment_variables) { described_class.new(env).tags } | ||
end | ||
|
||
context "example git repository" do | ||
include_context "with git fixture", "gitdir_with_commit" | ||
|
||
let(:expected_tags) do | ||
{ | ||
"ci.workspace_path" => "#{Dir.pwd}/spec/support/fixtures/git", | ||
"git.branch" => "master", | ||
"git.commit.author.date" => "2011-02-16T13:00:00+00:00", | ||
"git.commit.author.email" => "bot@friendly.test", | ||
"git.commit.author.name" => "Friendly bot", | ||
"git.commit.committer.date" => "2021-06-17T18:35:10+00:00", | ||
"git.commit.committer.email" => "marco.costa@datadoghq.com", | ||
"git.commit.committer.name" => "Marco Costa", | ||
"git.commit.message" => "First commit!", | ||
"git.commit.sha" => "9322ca1d57975b49b8c00b449d21b06660ce8b5b", | ||
"git.repository_url" => "https://datadoghq.com/git/test.git" | ||
} | ||
end | ||
|
||
it "matches expected tags" do | ||
is_expected.to eq(expected_tags) | ||
end | ||
end | ||
end | ||
|
||
describe "#committer" do | ||
include_context "with git fixture", "gitdir_with_commit" | ||
|
||
subject(:committer_email) do | ||
ClimateControl.modify(environment_variables) { described_class.new(env).tags["git.commit.committer.email"] } | ||
end | ||
|
||
it "returns committer from the latest commit in the repository" do | ||
is_expected.to eq("marco.costa@datadoghq.com") | ||
end | ||
|
||
context "when git show -s returns nothing" do | ||
before do | ||
allow(Open3).to receive(:capture2e).and_return(["", double(success?: true)]) | ||
end | ||
|
||
it "returns nil and does not fail" do | ||
is_expected.to be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
RSpec.describe ::Datadog::CI::Ext::Environment::UserDefinedTags do | ||
describe ".tags" do | ||
subject(:extracted_tags) do | ||
ClimateControl.modify(environment_variables) { described_class.new(env).tags } | ||
end | ||
|
||
let(:env) { {} } | ||
let(:environment_variables) { {} } | ||
|
||
context "example fixture" do | ||
let(:env) do | ||
{ | ||
"DD_GIT_BRANCH" => "usersupplied-branch", | ||
"DD_GIT_COMMIT_AUTHOR_DATE" => "usersupplied-authordate", | ||
"DD_GIT_COMMIT_AUTHOR_EMAIL" => "usersupplied-authoremail", | ||
"DD_GIT_COMMIT_AUTHOR_NAME" => "usersupplied-authorname", | ||
"DD_GIT_COMMIT_COMMITTER_DATE" => "usersupplied-comitterdate", | ||
"DD_GIT_COMMIT_COMMITTER_EMAIL" => "usersupplied-comitteremail", | ||
"DD_GIT_COMMIT_COMMITTER_NAME" => "usersupplied-comittername", | ||
"DD_GIT_COMMIT_MESSAGE" => "usersupplied-message", | ||
"DD_GIT_COMMIT_SHA" => "b9f0fb3fdbb94c9d24b2c75b49663122a529e123", | ||
"DD_GIT_REPOSITORY_URL" => "git@github.com:DataDog/userrepo.git" | ||
} | ||
end | ||
# Modify HOME so that '~' expansion matches CI home directory. | ||
let(:environment_variables) { super().merge("HOME" => env["HOME"]) } | ||
|
||
let(:expected_tags) do | ||
{ | ||
"git.branch" => "usersupplied-branch", | ||
"git.commit.author.date" => "usersupplied-authordate", | ||
"git.commit.author.email" => "usersupplied-authoremail", | ||
"git.commit.author.name" => "usersupplied-authorname", | ||
"git.commit.committer.date" => "usersupplied-comitterdate", | ||
"git.commit.committer.email" => "usersupplied-comitteremail", | ||
"git.commit.committer.name" => "usersupplied-comittername", | ||
"git.commit.message" => "usersupplied-message", | ||
"git.commit.sha" => "b9f0fb3fdbb94c9d24b2c75b49663122a529e123", | ||
"git.repository_url" => "git@github.com:DataDog/userrepo.git" | ||
} | ||
end | ||
|
||
it "matches CI tags" do | ||
is_expected.to eq(expected_tags) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FIXTURE_DIR = "#{File.dirname(__FILE__)}/fixtures/" # rubocop:disable all | ||
|
||
shared_context "with git fixture" do |git_fixture| | ||
let(:environment_variables) do | ||
super().merge("GIT_DIR" => "#{FIXTURE_DIR}/git/#{git_fixture}", "GIT_WORK_TREE" => "#{FIXTURE_DIR}/git/") | ||
end | ||
end | ||
|
||
shared_context "without git installed" do | ||
before { allow(Open3).to receive(:capture2e).and_raise(Errno::ENOENT, "No such file or directory - git") } | ||
end |