Skip to content

Commit

Permalink
Entrypoint specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronklaassen committed Dec 31, 2021
1 parent c04fd18 commit 3bc9dbc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if !ENV["GITHUB_TOKEN"]
exit(1)
end

if ARGV[0]&.empty?
if ARGV[0].nil? || ARGV[0].empty?
puts "Missing message argument."
exit(1)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/commenter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"
require "spec_helper"

RSpec.describe Commenter do
RSpec.describe Commenter do
let(:github) do
spy("GitHub", comments: [
{ "body" => "Oh, hi! I didn't see you there." },
Expand Down Expand Up @@ -82,4 +82,4 @@
end
end

end
end
28 changes: 28 additions & 0 deletions spec/entrypoint_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "spec_helper"

RSpec.describe "entrypoint.sh" do

def run_script(env = {}, args = [])
path = File.join(__dir__, "../entrypoint.sh")
Open3.capture3(env, path, *args)
end

let(:base_env) do
{
"GITHUB_TOKEN" => "secret",
"GITHUB_EVENT_PATH" => File.join(__dir__, "event.json")
}
end

it "fails without GITHUB_TOKEN" do
out, err, status = run_script
expect(out).to eq "Missing GITHUB_TOKEN\n"
expect(status.success?).to eq false
end

it "fails without message" do
out, err, status = run_script(base_env)
expect(out).to eq "Missing message argument.\n"
expect(status.success?).to eq false
end
end
5 changes: 5 additions & 0 deletions spec/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"respository": {
"full_name": "foo/bar"
}
}
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "json"
require "octokit"
require "open3"
require_relative "../lib/github"
require_relative "../lib/commenter"

0 comments on commit 3bc9dbc

Please sign in to comment.