Skip to content

Commit a88e48e

Browse files
committed
add e2e test runner
1 parent 127d533 commit a88e48e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Simple HTTP server to save artifacts
66
- [Usage](#usage)
77
- [Authentication](#authentication)
88
- [TLS](#tls)
9+
- [Testing](#testing)
910
- [API](#api)
1011
- [`POST /upload`](#post-upload)
1112
- [`PUT /files/:path`](#put-filespath)
@@ -78,6 +79,30 @@ v1 has TLS support but I decided to omit it from v2.
7879

7980
Please consider using a reverse proxy like nginx.
8081

82+
## Testing
83+
84+
To run all tests, just run `go test` as usual:
85+
86+
```
87+
$ go test ./...
88+
```
89+
90+
This includes end-to-end tests. By default, the server with on-memory FileSystem is created and it starts listening on
91+
the port chosen randomly. You can control this behavior by setting the environment variables.
92+
93+
If `TEST_WITH_REAL_FS=${PATH_TO_DOCUMENT_ROOT}` is set, the test server uses the real filesystem. Make sure the document
94+
root directory contains no files; otherwise, some tests might be failed. The directory will not be cleaned after testing.
95+
96+
If `TEST_TARGET_ADDR-${HOST}:${PORT}` is set, the test program doesn't start a local test server and sends requests to
97+
`http://${HOST}:${PORT}`. Note that the target server's document root should be cleared prior to testing.
98+
99+
This repository has `docker-compose.e2e.yml` to run the E2E test. To run tests using this:
100+
101+
```
102+
$ docker compose -f docker-compose.e2e.yml run --rm test
103+
$ docker compose -f docker-compose.e2e.yml down --rmi local --volumes
104+
```
105+
81106
## API
82107

83108
### `POST /upload`

docker-compose.e2e.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
tags:
6+
- "mayth/simple-upload-server:testing"
7+
ports:
8+
- "127.0.0.1::8080"
9+
volumes:
10+
- docroot:/docroot
11+
command: -document_root=/docroot -addr=:8080
12+
test:
13+
image: golang:1.21
14+
environment:
15+
- TEST_WITH_REAL_FS=/docroot
16+
- TEST_TARGET_ADDR=app:8080
17+
volumes:
18+
- .:/app
19+
- docroot:/docroot
20+
working_dir: /app
21+
command: go test -v -run TestServer ./...
22+
depends_on:
23+
- app
24+
volumes:
25+
docroot:

0 commit comments

Comments
 (0)