Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/install-tinygo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
tinygo-version:
description: "The version of TinyGo to install"
required: true
default: "0.33.0"
default: "0.39.0"
runs:
using: "composite"
steps:
Expand Down
22 changes: 13 additions & 9 deletions .github/workflows/build-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ on:
jobs:
build-examples:
runs-on: ubuntu-latest

strategy:
matrix:
include:
# Newest supported configuration
- go-version: '1.23' # pairs with TinyGo 0.33.0
tinygo-version: '0.33.0'
- go-version: "1.25" # pairs with TinyGo 0.39.0
tinygo-version: "0.39.0"
# Oldest supported configuration
- go-version: '1.21' # pairs with TinyGo 0.29.0
tinygo-version: '0.29.0'
- go-version: "1.23" # pairs with TinyGo 0.33.0
tinygo-version: "0.33.0"

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: ./.github/actions/install-tinygo
with:
tinygo-version: ${{ matrix.tinygo-version }}

- name: Build examples Go
env:
Expand All @@ -37,9 +36,14 @@ jobs:
cd ${GITHUB_WORKSPACE}/$i && go build -tags fastlyinternaldebug
done

- uses: acifani/setup-tinygo@v2
with:
tinygo-version: ${{ matrix.tinygo-version }}
binaryen-version: "124"

- name: Build examples TinyGo
run: |
for i in _examples/*/; do
echo ${GITHUB_WORKSPACE}/$i
cd ${GITHUB_WORKSPACE}/$i && tinygo build -target=wasi -tags fastlyinternaldebug
cd ${GITHUB_WORKSPACE}/$i && tinygo build -target=wasip1 -tags fastlyinternaldebug
done
33 changes: 12 additions & 21 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,34 @@ on:
jobs:
integration-tests:
runs-on: ubuntu-latest

strategy:
matrix:
include:
# Newest supported configuration
- go-version: "1.23" # pairs with TinyGo 0.33.0+
- go-version: "1.25.1" # pairs with TinyGo 0.39.0+
tinygo-version: "0.39.0"
tinygo-wasi-target: "wasip1"
- go-version: "1.23.12" # pairs with TinyGo 0.33.0+
tinygo-version: "0.35.0"
tinygo-wasi-target: "wasip1"
- go-version: "1.22" # pairs with TinyGo 0.31.2
tinygo-version: "0.31.2"
tinygo-wasi-target: "wasi"
# Oldest supported configuration
- go-version: "1.21" # pairs with TinyGo 0.29.0
tinygo-version: "0.29.0"
tinygo-wasi-target: "wasi"

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- uses: ./.github/actions/install-tinygo
with:
tinygo-version: ${{ matrix.tinygo-version }}
- run: tinygo version

- name: Setup Fastly CLI
uses: fastly/compute-actions/setup@v7

- name: Install Viceroy
run: make tools/viceroy

- name: Print dependency versions
run: |
go version
tinygo version
fastly version
viceroy --version
uses: fastly/compute-actions/setup@v11
with:
verbose: true
- run: fastly version

- name: Tests - Go
run: make test-go
Expand Down
29 changes: 9 additions & 20 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,17 @@ on:
jobs:
validate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: actions/checkout@v5

- uses: ./.github/actions/install-tinygo
- id: setup-go
uses: actions/setup-go@v5
with:
tinygo-version: "0.35.0"

- name: Print dependency versions
run: |
go version
tinygo version
go-version-file: go.mod

- run: go vet ./...
- name: vet
run: go vet ./...

- name: staticcheck
run: |
Expand All @@ -32,16 +27,10 @@ jobs:

- name: nilness
run: |
go install golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@master
go install golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@v0.36.0
nilness ./...

- name: ineffassign
run: |
go install github.com/gordonklaus/ineffassign@latest
go install github.com/gordonklaus/ineffassign@v0.2.0
ineffassign ./...

- name: Install viceroy
run: make tools/viceroy

- name: Run Tests
run: make test
79 changes: 46 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,60 +1,73 @@
.DEFAULT: test

test: test-go test-tinygo test-integration
.PHONY: test

# Makes tools/viceroy available as an executable within Makefile recipes.
PATH := $(PWD)/tools:$(PATH)
test: test-go test-tinygo test-integration test-e2e

# Override these with environment variables or directly on the make command line.
GO_BUILD_FLAGS := -tags=fastlyinternaldebug,nofastlyhostcalls
GO_TEST_FLAGS := -v
GO_PACKAGES := ./...

.PHONY: test-go
test-go:
@echo ">> Running Go tests..." >&2
go test $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)
.PHONY: test-go

# Using this target lets viceroy provide the wasm runtime, eliminating a dependency on wasmtime.
TINYGO_TARGET := ./targets/fastly-compute-wasip1.json

test-tinygo:
tinygo test -target=$(TINYGO_TARGET) $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)
.PHONY: test-tinygo
test-tinygo: viceroy
@echo ">> Running TinyGo tests..." >&2
tinygo test -target=$(TINYGO_TARGET) $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)

# Integration tests use viceroy and override the default values for these variables.
test-integration-%: GO_BUILD_FLAGS := -tags=fastlyinternaldebug
test-integration-%: GO_PACKAGES := ./integration_tests/...

test-integration: test-integration-go test-integration-tinygo

.PHONY: test-integration
test-integration: test-integration-go test-integration-tinygo

test-integration-go: tools/viceroy
GOARCH=wasm GOOS=wasip1 go test -exec "viceroy run -C fastly.toml" $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)
.PHONY: test-integration-go
test-integration-go: viceroy
@echo ">> Running Go integration tests..." >&2
GOARCH=wasm GOOS=wasip1 go test -exec "viceroy run -C fastly.toml" $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)

test-integration-tinygo: tools/viceroy
tinygo test -target=$(TINYGO_TARGET) $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)
.PHONY: test-integration-tinygo
test-integration-tinygo: viceroy
@echo ">> Running TinyGo integration tests..." >&2
tinygo test -target=$(TINYGO_TARGET) $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)

# End to end tests use serve.sh and override the default values for these variables.
test-e2e-%: GO_BUILD_FLAGS := -tags=fastlyinternaldebug
test-e2e-%: GO_PACKAGES := ./end_to_end_tests/...
test-e2e-%: export PATH := $(PWD)/end_to_end_tests:$(PATH) # allows go test to find serve.sh

.PHONY: test-e2e
test-e2e: test-e2e-go test-e2e-tinygo

.PHONY: test-e2e-go
test-e2e-go: viceroy
@echo ">> Running Go end-to-end tests..." >&2
GOARCH=wasm GOOS=wasip1 go test -exec "serve.sh viceroy run -C fastly.toml" $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)

.PHONY: test-e2e-tinygo
test-e2e-tinygo: TINYGO_TARGET := ./targets/fastly-compute-wasip1-serve.json
test-e2e-tinygo: viceroy
@echo ">> Running TinyGo end-to-end tests..." >&2
tinygo test -target=$(TINYGO_TARGET) $(GO_BUILD_FLAGS) $(GO_TEST_FLAGS) $(GO_PACKAGES)

tools/viceroy: | tools # Download latest version of Viceroy ./tools/viceroy; delete it if you'd like to upgrade
@arch=$$(uname -m | sed 's/x86_64/amd64/'); \
os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
url=$$(curl -s https://api.github.com/repos/fastly/viceroy/releases/latest | jq --arg arch $$arch --arg os $$os -r '.assets[] | select((.name | contains($$arch)) and (.name | contains($$os))) | .browser_download_url'); \
filename=$$(basename $$url); \
curl -sSLO $$url && \
tar -xzf $$filename --directory ./tools/ && \
rm $$filename && \
./tools/viceroy --version && \
touch ./tools/viceroy
ifneq ($(strip $(GITHUB_PATH)),)
@echo "$(PWD)/tools" >> "$(GITHUB_PATH)"
endif

tools:
@mkdir -p tools

viceroy-update:
@rm -f tools/viceroy
@$(MAKE) tools/viceroy
.PHONY: viceroy-update
.PHONY: viceroy
viceroy:
@which viceroy || ( \
echo "viceroy not found: please ensure it is installed and available in your PATH:" && \
echo $$PATH && \
echo && \
echo "The fastly CLI installs Viceroy in the fastly subdirectory of the path returned by" && \
echo "os.UserConfigDir():" && \
echo " > On Unix systems, it returns \$$XDG_CONFIG_HOME if non-empty, else \$$HOME/.config." && \
echo " > On Darwin, it returns \$$HOME/Library/Application Support." && \
echo "From https://pkg.go.dev/os#UserConfigDir" && \
exit 1 \
)
2 changes: 2 additions & 0 deletions end_to_end_tests/loopback/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
pkg/
15 changes: 15 additions & 0 deletions end_to_end_tests/loopback/fastly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file describes a Fastly Compute package. To learn more visit:
# https://www.fastly.com/documentation/reference/compute/fastly-toml

authors = []
description = ""
language = "go"
manifest_version = 3
name = "serve on loopback test"
service_id = ""

[scripts]
build = "GOARCH=wasm GOOS=wasip1 go build -tags fastlyinternaldebug -o bin/main.wasm ."

[local_server.backends.self]
url = "http://127.0.0.1:23456/"
18 changes: 18 additions & 0 deletions end_to_end_tests/loopback/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !test

package main

import (
"context"

"github.com/fastly/compute-sdk-go/fsthttp"
)

func main() {
handler := func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("X-Test-Header", "present")
w.Write([]byte("OK"))
}
fsthttp.ServeFunc(handler)
}
40 changes: 40 additions & 0 deletions end_to_end_tests/loopback/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//go:build ((tinygo.wasm && wasi) || wasip1) && !nofastlyhostcalls

package main

import (
"context"
"io"
"testing"

"github.com/fastly/compute-sdk-go/fsthttp"
)

func TestLoopback(t *testing.T) {
req, err := fsthttp.NewRequest("GET", "http://anyplace.horse", nil)
if err != nil {
t.Fatal(err)
}
resp, err := req.Send(context.Background(), "self")
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()

if h, want := resp.Header.Get("content-type"), "text/plain"; h != want {
t.Errorf("Content-Type = %s, want: %s", h, want)
}
if resp.Header.Get("date") == "" {
t.Errorf("expected default Date header is missing")
}
if h, want := resp.Header.Get("x-test-header"), "present"; h != want {
t.Errorf("X-Test-Header = %s, want: %s", h, want)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if b, want := string(body), "OK"; b != want {
t.Errorf("resp.Body = %s, want: %s", b, want)
}
}
Loading
Loading