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
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
uses: actions/checkout@v5

- name: Set up mise
uses: jdx/mise-action@v2
uses: jdx/mise-action@v4

- name: Cache Go modules
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
Expand Down Expand Up @@ -88,16 +88,21 @@ jobs:
e2e:
name: E2E Tests
runs-on: ubuntu-latest
# The browser suite is slower than the unit tests; give it a clear ceiling
# that sits above the `go test -timeout 20m` budget in `mise run test-e2e`,
# so a genuine hang is reported by go test (with a stack dump) before the job
# is force-killed.
timeout-minutes: 25

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Set up mise
uses: jdx/mise-action@v2
uses: jdx/mise-action@v4

- name: Cache Go modules
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
Expand Down
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,21 +450,37 @@ This starts a local Go server and opens the test runner at `http://localhost:888
- Route URL generators
- UI components (Button, Badge, Table, Pagination, ...)

### E2E Tests (chromedp)
### E2E Tests (Cucumber + chromedp)

End-to-end tests use [chromedp](https://github.com/chromedp/chromedp) to run a headless Chrome browser:
End-to-end tests are written as [Cucumber](https://cucumber.io/) feature files
and run with [godog](https://github.com/cucumber/godog). Each scenario drives the
real dashboard in a headless Chrome browser (via
[chromedp](https://github.com/chromedp/chromedp)) against an in-process server —
true black-box testing through the UI a user actually sees. The only thing done
outside the browser is invoking a deployed function, which is a public HTTP
endpoint a real client would call directly.

The feature files in `e2e/features/` read like a product spec (no selectors, no
implementation detail); the step definitions in `e2e/*_test.go` translate that
intent into browser interactions.

Make sure Chrome or Chromium is installed before running them.

```bash
mise run test-e2e
# Run a single feature while iterating:
GODOG_FEATURE=e2e/features/sign_in.feature go test ./e2e/
```

E2E tests cover:
E2E scenarios cover:

- Login flow
- Page navigation
- Functions list rendering
- Signing in and out of the dashboard
- Creating, listing, renaming, and deleting functions
- Invoking functions over HTTP (Lua, Starlark, templates, methods, env vars)
- Editing code, version history, rollback, and version comparison
- Execution history and disabled/deleted-function behaviour
- The key-value store and cron scheduling
- The connected clients page

### Run All Tests

Expand Down
19 changes: 13 additions & 6 deletions docs/adr/0011-testing-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ We will test at four layers, each with a dedicated task:
3. **CLI integration tests** (`mise run test-cli-integration`) — built-tagged
(`-tags integration`) tests in `lunar-cli/integration` that exercise the
generated client against a real running server.
4. **End-to-end browser tests** (`mise run test-e2e`) — Go tests under `e2e/`
that boot the real API on an `httptest.Server` against a migrated SQLite
store and drive **headless Chrome via `chromedp`**, with a small fluent
`browserTest` helper. `mise run test-all` runs units + e2e together.
4. **End-to-end browser tests** (`mise run test-e2e`) — **Cucumber/Gherkin**
feature files under `e2e/features/`, run with
[godog](https://github.com/cucumber/godog). Each scenario boots the real API
on an `httptest.Server` against a migrated SQLite store and drives the
dashboard in **headless Chrome via `chromedp`**. The features are written at
the product level (no selectors, no implementation detail); the Go step
definitions in `e2e/*_test.go` translate that intent into browser
interactions. Function invocation — the one thing a real client does outside
the browser — is exercised over plain HTTP against the public `/fn` endpoint.
`mise run test-all` runs units + e2e together.

The unifying principle: wherever a runtime is needed, prefer **Go** as the test
harness (testserver, chromedp, httptest) rather than introducing a second
language's tooling.
harness (testserver, chromedp + godog, httptest) rather than introducing a
second language's tooling. godog keeps the e2e specs in Cucumber while the
harness stays pure Go.

## Consequences

Expand Down
9 changes: 9 additions & 0 deletions e2e/features/connected_clients.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Connected clients
Operators can review the API clients (such as the CLI) connected to the server.

Background:
Given I am signed in

Scenario: Viewing the connected clients page
When I open the connected clients page
Then the connected clients page should be shown
28 changes: 28 additions & 0 deletions e2e/features/execution_history.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Execution history
Every call to a function is recorded so operators can audit what happened.

Background:
Given I am signed in
And I create a function named "audited"
And I open the function "audited"

Scenario: A function that has never run has no history
When I view the function's execution history
Then the execution history should be empty

Scenario: Calling a function records an execution
When I call the function
And I view the function's execution history
Then the function should have 1 recorded execution
And the latest execution should be successful

Scenario: Each call is recorded separately
When I call the function
And I call the function
And I call the function
Then the function should have 3 recorded executions

Scenario: Inspecting a recorded execution
When I call the function
And I open the most recent execution
Then the execution should be shown as successful
66 changes: 66 additions & 0 deletions e2e/features/invoking_functions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Feature: Invoking functions
A deployed function is reachable over HTTP. These scenarios create a function
in the dashboard and then call it the way a real client would.

Background:
Given I am signed in

Scenario: A brand-new function responds out of the box
Given I create a function named "hello"
And I open the function "hello"
When I call the function
Then the function should respond successfully
And the response should contain "Hello from Lua!"

Scenario: A Starlark function responds too
Given I create a Starlark function named "hello-star"
And I open the function "hello-star"
When I call the function
Then the function should respond successfully
And the response should contain "Hello from Starlark!"

Scenario: A function built from the REST API template responds
Given I create a function named "rest" from the "api" template
And I open the function "rest"
When I call the function
Then the function should respond successfully

Scenario: A function can be called with different HTTP methods
Given I create a function named "methods"
And I open the function "methods"
And I change the function's code to:
"""
function handler(ctx, event)
return { statusCode = 200, body = event.method }
end
"""
When I call the function with the POST method
Then the function should respond successfully
And the response should be "POST"

Scenario: A disabled function cannot be called
Given I create a function named "switched-off"
And I open the function "switched-off"
When I disable the function
And I call the function
Then the call should be refused because the function is disabled

Scenario: A deleted function cannot be called
Given I create a function named "gone"
And I open the function "gone"
When I delete the function
And I call the function
Then the function should no longer be reachable

Scenario: Environment variables are available to the function
Given I create a function named "greeter-env"
And I open the function "greeter-env"
And I change the function's code to:
"""
function handler(ctx, event)
return { statusCode = 200, body = env.get("GREETING") or "unset" }
end
"""
And I give the function an environment variable "GREETING" set to "hola"
When I call the function
Then the response should be "hola"
39 changes: 39 additions & 0 deletions e2e/features/managing_functions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Feature: Managing functions
Operators create, find, rename, and delete functions from the dashboard.

Background:
Given I am signed in

Scenario: The functions list starts empty
Given I have not created any functions yet
When I view my functions
Then my functions list should be empty

Scenario: Creating a function
When I create a function named "greeter"
Then I should land back on my functions list
And I should see "greeter" in my functions list

Scenario: The list shows which language each function uses
Given I create a function named "lua-one"
And I create a Starlark function named "star-one"
When I view my functions
Then "Lua" should be shown as a supported language
And "Starlark" should be shown as a supported language

Scenario: A new function needs a name
When I try to create a function without giving it a name
Then I should be told the function needs a name

Scenario: Renaming a function
Given I create a function named "before-rename"
And I open the function "before-rename"
When I rename the function to "after-rename"
And I view my functions
Then I should see "after-rename" in my functions list

Scenario: Deleting a function
Given I create a function named "throwaway"
And I open the function "throwaway"
When I delete the function
Then I should no longer see "throwaway" in my functions list
16 changes: 16 additions & 0 deletions e2e/features/sign_in.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Signing in to the dashboard
The dashboard is protected by an API key. Operators sign in to manage their
functions and can sign out when they are done.

Scenario: Signing in with a valid key
When I sign in with a valid API key
Then I should reach the dashboard

Scenario: Signing in with an invalid key
When I sign in with an invalid API key
Then I should be told the key is invalid

Scenario: Signing out
Given I am signed in
When I sign out
Then I should be signed out
31 changes: 31 additions & 0 deletions e2e/features/stored_data.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Function data and scheduling
Functions can keep values in a key-value store and run on a schedule. Both are
configured from the dashboard.

Background:
Given I am signed in
And I create a function named "stateful"
And I open the function "stateful"

Scenario: Storing a value in the key-value store
When I store the value "ready" under the key "status"
Then the stored value "ready" should be kept under the key "status"

Scenario: Storing a value in the global store
When I store the value "shared-secret" under the global key "token"
Then the global value "shared-secret" should be kept under the key "token"

Scenario: A stored value is readable from the function
Given I store the value "blue" under the key "color"
And I change the function's code to:
"""
function handler(ctx, event)
return { statusCode = 200, body = kv.get("color") or "none" }
end
"""
When I call the function
Then the response should be "blue"

Scenario: Putting a function on a schedule
When I schedule the function to run every 5 minutes
Then I should see when the function will next run
13 changes: 13 additions & 0 deletions e2e/features/test_page.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature: Trying a function from the dashboard
The dashboard's Test page lets operators send a request to a function and see
the response without leaving the browser.

Background:
Given I am signed in
And I create a function named "playground"
And I open the function "playground"

Scenario: Running a function from the Test page
When I try the function from the Test page
Then the Test page should show a successful response
And the Test page response should contain "Hello from Lua!"
40 changes: 40 additions & 0 deletions e2e/features/versions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Feature: Working with versions
Every code change is saved as a new version. Operators can review the history,
roll back to an earlier version, and compare two versions side by side.

Background:
Given I am signed in
And I create a function named "evolving"
And I open the function "evolving"

Scenario: Editing the code creates a new version
When I change the function's code to:
"""
function handler(ctx, event)
return { statusCode = 200, body = "second cut" }
end
"""
Then the function should have 2 versions
And version 2 should be the active version

Scenario: Rolling back to an earlier version
Given I change the function's code to:
"""
function handler(ctx, event)
return { statusCode = 200, body = "new behaviour" }
end
"""
When I roll back to version 1
Then version 1 should be the active version
And I call the function
And the response should contain "Hello from Lua!"

Scenario: Comparing two versions
Given I change the function's code to:
"""
function handler(ctx, event)
return { statusCode = 200, body = "the changed line" }
end
"""
When I compare version 1 with version 2
Then I should see the differences between the two versions
Loading
Loading