simpleinfra icon indicating copy to clipboard operation
simpleinfra copied to clipboard

tests(compute-static): add basic unit tests

Open Carbonhell opened this issue 2 months ago • 1 comments

Closes #401 .

This PR adds a few basic unit tests with Viceroy, a local runner for Fastly compute functions. There are a few functions I couldn't test:

  • set_ttl: there's no way to retrieve the TTL set on a Request struct, and the function itself is trivial;
  • ~~send_request_to_s3: this function sends a HTTP request to the backend, and Viceroy does not allow intercepting them (see related issue). This also prevents implementing a test for handle_request.~~ out of scope for this PR (needs to be tested with an integration test due to wasm)

While working on this, I noticed the build target was still set to wasm32-wasi (see here), which was breaking builds due to the target not being found - I've renamed it accordingly. ~~Also, I couldn't build the function either with the latest version of Rust (1.91) due to an ongoing incident with Fastly. I've pinned the version to 1.90 to allow builds, again.~~ The incident was resolved, so I reverted the toolchain to stable.

The tests have been integrated in the CI as part of the "Rust projects" job, although this step takes slightly less than 6 minutes due to the installation of Viceroy, mostly. If that's too much time, I can look into caching, or we can split it to only download those tools and execute the tests when files change in the compute-static directory with dorny/paths-filter.

Carbonhell avatar Nov 09 '25 23:11 Carbonhell