Skip to content

Commit 1cc8455

Browse files
committed
test(e2e): add docker e2e tests
1 parent de6247b commit 1cc8455

File tree

13 files changed

+228
-2
lines changed

13 files changed

+228
-2
lines changed

.github/workflows/.docker_tests.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Docker Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
setup:
7+
required: false
8+
type: string
9+
default: ""
10+
test_directory:
11+
required: false
12+
type: string
13+
default: "e2e"
14+
working_directory:
15+
required: false
16+
type: string
17+
default: "."
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
defaults:
23+
run:
24+
working-directory: ${{inputs.working_directory}}
25+
26+
steps:
27+
- name: 📚 Git Checkout
28+
uses: actions/checkout@v3
29+
30+
- name: 🎯 Setup Dart
31+
uses: dart-lang/setup-dart@v1
32+
33+
- name: ⚙️ Run Setup
34+
if: "${{inputs.setup != ''}}"
35+
run: ${{inputs.setup}}
36+
37+
- name: 📦 Install Dependencies
38+
run: dart pub get
39+
40+
- name: 🐸 Dart Frog Build
41+
run: dart_frog build
42+
43+
- name: 🐳 Build Docker Image
44+
run: docker build -q build -t e2e-image
45+
46+
- name: ⚡️ Run Docker Image
47+
run: docker run -d -p 8080:8080 --name e2e --rm e2e-image
48+
49+
- name: 🧪 Run Docker Tests
50+
run: dart test ${{inputs.test_directory}}
51+
52+
- name: 🧹 Docker Cleanup
53+
if: success() || failure()
54+
run: |
55+
docker stop e2e
56+
docker image rm e2e-image

.github/workflows/examples_counter.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "examples/counter/routes/**"
1111
- "examples/counter/lib/**"
1212
- "examples/counter/test/**"
13+
- "examples/counter/e2e/**"
1314
- ".github/workflows/examples_counter.yaml"
1415
- "packages/dart_frog/lib/**"
1516
- "packages/dart_frog/pubspec.yaml"
@@ -23,3 +24,9 @@ jobs:
2324
working_directory: examples/counter
2425
analyze_directories: "routes test"
2526
report_on: "routes"
27+
28+
docker:
29+
uses: ./.github/workflows/.docker_tests.yaml
30+
with:
31+
setup: rm pubspec_overrides.yaml && dart pub global activate --source path ../../packages/dart_frog_cli
32+
working_directory: examples/counter

.github/workflows/examples_echo.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "examples/echo/routes/**"
1111
- "examples/echo/lib/**"
1212
- "examples/echo/test/**"
13+
- "examples/echo/e2e/**"
1314
- ".github/workflows/examples_echo.yaml"
1415
- "packages/dart_frog/lib/**"
1516
- "packages/dart_frog/pubspec.yaml"
@@ -23,3 +24,9 @@ jobs:
2324
working_directory: examples/echo
2425
analyze_directories: "routes test"
2526
report_on: "routes"
27+
28+
docker:
29+
uses: ./.github/workflows/.docker_tests.yaml
30+
with:
31+
setup: rm pubspec_overrides.yaml && dart pub global activate --source path ../../packages/dart_frog_cli
32+
working_directory: examples/echo

.github/workflows/examples_hello_world.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "examples/hello_world/routes/**"
1111
- "examples/hello_world/lib/**"
1212
- "examples/hello_world/test/**"
13+
- "examples/hello_world/e2e/**"
1314
- ".github/workflows/examples_hello_world.yaml"
1415
- "packages/dart_frog/lib/**"
1516
- "packages/dart_frog/pubspec.yaml"
@@ -23,3 +24,9 @@ jobs:
2324
working_directory: examples/hello_world
2425
analyze_directories: "routes test"
2526
report_on: "routes"
27+
28+
docker:
29+
uses: ./.github/workflows/.docker_tests.yaml
30+
with:
31+
setup: rm pubspec_overrides.yaml && dart pub global activate --source path ../../packages/dart_frog_cli
32+
working_directory: examples/hello_world

.github/workflows/examples_todos.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- "examples/todos/test/**"
1313
- "examples/todos/packages/**/lib/**"
1414
- "examples/todos/packages/**/test/**"
15+
- "examples/todos/packages/**/e2e/**"
1516
- ".github/workflows/examples_todos.yaml"
1617
- "packages/dart_frog/lib/**"
1718
- "packages/dart_frog/pubspec.yaml"
@@ -26,6 +27,12 @@ jobs:
2627
analyze_directories: "routes test"
2728
report_on: "routes"
2829

30+
docker:
31+
uses: ./.github/workflows/.docker_tests.yaml
32+
with:
33+
setup: rm pubspec_overrides.yaml && dart pub global activate --source path ../../packages/dart_frog_cli
34+
working_directory: examples/todos
35+
2936
todos_data_source:
3037
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
3138
with:

examples/counter/e2e/index_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'dart:io';
2+
3+
import 'package:http/http.dart' as http;
4+
import 'package:test/test.dart';
5+
6+
void main() {
7+
group('E2E', () {
8+
test('GET / increments the count on each request', () async {
9+
const numRequests = 10;
10+
for (var i = 1; i <= numRequests; i++) {
11+
final response = await http.get(Uri.parse('http://localhost:8080'));
12+
expect(response.statusCode, equals(HttpStatus.ok));
13+
expect(
14+
response.body,
15+
equals('You have requested this route $i time(s).'),
16+
);
17+
}
18+
});
19+
});
20+
}

examples/counter/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
dart_frog: ^0.0.1-dev
1111

1212
dev_dependencies:
13+
http: ^0.13.5
1314
mocktail: ^0.3.0
1415
test: ^1.19.2
1516
very_good_analysis: ^3.0.1

examples/echo/e2e/[message]_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'dart:io';
2+
3+
import 'package:http/http.dart' as http;
4+
import 'package:test/test.dart';
5+
6+
void main() {
7+
group('E2E', () {
8+
test('GET /<message> echos back <message>', () async {
9+
final messages = ['hello', 'world'];
10+
for (final message in messages) {
11+
final response = await http.get(
12+
Uri.parse('http://localhost:8080/$message'),
13+
);
14+
expect(response.statusCode, equals(HttpStatus.ok));
15+
expect(response.body, equals(message));
16+
}
17+
});
18+
});
19+
}

examples/echo/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
dart_frog: ^0.0.1-dev
1111

1212
dev_dependencies:
13+
http: ^0.13.5
1314
mocktail: ^0.3.0
1415
test: ^1.19.2
1516
very_good_analysis: ^3.0.1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'dart:io';
2+
3+
import 'package:http/http.dart' as http;
4+
import 'package:test/test.dart';
5+
6+
void main() {
7+
group('E2E', () {
8+
test('GET / responds with "Welcome to Dart Frog!"', () async {
9+
final response = await http.get(Uri.parse('http://localhost:8080'));
10+
expect(response.statusCode, equals(HttpStatus.ok));
11+
expect(response.body, equals('Welcome to Dart Frog!'));
12+
});
13+
14+
test('GET /favicon.ico responds with the favicon.cio', () async {
15+
final response = await http.get(
16+
Uri.parse('http://localhost:8080/favicon.ico'),
17+
);
18+
expect(response.statusCode, equals(HttpStatus.ok));
19+
expect(response.body, isNotEmpty);
20+
});
21+
});
22+
}

0 commit comments

Comments
 (0)