Skip to content

Commit

Permalink
Remove cutlass integration tests (#674)
Browse files Browse the repository at this point in the history
* Remove cutlass integration tests

All equivalent checks that were done in the cutlass tests have been moved into the Rust integration tests which use the composite buildpacks to execute.
  • Loading branch information
colincasey authored Oct 4, 2023
1 parent fbd3054 commit 84c4cb8
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 328 deletions.
1 change: 0 additions & 1 deletion .rspec

This file was deleted.

9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions Gemfile

This file was deleted.

41 changes: 0 additions & 41 deletions Gemfile.lock

This file was deleted.

9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ please see [heroku/nodejs](https://github.com/heroku/heroku-buildpack-nodejs).
- [`jq`](https://github.com/stedolan/jq) >= `1.6`
- [`shpec`](https://github.com/rylnd/shpec)

#### For cutlass integration tests
- `Ruby` >= `2.7`
- `bundler` via `gem install bundler`

### Building

1. Run `cargo install libcnb-cargo` to [install the `libcnb` Cargo command](https://github.com/heroku/libcnb.rs#libcnb-cargo-command)
Expand All @@ -55,9 +51,8 @@ pack build example-app \

### Testing

- `cargo test` performs Rust unit and intgration tests for the `heroku/nodejs-engine` buildpack.
- `bundle exec rspec test/specs/node` runs cutlass integration tests for the `heroku/nodejs` buildpack.
- `bundle exec rspec test/specs/node-function` runs cutlass integration tests for the `heroku/nodejs-function` buildpack.
- `cargo test` runs Rust unit tests.
- `cargo test -- --ignored` runs Rust integration tests.
- `shpec buildpacks/npm/shpec/*_shpec.sh` runs the shpec unit tests for the `heroku/nodejs-npm` buildpack.
- `shpec buildpacks/nodejs-function-invoker/shpec/*_shpec.sh` runs the shpec unit tests for the `heroku/nodejs-function-invoker` buildpack.

Expand Down
36 changes: 35 additions & 1 deletion buildpacks/nodejs-engine/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![warn(clippy::pedantic)]

use libcnb_test::assert_contains;
use libcnb_test::{assert_contains, assert_not_contains};
use test_support::{
assert_web_response, nodejs_integration_test, nodejs_integration_test_with_config,
set_node_engine,
Expand Down Expand Up @@ -47,3 +47,37 @@ fn reinstalls_node_if_version_changes() {
},
);
}

// TODO: move this test & fixture to the npm buildpack once that is ready
#[test]
#[ignore]
fn npm_project_with_no_lockfile() {
nodejs_integration_test("../../../test/fixtures/npm-project", |ctx| {
assert_contains!(ctx.pack_stdout, "Installing Node");
assert_contains!(ctx.pack_stdout, "Installing node modules");

assert_not_contains!(ctx.pack_stdout, "Installing yarn");
assert_not_contains!(ctx.pack_stdout, "Installing node modules from ./yarn.lock");
assert_not_contains!(
ctx.pack_stdout,
"Installing node modules from ./package-lock.json"
);
});
}

// TODO: move this test & fixture to the npm buildpack once that is ready
#[test]
#[ignore]
fn npm_project_with_lockfile() {
nodejs_integration_test("../../../test/fixtures/npm-project-with-lockfile", |ctx| {
assert_contains!(ctx.pack_stdout, "Installing Node");
assert_contains!(ctx.pack_stdout, "Installing node modules");
assert_contains!(
ctx.pack_stdout,
"Installing node modules from ./package-lock.json"
);

assert_not_contains!(ctx.pack_stdout, "Installing yarn");
assert_not_contains!(ctx.pack_stdout, "Installing node modules from ./yarn.lock");
});
}
3 changes: 3 additions & 0 deletions buildpacks/nodejs-function-invoker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ thiserror.workspace = true
toml.workspace = true

[dev-dependencies]
base64 = "0.21"
hex = "0.4"
libcnb-test.workspace = true
rand = "0.8"
serde_json.workspace = true
tempfile.workspace = true
test_support.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions buildpacks/nodejs-function-invoker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use crate::function::{
use crate::layers::{
RuntimeLayer, RuntimeLayerError, ScriptLayer, ScriptLayerError, NODEJS_RUNTIME_SCRIPT,
};
#[cfg(test)]
use base64 as _;
#[cfg(test)]
use hex as _;
use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
use libcnb::data::build_plan::BuildPlanBuilder;
use libcnb::data::launch::{LaunchBuilder, ProcessBuilder};
Expand All @@ -21,6 +25,8 @@ use libcnb::{buildpack_main, Buildpack};
use libcnb_test as _;
use libherokubuildpack::error::on_error;
use libherokubuildpack::log::{log_error, log_header, log_info, log_warning};
#[cfg(test)]
use rand as _;
use serde::Deserialize;
#[cfg(test)]
use test_support as _;
Expand Down
101 changes: 83 additions & 18 deletions buildpacks/nodejs-function-invoker/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#![warn(clippy::pedantic)]

use base64::Engine;
use libcnb_test::{assert_contains, assert_not_contains, TestContext};
use rand::RngCore;
use std::net::SocketAddr;
use test_support::{
function_integration_test, retry, start_container, DEFAULT_RETRIES,
DEFAULT_RETRY_DELAY_IN_SECONDS,
function_integration_test, retry, start_container, DEFAULT_RETRIES, DEFAULT_RETRY_DELAY,
};

#[test]
#[ignore]
fn simple_javascript_function() {
function_integration_test("../../../test/fixtures/simple-function", |ctx| {
assert_contains!(ctx.pack_stdout, "Installing Node.js Function Invoker");
start_container_and_assert_health_check_responds(&ctx);
start_container(&ctx, |container, socket_addr| {
assert_health_check_responds(socket_addr);
let payload = serde_json::json!({});
let result = invoke_function(socket_addr, &payload);
assert_eq!(result, serde_json::Value::String("hello world".to_string()));
let container_logs = container.logs_now();
assert_contains!(container_logs.stdout, "logging info is a fun 1");
});
});
}

Expand All @@ -21,7 +29,15 @@ fn simple_javascript_function() {
fn simple_typescript_function() {
function_integration_test("../../../test/fixtures/simple-typescript-function", |ctx| {
assert_contains!(ctx.pack_stdout, "Installing Node.js Function Invoker");
start_container_and_assert_health_check_responds(&ctx);
start_container(&ctx, |_container, socket_addr| {
assert_health_check_responds(socket_addr);
let payload = serde_json::json!({});
let result = invoke_function(socket_addr, &payload);
assert_eq!(
result,
serde_json::Value::String("hello world from typescript".to_string())
);
});
});
}

Expand Down Expand Up @@ -89,25 +105,74 @@ fn test_function_with_implicit_runtime_dependency_ts() {
);
}

fn invoke_function(socket_addr: &SocketAddr, payload: &serde_json::Value) -> serde_json::Value {
let id = format!("MyFunction-{}", random_hex_string(10));

let sf_context = base64_encode_json(&serde_json::json!({
"apiVersion": "",
"payloadVersion": "",
"userContext": {
"orgId": "",
"userId": "",
"username": "",
"orgDomainUrl": "",
"onBehalfOfUserId": serde_json::Value::Null,
"salesforceBaseUrl": ""
}
}));

let ssfn_context = base64_encode_json(&serde_json::json!({
"resource": "",
"requestId": "",
"accessToken": "",
"apexClassId": serde_json::Value::Null,
"apexClassFQN": serde_json::Value::Null,
"functionName": "",
"functionInvocationId": serde_json::Value::Null
}));

let response = retry(DEFAULT_RETRIES, DEFAULT_RETRY_DELAY, || {
ureq::post(&format!("http://{socket_addr}"))
.set("Content-Type", "application/json")
.set("Authorization", "")
.set("ce-id", &id)
.set("ce-time", "2020-09-03T20:56:28.297915Z")
.set("ce-type", "")
.set("ce-source", "")
.set("ce-specversion", "1.0")
.set("ce-sfcontext", &sf_context)
.set("ce-sffncontext", &ssfn_context)
.send_json(payload.clone())
})
.unwrap();

response.into_json().expect("expected response to be json")
}

fn assert_health_check_responds(socket_addr: &SocketAddr) {
retry(
DEFAULT_RETRIES,
DEFAULT_RETRY_DELAY_IN_SECONDS,
|| {
ureq::post(&format!("http://{socket_addr}"))
.set("x-health-check", "true")
.call()
},
|res| {
let response_body = res.into_string().unwrap();
assert_contains!(response_body, "OK");
},
|error| panic!("request to assert function health check response failed: {error}"),
);
let response = retry(DEFAULT_RETRIES, DEFAULT_RETRY_DELAY, || {
ureq::post(&format!("http://{socket_addr}"))
.set("x-health-check", "true")
.call()
})
.unwrap();
let response_body = response.into_string().unwrap();
assert_contains!(response_body, "OK");
}

fn start_container_and_assert_health_check_responds(ctx: &TestContext) {
start_container(ctx, |_container, socket_addr| {
assert_health_check_responds(socket_addr);
});
}

fn random_hex_string(length: usize) -> String {
let mut bytes = Vec::with_capacity(length);
rand::thread_rng().fill_bytes(&mut bytes);
hex::encode(&bytes)
}

fn base64_encode_json(value: &serde_json::Value) -> String {
let json_string = serde_json::to_string(value).expect("Value should be encodable as JSON");
base64::engine::general_purpose::STANDARD.encode(json_string)
}
28 changes: 22 additions & 6 deletions buildpacks/nodejs-yarn/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ use test_support::{assert_web_response, nodejs_integration_test};
#[ignore = "integration test"]
fn yarn_1_typescript() {
nodejs_integration_test("../../../test/fixtures/yarn-1-typescript", |ctx| {
assert_contains!(ctx.pack_stdout, "Installing yarn");
assert_contains!(ctx.pack_stdout, "Installing Node");
assert_contains!(ctx.pack_stdout, "Installing yarn CLI");
assert_contains!(ctx.pack_stdout, "Installing dependencies");
assert_contains!(ctx.pack_stdout, "Running `build` script");

assert_not_contains!(ctx.pack_stdout, "corepack");
assert_not_contains!(
ctx.pack_stdout,
"Installing node modules from ./package-lock.json"
);

assert_web_response(&ctx, "yarn-1-typescript");
});
}
Expand All @@ -18,17 +26,25 @@ fn yarn_1_typescript() {
#[ignore = "integration test"]
fn yarn_2_pnp_zero() {
nodejs_integration_test("../../../test/fixtures/yarn-2-pnp-zero", |ctx| {
assert_contains!(ctx.pack_stdout, "Installing yarn");
assert_contains!(ctx.pack_stdout, "Installing Node");
assert_contains!(ctx.pack_stdout, "Installing yarn 2.4.1 via corepack");
assert_contains!(ctx.pack_stdout, "Yarn zero-install detected");
assert_contains!(ctx.pack_stdout, "Installing dependencies");
assert_not_contains!(
ctx.pack_stdout,
"can't be found in the cache and will be fetched from the remote registry"
);
assert_contains!(ctx.pack_stdout, "Resolution step");
assert_contains!(ctx.pack_stdout, "Fetch step");
assert_contains!(ctx.pack_stdout, "Link step");
assert_contains!(ctx.pack_stdout, "Completed");

assert_not_contains!(ctx.pack_stdout, "Installing yarn CLI");
assert_not_contains!(
ctx.pack_stdout,
"Installing node modules from ./package-lock.json"
);
assert_not_contains!(
ctx.pack_stdout,
"can't be found in the cache and will be fetched from the remote registry"
);

assert_web_response(&ctx, "yarn-2-pnp-zero");
});
}
Expand Down
10 changes: 0 additions & 10 deletions meta-buildpacks/nodejs-function/build.sh

This file was deleted.

10 changes: 0 additions & 10 deletions meta-buildpacks/nodejs/build.sh

This file was deleted.

Loading

0 comments on commit 84c4cb8

Please sign in to comment.