This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
forked from heroku/heroku-buildpack-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hatchet Regression Tests (heroku#969)
I went through all the tests in the Ruby buildpack and cataloged what I think can be generalized between languages to prevent regressions. This PR add tests for these cases: * Test CI deploys run tests and use the cache [[reference test](https://github.com/heroku/heroku-buildpack-ruby/blob/f488bd53c7ff0b78e17c2405166cbd4a3af75ee2/spec/hatchet/ci_spec.rb#L36)] * Test cache for regular deploys is used on repeated deploys (This was already tested on the Python buildpack, I moved it) [[reference test](https://github.com/heroku/heroku-buildpack-ruby/blob/e34c583c139911d059f5627bb25125707288f053/spec/hatchet/stack_spec.rb#L21-L25)] * Test modifying a requirement clears the cache appropriately (This was already tested on the Python buildpack, I moved it) * Test deploying the getting started guide works [[reference test](https://github.com/heroku/heroku-buildpack-ruby/blob/424a7245e2da86845a20d58a9482bcf2a00c3a8f/spec/hatchet/getting_started_spec.rb#L5)] * Test that all paths set by the buildpack are absolute instead of relative [[reference test](https://github.com/heroku/heroku-buildpack-ruby/blob/249d3c1a4e97068f8fd016f10fa0839709d95658/spec/hatchet/rails5_spec.rb#L68]) * Test upgrading stack invalidates the cache [[reference test](https://github.com/heroku/heroku-buildpack-ruby/blob/f488bd53c7ff0b78e17c2405166cbd4a3af75ee2/spec/hatchet/stack_spec.rb#L3)] * Test that builds fail when a bad version is specified [[reference test](https://github.com/heroku/heroku-buildpack-ruby/blob/249d3c1a4e97068f8fd016f10fa0839709d95658/spec/hatchet/ruby_spec.rb#L5)] In addition to that I've also got a CNB test with `pack-build` with the getting started app, but since python isn't `cnb` capable yet I didn't add one.
- Loading branch information
Showing
8 changed files
with
119 additions
and
74 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
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ gem "rspec" | |
gem "heroku_hatchet" | ||
gem "rspec-retry" | ||
gem "rake" | ||
gem "parallel_split_test" | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"python": [ | ||
"heroku/python-getting-started" | ||
"heroku/python-getting-started", | ||
"sharpstone/python_default" | ||
] | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
--- | ||
- - "./repos/python/python-getting-started" | ||
- 443a90c58be6881583cd7ef628e3869e3c30bb98 | ||
- master | ||
- - "./repos/python/python_default" | ||
- ca947f69027b2a30be5d26f9a42f25e54f4d7a1a |
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,33 @@ | ||
require_relative '../spec_helper' | ||
|
||
describe "Heroku CI" do | ||
it "works" do | ||
before_deploy = Proc.new do | ||
File.open("app.json", "w+") do |f| | ||
f.puts <<~EOM | ||
{ | ||
"environments": { | ||
"test": { | ||
"scripts": { | ||
"test": "nosetests" | ||
} | ||
} | ||
} | ||
} | ||
EOM | ||
end | ||
|
||
run!("echo nose >> requirements.txt") | ||
end | ||
|
||
Hatchet::Runner.new("python_default", before_deploy: before_deploy).run_ci do |test_run| | ||
expect(test_run.output).to match("Downloading nose") | ||
expect(test_run.output).to match("OK") | ||
|
||
test_run.run_again | ||
|
||
expect(test_run.output).to match("installing from cache") | ||
expect(test_run.output).to_not match("Downloading nose") | ||
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 |
---|---|---|
@@ -1,68 +1,72 @@ | ||
require_relative '../spec_helper' | ||
|
||
describe "Default Python Deploy" do | ||
describe "Python" do | ||
describe "cache" do | ||
it "functions correctly" do | ||
Hatchet::Runner.new("python_default").deploy do |app| | ||
expect(app.output).to match(/Installing pip/) | ||
|
||
def set_python_version(d, v) | ||
Dir.chdir(d) do | ||
File.open('runtime.txt', 'w') do |f| | ||
f.puts "python-#{v}" | ||
end | ||
`git add runtime.txt && git commit -am "setting python version"` | ||
end | ||
end | ||
|
||
before(:each) do | ||
set_python_version(app.directory, python_version) | ||
init_app(app) | ||
end | ||
expect(app.output).to_not match("Requirements file has been changed, clearing cached dependencies") | ||
expect(app.output).to_not match("No change in requirements detected, installing from cache") | ||
expect(app.output).to_not match("No such file or directory") | ||
expect(app.output).to_not match("cp: cannot create regular file") | ||
|
||
["3.7.6", "3.8.2"].each do |version| | ||
context "on python-#{version}" do | ||
let(:app) { Hatchet::Runner.new('python-getting-started', stack: DEFAULT_STACK) } | ||
let(:python_version) { version } | ||
it "🐍" do | ||
app.deploy do |app| | ||
# What should happen on first deploy | ||
expect(app.output).to match(/Installing pip/) | ||
# Redeploy with changed requirements file | ||
run!(%Q{echo "" >> requirements.txt}) | ||
run!(%Q{echo "pygments" >> requirements.txt}) | ||
run!(%Q{git add . ; git commit --allow-empty -m next}) | ||
app.push! | ||
|
||
# What should not happen | ||
expect(app.output).to_not match("Requirements file has been changed, clearing cached dependencies") | ||
expect(app.output).to_not match("No change in requirements detected, installing from cache") | ||
expect(app.output).to_not match("No such file or directory") | ||
expect(app.output).to_not match("cp: cannot create regular file") | ||
# Check the cache to have cleared | ||
expect(app.output).to match("Requirements file has been changed, clearing cached dependencies") | ||
expect(app.output).to_not match("No dependencies found, preparing to install") | ||
expect(app.output).to_not match("No change in requirements detected, installing from cache") | ||
|
||
# let the previous build finish | ||
sleep(5) | ||
# With no changes on redeploy, the cache should be present | ||
run!(%Q{git commit --allow-empty -m next}) | ||
app.push! | ||
|
||
# Redeploy with changed requirements file | ||
run!(%Q{echo "" >> requirements.txt}) | ||
run!(%Q{echo "flask" >> requirements.txt}) | ||
run!(%Q{git add . ; git commit --allow-empty -m next}) | ||
app.push! | ||
|
||
# Check the cache to have cleared | ||
expect(app.output).to match("Requirements file has been changed, clearing cached dependencies") | ||
|
||
# What should not happen when the requirements file is changed | ||
expect(app.output).to_not match("No dependencies found, preparing to install") | ||
expect(app.output).to_not match("No change in requirements detected, installing from cache") | ||
|
||
# let the previous build finish | ||
sleep(5) | ||
|
||
run!(%Q{git commit --allow-empty -m next}) | ||
app.push! | ||
expect(app.output).to match("No change in requirements detected, installing from cache") | ||
expect(app.output).to_not match("Requirements file has been changed, clearing cached dependencies") | ||
expect(app.output).to_not match("No dependencies found, preparing to install") | ||
end | ||
end | ||
end | ||
|
||
# With no changes on redeploy, the cache should | ||
expect(app.output).to match("No change in requirements detected, installing from cache") | ||
describe "python versions" do | ||
let(:stack) { ENV["HEROKU_TEST_STACK"] || DEFAULT_STACK } | ||
it "works with 3.7.6" do | ||
version = "3.7.6" | ||
before_deploy = -> { run!(%Q{echo "python-#{version}" >> runtime.txt}) } | ||
Hatchet::Runner.new("python_default", before_deploy: before_deploy, stack: stack).deploy do |app| | ||
expect(app.run('python -V')).to match(version) | ||
end | ||
end | ||
|
||
# With no changes on redeploy, the cache should not | ||
expect(app.output).to_not match("Requirements file has been changed, clearing cached dependencies") | ||
expect(app.output).to_not match("No dependencies found, preparing to install") | ||
it "works with 3.8.2" do | ||
version = "3.8.2" | ||
before_deploy = -> { run!(%Q{echo "python-#{version}" >> runtime.txt}) } | ||
Hatchet::Runner.new("python_default", before_deploy: before_deploy, stack: stack).deploy do |app| | ||
expect(app.run('python -V')).to match(version) | ||
end | ||
end | ||
|
||
expect(app.run('python -V')).to match(version) | ||
end | ||
it "fails with a bad version" do | ||
version = "3.8.2.lol" | ||
before_deploy = -> { run!(%Q{echo "python-#{version}" >> runtime.txt}) } | ||
Hatchet::Runner.new("python_default", before_deploy: before_deploy, stack: stack, allow_failure: true).deploy do |app| | ||
expect(app.output).to match("not available for this stack") | ||
end | ||
end | ||
end | ||
|
||
it "getting started app has no relative paths" do | ||
buildpacks = [ | ||
:default, | ||
"https://github.com/sharpstone/force_absolute_paths_buildpack" | ||
] | ||
Hatchet::Runner.new("python-getting-started", buildpacks: buildpacks).deploy do |app| | ||
# Deploy works | ||
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