Updating distribution

This commit is contained in:
Valet Bot
2022-01-07 19:45:53 +00:00
parent 74be75ac84
commit 51b31a805e
60 changed files with 1895 additions and 1 deletions
+67
View File
@@ -0,0 +1,67 @@
# frozen_string_literal: true
RSpec.describe Arguments do
let(:arguments) { Arguments.new(provider, command, issue_content) }
let(:provider) { instance_double(Provider) }
let(:command) { instance_double(Command) }
let(:issue_content) { "some issue content" }
describe "#argument_class" do
subject { arguments.argument_class(provider, command, issue_content) }
context "when the command is found" do
before do
expect(provider).to receive(:module).and_return(::Jenkins).at_least(:once)
expect(command).to receive(:classify).and_return("Audit").at_least(:once)
end
it { is_expected.to be_a(::Jenkins::Audit) }
end
context "when the command is not found" do
before do
expect(provider).to receive(:module).and_return(::Jenkins).at_least(:once)
expect(command).to receive(:classify).and_return("Whoopsie").at_least(:once)
end
it { expect { subject }.to raise_error(NameError) }
end
end
describe "#to_output" do
subject { arguments.to_output }
before do
expect(provider).to receive(:module).and_return(::AzureDevops).at_least(:once)
expect(command).to receive(:classify).and_return("Audit").at_least(:once)
expect_any_instance_of(::AzureDevops::Audit).to receive(:to_a).and_return(output)
end
context "when the output is nil" do
let(:output) { nil }
it "does not write any output variable" do
expect(arguments).not_to receive(:set_output)
subject
end
end
context "when the output is not nil" do
let(:output) { ["--option", "value"] }
it "writes an output variable" do
expect(arguments).to receive(:set_output).with("args", "--option value")
subject
end
end
context "when the output contains a space" do
let(:output) { ["--option", "some value"] }
it "writes an output variable" do
expect(arguments).to receive(:set_output).with("args", "--option \"some value\"")
subject
end
end
end
end
+42
View File
@@ -0,0 +1,42 @@
# frozen_string_literal: true
RSpec.describe AzureDevops::Audit do
let(:audit) { described_class.new(issue_content, nil) }
describe "#to_a" do
subject { audit.to_a }
context "when issue_content contains no args" do
let(:issue_content) do
<<~ISSUE
Organization:
Project:
ISSUE
end
it { is_expected.to be_nil }
end
context "when issue_content contains an organization" do
let(:issue_content) do
<<~ISSUE
Organization: my-organization
Project:
ISSUE
end
it { is_expected.to eq(["--azure-devops-organization", "my-organization"]) }
end
context "when issue_content contains a project" do
let(:issue_content) do
<<~ISSUE
Organization: my-organization
Project: my-project
ISSUE
end
it { is_expected.to eq(["--azure-devops-organization", "my-organization", "--azure-devops-project", "my-project"]) }
end
end
end
+28
View File
@@ -0,0 +1,28 @@
# frozen_string_literal: true
RSpec.describe AzureDevops::DryRun do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Organization: my-organization
Project: my-project
ISSUE
end
context "when the comment body does not contain a pipeline type" do
let(:comment_body) { "/dry-run" }
it { is_expected.to eq(["pipeline", "--azure-devops-organization", "my-organization", "--azure-devops-project", "my-project"]) }
end
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/dry-run --pipeline-id 42" }
it { is_expected.to eq(["pipeline", "--azure-devops-organization", "my-organization", "--azure-devops-project", "my-project", "--pipeline-id", "42"]) }
end
end
end
+28
View File
@@ -0,0 +1,28 @@
# frozen_string_literal: true
RSpec.describe AzureDevops::Migrate do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Organization: my-organization
Project: my-project
ISSUE
end
context "when the comment body does not contain a pipeline type" do
let(:comment_body) { "/migrate" }
it { is_expected.to eq(["pipeline", "--azure-devops-organization", "my-organization", "--azure-devops-project", "my-project"]) }
end
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/migrate --pipeline-id 42 --target-url https://github.com/org/repo" }
it { is_expected.to eq(["pipeline", "--azure-devops-organization", "my-organization", "--azure-devops-project", "my-project", "--pipeline-id", "42", "--target-url", "https://github.com/org/repo"]) }
end
end
end
+29
View File
@@ -0,0 +1,29 @@
# frozen_string_literal: true
RSpec.describe CircleCI::Audit do
let(:audit) { described_class.new(issue_content, nil) }
describe "#to_a" do
subject { audit.to_a }
context "when issue_content contains no args" do
let(:issue_content) do
<<~ISSUE
Organization:
ISSUE
end
it { is_expected.to be_nil }
end
context "when issue_content contains a organization" do
let(:issue_content) do
<<~ISSUE
Organization: testing
ISSUE
end
it { is_expected.to eq(["--circle-ci-organization", "testing"]) }
end
end
end
+21
View File
@@ -0,0 +1,21 @@
# frozen_string_literal: true
RSpec.describe CircleCI::DryRun do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Organization: testing
ISSUE
end
context "when the comment body contains a project" do
let(:comment_body) { "/dry-run --project repo" }
it { is_expected.to eq(["--circle-ci-organization", "testing", "--circle-ci-project", "repo"]) }
end
end
end
+21
View File
@@ -0,0 +1,21 @@
# frozen_string_literal: true
RSpec.describe CircleCI::Migrate do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Organization: testing
ISSUE
end
context "when the comment body contains a project" do
let(:comment_body) { "/migrate --project repo --target-url https://github.com/org/repo" }
it { is_expected.to eq(["--circle-ci-organization", "testing", "--circle-ci-project", "repo", "--target-url", "https://github.com/org/repo"]) }
end
end
end
+109
View File
@@ -0,0 +1,109 @@
# frozen_string_literal: true
RSpec.describe Command do
let(:command) { described_class.new(comment_body) }
describe "#command" do
subject { command.command }
context "when no command is present" do
let(:comment_body) do
<<~COMMENT
This is just a comment.
COMMENT
end
it { is_expected.to be_nil }
end
context "when an unsupported comment is present" do
let(:comment_body) do
<<~COMMENT
/do-something-unsupported
COMMENT
end
it { is_expected.to be_nil }
end
described_class::VALID_COMMANDS.each do |c|
context "when a supported command is present" do
let(:comment_body) do
<<~COMMENT
/#{c}
COMMENT
end
it { is_expected.to eq(c) }
end
end
end
describe "#options" do
subject { command.options }
context "when the command is not valid" do
let(:comment_body) { "/do-something-unsupported --option-one value" }
it { is_expected.to be_nil }
end
context "when no options are present" do
let(:comment_body) { "/dry-run" }
it { is_expected.to be_blank }
end
context "when options are present" do
let(:comment_body) { "/dry-run --option-one value-one --option-two value-two" }
it { is_expected.to eq({ "option-one" => "value-one", "option-two" => "value-two" }) }
end
end
describe "#valid?" do
subject { command.valid? }
context "when the command is supported" do
let(:comment_body) { "/dry-run" }
it { is_expected.to be_truthy }
end
context "when the command is not supported" do
let(:comment_body) { "/run-something-else" }
it { is_expected.to be_falsey }
end
end
describe "#classify" do
subject { command.classify }
[%w[audit Audit], %w[dry-run DryRun], %w[migrate Migrate]].each do |command, klass|
context "when the command is #{command}" do
let(:comment_body) { "/#{command}" }
it { is_expected.to eq(klass) }
end
end
context "when the command is invalid" do
let(:comment_body) { "/do-something-unsupported" }
it { is_expected.to be_nil }
end
end
describe "to_output" do
subject { command.to_output }
let(:comment_body) do
<<~COMMENT
/audit
COMMENT
end
it { expect { subject }.to output(/::set-output name=command::audit/).to_stdout }
end
end
+29
View File
@@ -0,0 +1,29 @@
# frozen_string_literal: true
RSpec.describe GitlabCI::Audit do
let(:audit) { described_class.new(issue_content, nil) }
describe "#to_a" do
subject { audit.to_a }
context "when issue_content contains no args" do
let(:issue_content) do
<<~ISSUE
Namespace:
ISSUE
end
it { is_expected.to be_nil }
end
context "when issue_content contains a namespace" do
let(:issue_content) do
<<~ISSUE
Namespace: testing
ISSUE
end
it { is_expected.to eq(["--namespace", "testing"]) }
end
end
end
+21
View File
@@ -0,0 +1,21 @@
# frozen_string_literal: true
RSpec.describe GitlabCI::DryRun do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Namespace: testing
ISSUE
end
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/dry-run --project project" }
it { is_expected.to eq(["--namespace", "testing", "--project", "project"]) }
end
end
end
+21
View File
@@ -0,0 +1,21 @@
# frozen_string_literal: true
RSpec.describe GitlabCI::Migrate do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Namespace: testing
ISSUE
end
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/migrate --project project --target-url https://github.com/org/repo" }
it { is_expected.to eq(["--namespace", "testing", "--project", "project", "--target-url", "https://github.com/org/repo"]) }
end
end
end
+29
View File
@@ -0,0 +1,29 @@
# frozen_string_literal: true
RSpec.describe Jenkins::Audit do
let(:audit) { described_class.new(issue_content, nil) }
describe "#to_a" do
subject { audit.to_a }
context "when issue_content contains no args" do
let(:issue_content) do
<<~ISSUE
Folders:
ISSUE
end
it { is_expected.to be_nil }
end
context "when issue_content contains a folder" do
let(:issue_content) do
<<~ISSUE
Folders: test, prod
ISSUE
end
it { is_expected.to eq(["--folders", "test, prod"]) }
end
end
end
+16
View File
@@ -0,0 +1,16 @@
# frozen_string_literal: true
RSpec.describe Jenkins::DryRun do
let(:dry_run) { described_class.new(nil, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/dry-run --source-url https://jenkins.company.com/job/pipeline" }
it { is_expected.to eq(["--source-url", "https://jenkins.company.com/job/pipeline"]) }
end
end
end
+16
View File
@@ -0,0 +1,16 @@
# frozen_string_literal: true
RSpec.describe Jenkins::Migrate do
let(:dry_run) { described_class.new(nil, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/migrate --source-url https://jenkins.company.com/job/pipeline --target-url https://github.com/org/repo" }
it { is_expected.to eq(["--source-url", "https://jenkins.company.com/job/pipeline", "--target-url", "https://github.com/org/repo"]) }
end
end
end
+97
View File
@@ -0,0 +1,97 @@
# frozen_string_literal: true
RSpec.describe Provider do
let(:provider) { described_class.new(labels) }
describe "#initialize" do
subject { provider }
context "when no providers are selected" do
let(:labels) do
<<~LABELS
[]
LABELS
end
it { expect { subject }.to raise_error("One provider must be selected") }
end
context "when multiple providers are selected" do
let(:labels) do
<<~LABELS
[
jenkins,
azure-devops
]
LABELS
end
it { expect { subject }.to raise_error("Only one provider can be selected") }
end
context "when an unsupported provider is selected" do
let(:labels) do
<<~LABELS
[
something-unsupported
]
LABELS
end
it { expect { subject }.to raise_error("One provider must be selected") }
end
context "when a single provider is selected" do
let(:labels) do
<<~LABELS
[
jenkins
]
LABELS
end
it { expect { subject }.not_to raise_error }
end
end
describe "#cli_command" do
subject { provider.cli_command }
let(:labels) do
<<~LABELS
[
gitlab
]
LABELS
end
it { is_expected.to eq("gitlab") }
end
describe "#module" do
subject { provider.module }
let(:labels) do
<<~LABELS
[
travis-ci
]
LABELS
end
it { is_expected.to eq(::TravisCI) }
end
describe "to_output" do
subject { provider.to_output }
let(:labels) do
<<~LABELS
[
azure-devops
]
LABELS
end
it { expect { subject }.to output(/::set-output name=provider::azure-devops/).to_stdout }
end
end
+29
View File
@@ -0,0 +1,29 @@
# frozen_string_literal: true
RSpec.describe TravisCI::Audit do
let(:audit) { described_class.new(issue_content, nil) }
describe "#to_a" do
subject { audit.to_a }
context "when issue_content contains no args" do
let(:issue_content) do
<<~ISSUE
Organization:
ISSUE
end
it { is_expected.to be_nil }
end
context "when issue_content contains an organization" do
let(:issue_content) do
<<~ISSUE
Organization: testing
ISSUE
end
it { is_expected.to eq(["--travis-ci-organization", "testing"]) }
end
end
end
+21
View File
@@ -0,0 +1,21 @@
# frozen_string_literal: true
RSpec.describe TravisCI::DryRun do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Organization: testing
ISSUE
end
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/dry-run --repository repo" }
it { is_expected.to eq(["--travis-ci-organization", "testing", "--travis-ci-repository", "repo"]) }
end
end
end
+21
View File
@@ -0,0 +1,21 @@
# frozen_string_literal: true
RSpec.describe TravisCI::Migrate do
let(:dry_run) { described_class.new(issue_content, command) }
let(:command) { Command.new(comment_body) }
describe "#to_a" do
subject { dry_run.to_a }
let(:issue_content) do
<<~ISSUE
Organization: testing
ISSUE
end
context "when the comment body contains a pipeline id" do
let(:comment_body) { "/migrate --repository repo --target-url https://github.com/org/repo" }
it { is_expected.to eq(["--travis-ci-organization", "testing", "--travis-ci-repository", "repo", "--target-url", "https://github.com/org/repo"]) }
end
end
end