-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sharpstone/schneems/tests
Introduce testing
- Loading branch information
Showing
9 changed files
with
276 additions
and
4 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,47 @@ | ||
|
||
version: 2 | ||
references: | ||
unit: &unit | ||
run: | ||
name: Run test suite | ||
command: PARALLEL_SPLIT_TEST_PROCESSES=25 bundle exec parallel_split_test spec/ | ||
restore: &restore | ||
restore_cache: | ||
keys: | ||
- v1_bundler_deps-{{ .Environment.CIRCLE_JOB }} | ||
save: &save | ||
save_cache: | ||
paths: | ||
- ./vendor/bundle | ||
key: v1_bundler_deps-{{ .Environment.CIRCLE_JOB }} # CIRCLE_JOB e.g. "ruby-2.5" | ||
hatchet_setup: &hatchet_setup | ||
run: | ||
name: Hatchet setup | ||
command: | | ||
bundle exec hatchet ci:setup | ||
bundle: &bundle | ||
run: | ||
name: install dependencies | ||
command: | | ||
bundle install --jobs=4 --retry=3 --path vendor/bundle | ||
bundle update | ||
bundle clean | ||
jobs: | ||
"ruby-2.7": | ||
docker: | ||
- image: circleci/ruby:2.7 | ||
steps: | ||
- checkout | ||
- <<: *restore | ||
- <<: *bundle | ||
- <<: *hatchet_setup | ||
- <<: *unit | ||
- <<: *save | ||
|
||
workflows: | ||
version: 2 | ||
build: | ||
jobs: | ||
- "ruby-2.7" | ||
|
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,4 @@ | ||
.DS_Store | ||
.rspec_status | ||
|
||
spec/fixtures/repos/generated/* |
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,5 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "parallel_split_test" | ||
gem "heroku_hatchet" | ||
gem "rspec-retry" |
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,75 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (6.0.3.1) | ||
concurrent-ruby (~> 1.0, >= 1.0.2) | ||
i18n (>= 0.7, < 2) | ||
minitest (~> 5.1) | ||
tzinfo (~> 1.1) | ||
zeitwerk (~> 2.2, >= 2.2.2) | ||
concurrent-ruby (1.1.6) | ||
diff-lcs (1.3) | ||
erubis (2.7.0) | ||
excon (0.73.0) | ||
heroics (0.0.25) | ||
erubis (~> 2.0) | ||
excon | ||
moneta | ||
multi_json (>= 1.9.2) | ||
heroku_hatchet (5.0.3) | ||
excon (~> 0) | ||
minitest-retry (~> 0.1.9) | ||
platform-api (~> 2) | ||
repl_runner (~> 0.0.3) | ||
rrrretry (~> 1) | ||
thor (~> 0) | ||
threaded (~> 0) | ||
i18n (1.8.2) | ||
concurrent-ruby (~> 1.0) | ||
minitest (5.14.1) | ||
minitest-retry (0.1.9) | ||
minitest (>= 5.0) | ||
moneta (1.0.0) | ||
multi_json (1.14.1) | ||
parallel (1.19.1) | ||
parallel_split_test (0.7.0) | ||
parallel (>= 0.5.13) | ||
rspec (>= 3.1.0) | ||
platform-api (2.2.0) | ||
heroics (~> 0.0.25) | ||
moneta (~> 1.0.0) | ||
repl_runner (0.0.3) | ||
activesupport | ||
rrrretry (1.0.0) | ||
rspec (3.9.0) | ||
rspec-core (~> 3.9.0) | ||
rspec-expectations (~> 3.9.0) | ||
rspec-mocks (~> 3.9.0) | ||
rspec-core (3.9.2) | ||
rspec-support (~> 3.9.3) | ||
rspec-expectations (3.9.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-mocks (3.9.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-retry (0.6.2) | ||
rspec-core (> 3.3) | ||
rspec-support (3.9.3) | ||
thor (0.20.3) | ||
thread_safe (0.3.6) | ||
threaded (0.0.4) | ||
tzinfo (1.2.7) | ||
thread_safe (~> 0.1) | ||
zeitwerk (2.3.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
heroku_hatchet | ||
parallel_split_test | ||
rspec-retry | ||
|
||
BUNDLED WITH | ||
2.1.4 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
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 @@ | ||
--- [] |
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,78 @@ | ||
require_relative "../spec_helper.rb" | ||
|
||
RSpec.describe "This buildpack" do | ||
it "accepts absolute paths at build and runtime" do | ||
app_dir = generate_fixture_app( | ||
name: "works", | ||
compile_script: <<~EOM | ||
#!/usr/bin/env bash | ||
# Test export | ||
echo "PATH=/good/absolute/path:$PATH" >> export | ||
# Test .profile.d | ||
BUILD_DIR=$1 | ||
mkdir -p $BUILD_DIR/.profile.d | ||
echo "PATH=/good/absolute/path:$PATH" >> $BUILD_DIR/.profile.d/my.sh | ||
EOM | ||
) | ||
|
||
buildpacks = [ | ||
"https://github.com/heroku/heroku-buildpack-inline", | ||
:default | ||
] | ||
|
||
Hatchet::Runner.new(app_dir, buildpacks: buildpacks).deploy do |app| | ||
expect(app.output).to_not include("All paths must be absolute") | ||
end | ||
end | ||
|
||
describe "export detection" do | ||
it "errors on relative paths" do | ||
app_dir = generate_fixture_app( | ||
name: "export_fails_relative", | ||
compile_script: <<~EOM | ||
#!/usr/bin/env bash | ||
echo "PATH=bad_export_path_because_im_relative:$PATH" >> export | ||
EOM | ||
) | ||
|
||
buildpacks = [ | ||
"https://github.com/heroku/heroku-buildpack-inline", | ||
:default | ||
] | ||
|
||
Hatchet::Runner.new(app_dir, buildpacks: buildpacks, allow_failure: true).deploy do |app| | ||
expect(app.output).to include("All paths must be absolute") | ||
end | ||
end | ||
end | ||
|
||
describe "profile.d detection" do | ||
it "errors on relative paths" do | ||
app_dir = generate_fixture_app( | ||
name: "export_fails_relative", | ||
compile_script: <<~EOM | ||
#!/usr/bin/env bash | ||
BUILD_DIR=$1 | ||
mkdir -p $BUILD_DIR/.profile.d | ||
echo "PATH=bad_export_path_because_im_relative:$PATH" >> $BUILD_DIR/.profile.d/my.sh | ||
EOM | ||
) | ||
|
||
buildpacks = [ | ||
"https://github.com/heroku/heroku-buildpack-inline", | ||
:default | ||
] | ||
|
||
Hatchet::Runner.new(app_dir, buildpacks: buildpacks, allow_failure: true).deploy do |app| | ||
expect(app.output).to include("All paths must be absolute") | ||
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,57 @@ | ||
require "bundler/setup" | ||
|
||
require 'rspec/retry' | ||
|
||
ENV["HATCHET_BUILDPACK_BASE"] = "https://github.com/sharpstone/force_absolute_paths_buildpack.git" | ||
|
||
require 'hatchet' | ||
require 'pathname' | ||
|
||
RSpec.configure do |config| | ||
# Enable flags like --only-failures and --next-failure | ||
config.example_status_persistence_file_path = ".rspec_status" | ||
config.verbose_retry = true # show retry status in spec process | ||
config.default_retry_count = 2 if ENV['IS_RUNNING_ON_CI'] # retry all tests that fail again | ||
|
||
config.expect_with :rspec do |c| | ||
c.syntax = :expect | ||
end | ||
end | ||
|
||
require 'parallel_tests/test/runtime_logger' if ENV['RECORD_RUNTIME'] | ||
|
||
def run!(cmd) | ||
out = `#{cmd}` | ||
raise "Error running #{cmd}, output: #{out}" unless $?.success? | ||
out | ||
end | ||
|
||
def spec_dir | ||
Pathname.new(__dir__) | ||
end | ||
|
||
|
||
def generate_fixture_app(compile_script:, name: ) | ||
app_dir = spec_dir.join("fixtures/repos/generated/#{name}") | ||
bin_dir = app_dir.join("bin") | ||
bin_dir.mkpath | ||
|
||
bin_compile = bin_dir.join("compile") | ||
bin_compile.write(compile_script) | ||
|
||
bin_detect = bin_dir.join("detect") | ||
bin_detect.write(<<~EOM) | ||
#!/usr/bin/env bash | ||
echo "inline buildpack" | ||
exit 0 | ||
EOM | ||
|
||
app_dir.join("Procfile").write("") | ||
|
||
FileUtils.chmod("+x", bin_compile) | ||
FileUtils.chmod("+x", bin_detect) | ||
|
||
app_dir | ||
end |