1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 14:28:51 +00:00
Files
samples/code_sharing/server/test/server_test.dart
Craig Labenz fc6222ebc8 Add code sharing sample (#1444)
* code-sharing boilerplate

* initial commit of code-sharing logic

* documentation improvements

* added code-sharing to samples.yaml

* Updated counter UI to visually indicate communication with the server

* added code_sharing to CI

* CI changes to code_sharing

* fixed test with DI

* formatting

* added shared module to CI

* adds forgotten CI change
2022-10-05 08:47:30 -07:00

41 lines
997 B
Dart

import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart';
import 'package:test/test.dart';
// Manual test:
// $ dart bin/server.dart
// $ curl -X POST -d '{"by": 1}' -H "Content-Type: application/json" localhost:8080/
void main() {
final port = '8080';
final host = 'http://0.0.0.0:$port';
late Process p;
setUp(() async {
p = await Process.start(
'dart',
['run', 'bin/server.dart'],
environment: {'PORT': port},
);
// Wait for server to start and print to stdout.
await p.stdout.first;
});
tearDown(() => p.kill());
test('Increment', () async {
final response = await post(Uri.parse('$host/'), body: '{"by": 1}');
expect(response.statusCode, 200);
expect(response.body, '{"value":1}');
});
test('Get', () async {
final response = await get(Uri.parse('$host/'));
expect(response.statusCode, 200);
final resp = json.decode(response.body) as Map;
expect(resp.containsKey('value'), true);
});
}