• Stars
    star
    141
  • Rank 259,042 (Top 6 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Viceroy provides local testing for developers working with Compute.

Viceroy

Viceroy provides local testing for developers working with Compute@Edge. It allows you to run services written against the Compute@Edge APIs on your local development machine, and allows you to configure testing backends for your service to communicate with.

Viceroy is normally used through the Fastly CLI's fastly compute serve command, where it is fully integrated into Compute@Edge workflows. However, it is also a standalone open source tool with its own CLI and a Rust library that can be embedded into your own testing infrastructure.

Installation

Via the Fastly CLI

As mentioned above, most users of Compute@Edge should do local testing via the Fastly CLI, rather than working with Viceroy directly. Any CLI release of version 0.34 or above supports local testing, and the workflow is documented here.

As a standalone tool from crates.io

To install Viceroy as a standalone tool, you'll need to first install Rust if you haven't already. Then run cargo install viceroy, which will download and build the latest Viceroy release.

Usage as a library

Viceroy can be used as a Rust library. This is useful if you want to run integration tests in the same codebase. We provide a helper method handle_request. Before you build or test your code, we recommend to set the release flag e.g. cargo test --release otherwise, the execution will be very slow. This has to do with the Cranelift compiler, which is extremely slow when compiled in debug mode. Besides that, if you use Github Actions don't forget to setup a build cache for Rust. This will speed up your build times a lot.

Usage as a standalone tool

NOTE: the Viceroy standalone CLI has a somewhat different interface from that of the Fastly CLI. Command-line options below describe the standalone Viceroy interface.

After installation, the viceroy command should be available on your path. The only required argument is the path to a compiled .wasm blob, which can be built by fastly compute build. The Fastly CLI should put the blob at bin/main.wasm. To test the service, you can run:

viceroy bin/main.wasm

This will start a local server (by default at: http://127.0.0.1:7676), which can be used to make requests to your Compute@Edge service locally. You can make requests by using curl, or you can send a simple GET request by visiting the URL in your web browser.

Usage as a test runner

Viceroy can also be used as a test runner for running Rust unit tests for Compute@Edge applications in the following way:

  1. Ensure the viceroy command is available in your path
  2. Add the following to your project's .cargo/config:
[build]
target = "wasm32-wasi"

[target.wasm32-wasi]
runner = "viceroy run -C fastly.toml -- "
  1. Install cargo-nextest
  2. Write your tests that use the fastly crate. For example:
#[test]
fn test_using_client_request() {
    let client_req = fastly::Request::from_client();
    assert_eq!(client_req.get_method(), Method::GET);
    assert_eq!(client_req.get_path(), "/");
}

#[test]
fn test_using_bodies() {
    let mut body1 = fastly::Body::new();
    body1.write_str("hello, ");
    let mut body2 = fastly::Body::new();
    body2.write_str("Viceroy!");
    body1.append(body2);
    let appended_str = body1.into_string();
    assert_eq!(appended_str, "hello, Viceroy!");
}

#[test]
fn test_a_handler_with_fastly_types() {
    let req = fastly::Request::get("http://example.com/Viceroy");
    let resp = some_handler(req).expect("request succeeds");
    assert_eq!(resp.get_content_type(), Some(TEXT_PLAIN_UTF_8));
    assert_eq!(resp.into_body_str(), "hello, /Viceroy!");
}
  1. Run your tests with cargo nextest run:
 % cargo nextest run
   Compiling unit-tests-test v0.1.0
    Finished test [unoptimized + debuginfo] target(s) in 1.16s
    Starting 3 tests across 1 binaries
        PASS [   2.106s] unit-tests-test::bin/unit-tests-test tests::test_a_handler_with_fastly_types
        PASS [   2.225s] unit-tests-test::bin/unit-tests-test tests::test_using_bodies
        PASS [   2.223s] unit-tests-test::bin/unit-tests-test tests::test_using_client_request
------------
     Summary [   2.230s] 3 tests run: 3 passed, 0 skipped

The reason that cargo-nextest is needed rather than just cargo test is to allow tests to keep executing if any other test fails. There is no way to recover from a panic in wasm, so test execution would halt as soon as the first test failure occurs. Because of this, we need each test to be executed in its own wasm instance and have the results aggregated to report overall success/failure. cargo-nextest handles that orchestration for us.

Documentation

Since the Fastly CLI uses Viceroy under the hood, the two share documentation for everything other than CLI differences. You can find general documentation for local testing here, and documentation about configuring local testing here. Documentation for Viceroy's CLI can be found via --help.

Colophon

Viceroy

The viceroy is a butterfly whose color and pattern mimics that of the monarch butterfly but is smaller in size.

More Repositories

1

pushpin

A proxy server for adding push to your API, used at the core of Fastly's Fanout service
Rust
3,639
star
2

ftw

Framework for Testing WAFs (FTW!)
Python
264
star
3

js-compute-runtime

JavaScript SDK and runtime for building Fastly Compute applications
C++
197
star
4

go-fastly

A Fastly API client for Go
Go
154
star
5

fastly-rails

Please visit https://github.com/fastly/fastly-ruby.
Ruby
143
star
6

cli

Build, deploy and configure Fastly services from your terminal
Go
139
star
7

fastly-magento2

Module for integrating Fastly CDN with Magento 2 installations
PHP
125
star
8

terraform-provider-fastly

Terraform Fastly provider
Go
119
star
9

Avalanche

Random, repeatable network fault injection
Python
104
star
10

fastly-exporter

A Prometheus exporter for the Fastly Real-time Analytics API
Go
97
star
11

fastly-ruby

A Fastly API client for Ruby
Ruby
91
star
12

compute-sdk-go

Go SDK for building Fastly Compute applications
Go
78
star
13

fastly-py

A Fastly API client for Python
Python
76
star
14

sidekiq-prometheus

Public repository with Prometheus instrumentation for Sidekiq
Ruby
74
star
15

wafefficacy

Measures the effectiveness of your Web Application Firewall (WAF)
Go
73
star
16

next-compute-js

Run Next.js on Fastly Compute
TypeScript
73
star
17

WordPress-Plugin

The Official Fastly WordPress Plugin
JavaScript
59
star
18

uslab

Lock-free slab allocator / freelist.
C
57
star
19

compute-starter-kit-rust-default

Default package template for Rust based Compute projects
Rust
50
star
20

go-utils

utils for go
Go
44
star
21

insights.js

Real user monitoring of network timing signals using the Open Insights framework
TypeScript
40
star
22

compute-actions

GitHub Actions for building on Fastly Compute.
JavaScript
39
star
23

compute-rust-auth

Authentication at Fastly's edge, using OAuth 2.0, OpenID Connect, and Fastly Compute.
Rust
36
star
24

waf_testbed

Chef Cookbook which provisions apache+mod_security+owasp-crs
HTML
35
star
25

fastlyctl

A CLI for managing Fastly configurations
Ruby
35
star
26

fastly2git

Create a git repository from Fastly service generated VCL
Ruby
32
star
27

token-functions

Example implementations for Fastly's token validation
Java
29
star
28

terrarium-rust-guest

The "http_guest" crate used by Fastly Labs Terrarium https://wasm.fastlylabs.com/
Rust
29
star
29

performance-observer-polyfill

🔎 Polyfill for the PerformanceObserver API
TypeScript
29
star
30

terrarium-templates

Template and example projects for Fastly Labs Terrarium https://wasm.fastlylabs.com
C
27
star
31

waflyctl

Fastly WAF CLI
Go
27
star
32

fastly-magento

Magento Extension for working with the Fastly Content Delivery Network
PHP
26
star
33

compute-js-static-publish

Static Publisher for Fastly Compute JavaScript
TypeScript
26
star
34

libvmod-urlcode

urlencode/urldecode functions vmod
C
24
star
35

fastly-php

A Fastly API client for PHP
PHP
24
star
36

compute-starter-kit-rust-static-content

Static content starter kit for Rust based Fastly Compute projects. Speed up your websites with a Compute application serving content from a static bucket, redirects, security and performance headers, and a 404 page.
Rust
23
star
37

log4j_interpreter

A Rust library for evaluating log4j substitution queries in order to determine whether or not malicious queries may exist.
Rust
22
star
38

expressly

Express style router for Fastly Compute
TypeScript
22
star
39

vcl-json-generate

A VCL module that allows you to generate JSON dynamically on the edge
VCL
21
star
40

compute-starter-kit-assemblyscript-default

Default package template for AssemblyScript based Fastly Compute projects
TypeScript
20
star
41

remix-compute-js

Remix for Fastly Compute JavaScript
TypeScript
19
star
42

compute-starter-kit-javascript-default

Default package template for JavaScript based Fastly Compute projects
JavaScript
19
star
43

fanout-compute-js-demo

Fanout Fastly Compute JavaScript demo
TypeScript
17
star
44

cd-with-terraform

Practical exercises for InfoQ "Continuous deployment with Terraform" workshop
HCL
16
star
45

fastly-perl

A Fastly API client for Perl
Perl
16
star
46

mruby-optparse

Port of Ruby's OptionParser to mruby
Ruby
16
star
47

http-compute-js

Node.js-compatible request and response objects
TypeScript
16
star
48

compute-at-edge-abi

Interface definitions for the Compute@Edge platform in witx.
Rust
15
star
49

compute-js-opentelemetry

An implementation of OpenTelemetry for Fastly Compute
TypeScript
14
star
50

blockbuster

VCR cassette manager
Ruby
13
star
51

demo-fiddle-ci

Using Fastly Fiddle to enable CI testing of Fastly services
JavaScript
13
star
52

secretd

Secret storage server
Go
12
star
53

fastly-rust

A Rust Fastly API client library.
Rust
12
star
54

heroku-fastly

Heroku CLI plugin for Fastly
JavaScript
10
star
55

go-mtr

go wrapped mtr --raw
Go
10
star
56

fastly-js

A Fastly API client for JavaScript
JavaScript
10
star
57

terrctl

A command-line client for Fastly Terrarium. https://wasm.fastlylabs.com
Go
10
star
58

compute-starter-kit-javascript-openapi-validation

OpenAPI Validation Starter Kit for Fastly Compute (JavaScript)
JavaScript
10
star
59

http_connection_monitor

Monitors your outbound HTTP requests for number of requests made over a persistent connection.
Ruby
9
star
60

security-use-cases

Placeholder for security related use cases and demos
HCL
9
star
61

fastly-test-blog

Test application for learning Fastly's UI
Ruby
9
star
62

uap-vcl

uap-vcl is a VCL module which parses a User-Agent string
VCL
8
star
63

sigsci-splunk-app

Splunk app for Fastly (Signal Sciences)
Python
8
star
64

librip

Librip is a minimal-overhead API for instruction-level tracing in highly concurrent software.
Python
8
star
65

fastly_nsq

Public repository with a convenience adapter & testing classes for apps talking to NSQ
Ruby
8
star
66

vscode-fastly-vcl

A Visual Studio Code extension which adds syntax highlighting for Fastly Varnish Configuration Language (VCL) files.
TypeScript
8
star
67

altitude-nyc-abcd-workshop

Practical exercises for "ABCD: Always be continuously deploying" workshop at Altitude NYC 2017
HCL
7
star
68

compute-starter-kit-typescript

A simple Fastly starter kit for Typescript
TypeScript
6
star
69

ember-anti-clickjacking

Anti-Clickjacking in Ember
JavaScript
6
star
70

compute-starter-kit-rust-beacon-termination

Beacon Termination package template for Rust based Fastly Compute projects.
Rust
6
star
71

Raikkonen

Räikkönen tests races.
C
6
star
72

js-compute-testing

Write JavaScript tests from Node.js, against a local or remote Fastly Compute application
TypeScript
6
star
73

diff-service

An experiment in powering Edge diff functionality from Google Cloud Functions
JavaScript
6
star
74

jlog-go

Go bindings for jlog
Go
6
star
75

vmdebootstrap

wrapper around debootstrap to create virtual machine disk images
Python
6
star
76

compute-starter-kit-go-default

Default package template for Go based Fastly Compute projects
Go
5
star
77

compute-hibp-filter

Fastly Compute enrichment to detect compromised passwords
Go
5
star
78

fastly-blocklist

Configure request blocking for a Fastly service.
Python
5
star
79

altitude-ci-cd-workshop

Practical exercises for "Building a continuous deployment pipeline" workshop at Altitude 2017
HCL
5
star
80

dnstap-utils

dnstap utilities implemented in Rust
Rust
5
star
81

compute-starter-kit-javascript-queue

Queuing package template for JavaScript based Fastly Compute projects. Park your users in a virtual queue to reduce the demand on your origins during peak times.
JavaScript
5
star
82

compute-starter-kit-rust-websockets

WebSockets starter kit for Fastly Compute (Rust)
Rust
4
star
83

altitude-LON-logging-workshop

Fiddle links & exercises for "Building an internal analytics platform with real-time logs" workshop at Altitude LON 2019
4
star
84

irc2slack

Python
4
star
85

Varnish-API

Perl extension for accessing varnish stats and logs
C
4
star
86

security-solutions-visualization-waf-bigquery-looker

4
star
87

compute-ll-hls

Fastly Compute application for LL-HLS playlist manipulation.
Rust
4
star
88

compute-starter-kit-javascript-empty

Empty package template for JavaScript based Fastly Compute projects
JavaScript
4
star
89

serve-vercel-build-output

A runtime environment that executes output that targets the Vercel Build Output API on Fastly Compute
TypeScript
4
star
90

compute-starter-kit-rust-empty

Empty package template for Rust based Fastly Compute projects
Rust
3
star
91

fastly-lem

Automate the deployment of Live Event Monitoring
Go
3
star
92

wasm-workshop-altitude-ldn-2019

Workshop materials for the "WebAssembly outside the web" workshop
Rust
3
star
93

compute-rust-sentry

Send error reports from Rust Fastly Compute services to Sentry.
Rust
3
star
94

compute-starter-kit-javascript-expressly

A lightweight starter kit for Fastly Compute, demonstrating the expressly framework.
JavaScript
3
star
95

fastly-template-rust-nel

Package template for a Rust based Network Error Logging Fastly Compute service
Rust
3
star
96

next-compute-js-server

Implementation of Next.js Server class for Fastly Compute JavaScript
TypeScript
3
star
97

compute-segmented-caching

Segmented Caching as a Fastly Compute app
Rust
3
star
98

homebrew-tap

Homebrew Formulae
Ruby
3
star
99

sse-demo

A demo of a streaming data use case for Fastly
CSS
3
star
100

compute-js-apiclarity

compute-js-apiclarity
JavaScript
3
star