Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce testing #2

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .circleci/config.yml
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"

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.rspec_status

spec/fixtures/repos/generated/*
5 changes: 5 additions & 0 deletions Gemfile
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"
75 changes: 75 additions & 0 deletions Gemfile.lock
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
12 changes: 8 additions & 4 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env ruby
#!/usr/bin/env ruby

require 'pathname'
require 'fileutils'
Expand All @@ -17,19 +17,23 @@ FileUtils.mv(check_script, vendor_file)

puts "-----> Updating release script in procfile"
procfile = BUILD_DIR.join("Procfile")

procfile_written = false

if procfile.file?
contents = +""
contents = String.new("")
procfile.each_line do |line|
if line.start_with?("release")
procfile_written = true
contents << "#{line.chomp} && ruby bin/check_paths\n"
else
contents << line
end
end

procfile.write(contents)
else
procfile.write("release: ruby bin/check_paths\n")
end

procfile.write("release: ruby bin/check_paths\n") unless procfile_written

exit(0)
1 change: 1 addition & 0 deletions hatchet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions hatchet.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--- []
78 changes: 78 additions & 0 deletions spec/hatchet/buildpack_spec.rb
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
57 changes: 57 additions & 0 deletions spec/spec_helper.rb
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