-
Notifications
You must be signed in to change notification settings - Fork 2
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
Create fastly-edge-assignments integration tests #75
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2209629
Create fastly-edge-assignments integration tests.
leoromanovsky 2ca741e
refactor
leoromanovsky d65f604
add test for CORS headers
leoromanovsky 48040c8
Merge branch 'main' into lr/poc-tests
leoromanovsky 9131130
rm fastly-edge-assignments/Makefile
leoromanovsky d5b3d39
Update .github/workflows/fastly-edge-assignments.yml
leoromanovsky 82668b8
Merge branch 'main' into lr/poc-tests
leoromanovsky a30a882
Revert "rm fastly-edge-assignments/Makefile"
leoromanovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,64 @@ | ||
name: Fastly Edge Assignments | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
cargo_build_and_test: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: fastly-edge-assignments | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
|
||
# Cache Rust toolchain and dependencies | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
~/.rustup/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-cargo- | ||
|
||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
target: wasm32-wasi | ||
|
||
# Install tools only if not cached | ||
- name: Install Tools | ||
run: | | ||
if ! command -v cargo-nextest &> /dev/null; then | ||
cargo install cargo-nextest | ||
fi | ||
if ! command -v fastly &> /dev/null; then | ||
wget https://github.com/fastly/cli/releases/download/v10.17.0/fastly_10.17.0_linux_amd64.deb | ||
sudo apt install ./fastly_10.17.0_linux_amd64.deb | ||
fi | ||
if ! command -v viceroy &> /dev/null; then | ||
cargo install viceroy | ||
fi | ||
|
||
# Build WASM target | ||
- run: make build | ||
|
||
# Run unit and integration tests | ||
- run: make 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
[build] | ||
target = "wasm32-wasi" | ||
|
||
[target.wasm32-wasi] | ||
runner = "viceroy run -C fastly.toml -- " | ||
|
||
[patch.crates-io] | ||
# Local override for development. | ||
eppo_core = { path = '../eppo_core' } |
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,31 @@ | ||
SHELL := bash | ||
.ONESHELL: | ||
.SHELLFLAGS := -eu -o pipefail -c | ||
.DELETE_ON_ERROR: | ||
MAKEFLAGS += --warn-undefined-variables | ||
MAKEFLAGS += --no-builtin-rules | ||
|
||
WASM_TARGET=wasm32-wasi | ||
BUILD_DIR=target/$(WASM_TARGET)/release | ||
WASM_FILE=$(BUILD_DIR)/$(FASTLY_PACKAGE).wasm | ||
|
||
# Help target for easy documentation | ||
.PHONY: help | ||
help: | ||
@echo "Available targets:" | ||
@echo " build - Build the WASM target" | ||
@echo " test - Run unit and integration tests" | ||
@echo " clean - Clean all build artifacts" | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf bin pkg | ||
|
||
.PHONY: build | ||
build: | ||
rustup target add $(WASM_TARGET) | ||
fastly compute build | ||
|
||
.PHONY: test | ||
test: | ||
cargo nextest run |
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,33 @@ | ||
# Eppo Assignments on Fastly Compute@Edge | ||
|
||
TODO: Add a description | ||
|
||
## Development | ||
|
||
Install Rust toolchain: | ||
|
||
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` | ||
|
||
Install Fastly CLI: | ||
|
||
`brew install fastly/tap/fastly` | ||
|
||
https://www.fastly.com/documentation/reference/tools/cli/ | ||
|
||
Install Viceroy: | ||
|
||
`cargo install viceroy` | ||
|
||
Build with Fastly: | ||
|
||
`make build` | ||
|
||
## Testing | ||
|
||
Install nextest: | ||
|
||
`cargo binstall cargo-nextest --secure` | ||
|
||
Run tests: | ||
|
||
`make 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,17 @@ mod handlers; | |
use fastly::http::{Method, StatusCode}; | ||
use fastly::{Error, Request, Response}; | ||
|
||
#[fastly::main] | ||
fn main(req: Request) -> Result<Response, Error> { | ||
#[cfg(test)] | ||
const TEST_HOST: &str = "test-host"; | ||
|
||
fn main() -> Result<(), Error> { | ||
let ds_req = Request::from_client(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required scaffolding to run integration tests. |
||
let us_resp = handler(ds_req)?; | ||
us_resp.send_to_client(); | ||
Ok(()) | ||
} | ||
|
||
fn handler(req: Request) -> Result<Response, Error> { | ||
// Handle CORS preflight requests | ||
if req.get_method() == Method::OPTIONS { | ||
return Ok(Response::from_status(StatusCode::NO_CONTENT) | ||
|
@@ -26,3 +35,44 @@ fn main(req: Request) -> Result<Response, Error> { | |
.with_header("Access-Control-Allow-Origin", "*") | ||
.with_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")) | ||
} | ||
|
||
#[test] | ||
fn test_health() { | ||
let req = fastly::Request::get(&format!("https://{}/health", TEST_HOST)); | ||
let resp = handler(req).expect("request succeeds"); | ||
assert_eq!(resp.get_status(), StatusCode::OK); | ||
assert_eq!(resp.into_body_str(), "OK"); | ||
} | ||
|
||
#[test] | ||
fn test_cors_headers() { | ||
let req = Request::get(&format!("https://{}/health", TEST_HOST)); | ||
let resp = handler(req).expect("request succeeds"); | ||
|
||
assert_eq!(resp.get_header("Access-Control-Allow-Origin").unwrap(), "*"); | ||
assert_eq!( | ||
resp.get_header("Access-Control-Allow-Methods").unwrap(), | ||
"GET, POST, OPTIONS" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_options_request() { | ||
let req = Request::new( | ||
Method::OPTIONS, | ||
&format!("https://{}/assignments", TEST_HOST), | ||
); | ||
let resp = handler(req).expect("request succeeds"); | ||
|
||
assert_eq!(resp.get_status(), StatusCode::NO_CONTENT); | ||
assert_eq!(resp.get_header("Access-Control-Allow-Origin").unwrap(), "*"); | ||
assert_eq!( | ||
resp.get_header("Access-Control-Allow-Methods").unwrap(), | ||
"GET, POST, OPTIONS" | ||
); | ||
assert_eq!( | ||
resp.get_header("Access-Control-Allow-Headers").unwrap(), | ||
"Content-Type" | ||
); | ||
assert_eq!(resp.get_header("Access-Control-Max-Age").unwrap(), "86400"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this step takes ~7 min so I added it to the github cache