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

Allow running subsequent integration test builds #422

Merged
merged 7 commits into from
Jun 23, 2022

Conversation

Malax
Copy link
Member

@Malax Malax commented Jun 22, 2022

To achieve a consistent API, breaking changes had to be made to allow sharing of TestConfig (formerly IntegrationTest) for both initial and subsequent test runs. The biggest change is the addition of TestRunner which is now the way to run tests.

Even though it's a breaking change, migration to this new API should be simple. See examples in this PR for an idea of required changes.

Changelog

  • Remove IntegrationTest::run_test, to run a test use the new TestRunner::run_test function.
  • Rename IntegrationTest to TestConfig.
  • Rename IntegrationTestContext to TestContext.
  • Add Clone implementation for TestConfig, allowing it to be shared across tests.
  • Add TestContext::run_test and TestContext::run_test_inherit_config, allowing you to run subsequent integration tests with the image from a previous test. These functions allow testing of subsequent builds, including caching logic and buildpack behaviour when build environment variables change, stacks are upgraded and more.

Examples

#[test]
fn basic() {
    TestRunner::default().run_test(
        TestConfig::new("heroku/buildpacks:20", "test-fixtures/simple-ruby-app"),
        |context| {
            assert_contains!(context.pack_stdout, "---> Ruby Buildpack");
            assert_contains!(context.pack_stdout, "---> Installing bundler");
            assert_contains!(context.pack_stdout, "---> Installing gems");

            context.run_test_inherit_config(|context| {
                assert_not_contains!(context.pack_stdout, "---> Installing bundler");
                assert_not_contains!(context.pack_stdout, "---> Installing gems");
            });
        },
    );
}

#[test]
fn clear_bundler_cache() {
    let base_config = TestConfig::new("heroku/buildpacks:20", "test-fixtures/simple-ruby-app");

    TestRunner::default().run_test(&base_config, |context| {
        assert_contains!(context.pack_stdout, "---> Ruby Buildpack");
        assert_contains!(context.pack_stdout, "---> Installing bundler");
        assert_contains!(context.pack_stdout, "---> Installing gems");

        context.run_test(
            // Subsequent tests can be run using a different config, allowing testing of stack
            // changes, different environment variables, etc. Since TestConfig is now Clone,
            // configuration can be easily shared.
            base_config.clone().env("CLEAR_BUNDLER_CACHE", "true"),
            |context| {
                assert_contains!(context.pack_stdout, "---> Installing bundler");
                assert_contains!(context.pack_stdout, "---> Installing gems");
            },
        );
    });
}

Closes #278, GUS-W-10539929

@Malax Malax force-pushed the malax/subsequent-test-runs branch 8 times, most recently from f542682 to 31d6692 Compare June 22, 2022 15:41
@Malax Malax force-pushed the malax/subsequent-test-runs branch 2 times, most recently from d147c30 to f0e5ae1 Compare June 23, 2022 12:02
@Malax Malax force-pushed the malax/subsequent-test-runs branch from 52e3367 to 3159531 Compare June 23, 2022 12:09
@Malax Malax marked this pull request as ready for review June 23, 2022 12:12
@Malax Malax requested a review from a team as a code owner June 23, 2022 12:12
Malax and others added 6 commits June 23, 2022 18:03
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
@Malax Malax force-pushed the malax/subsequent-test-runs branch from 45bda1f to 603e1d6 Compare June 23, 2022 16:27
@Malax Malax merged commit 83356f9 into main Jun 23, 2022
@Malax Malax deleted the malax/subsequent-test-runs branch June 23, 2022 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow running subsequent integration test builds
2 participants