1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-10 23:08:59 +00:00

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
This commit is contained in:
Craig Labenz
2022-10-05 08:47:30 -07:00
committed by GitHub
parent 9d86093342
commit fc6222ebc8
152 changed files with 5219 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
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);
});
}