Skip to content

Commit 0acada4

Browse files
committed
test/hello: DRY up JSON content-type in tests
1 parent d03aead commit 0acada4

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

test/hello/test/cloud_event_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void main() {
100100
final stderrOutput = await _makeBadRequest(
101101
_pubSubJsonString,
102102
{
103-
'Content-Type': 'application/json; charset=utf-8',
103+
...jsonContentType,
104104
'ce-specversion': '1.0',
105105
'ce-type': 'google.cloud.pubsub.topic.publish',
106106
'ce-time': 'bad time!',
@@ -136,7 +136,7 @@ void main() {
136136
}
137137
}''',
138138
{
139-
'Content-Type': 'application/json; charset=utf-8',
139+
...jsonContentType,
140140
'ce-specversion': '1.0',
141141
'ce-type': 'google.cloud.pubsub.topic.publish',
142142
'ce-time': 'bad time!',
@@ -183,9 +183,7 @@ void main() {
183183
}
184184
}
185185
}''';
186-
final response = await _makeRequest(body, {
187-
'Content-Type': 'application/json; charset=utf-8',
188-
});
186+
final response = await _makeRequest(body, jsonContentType);
189187
expect(response.statusCode, 200);
190188
expect(response.body, isEmpty);
191189
expect(

test/hello/test/custom_type_test.dart

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ void main() {
7878
final requestUrl = 'http://localhost:$autoPort/';
7979
final response = await post(
8080
requestUrl,
81-
headers: {
82-
'Content-Type': 'application/json; charset=utf-8',
83-
},
81+
headers: jsonContentType,
8482
body: 'not json!',
8583
);
8684

@@ -94,9 +92,7 @@ void main() {
9492
final requestUrl = 'http://localhost:$autoPort/';
9593
final response = await post(
9694
requestUrl,
97-
headers: {
98-
'Content-Type': 'application/json; charset=utf-8',
99-
},
95+
headers: jsonContentType,
10096
body: '[]',
10197
);
10298

@@ -123,9 +119,7 @@ void main() {
123119
final requestUrl = 'http://localhost:$autoPort/';
124120
final response = await post(
125121
requestUrl,
126-
headers: {
127-
'Content-Type': 'application/json; charset=utf-8',
128-
},
122+
headers: jsonContentType,
129123
body: jsonEncode(
130124
PubSub(
131125
PubSubMessage(
@@ -168,9 +162,7 @@ void main() {
168162
final requestUrl = 'http://localhost:$autoPort/';
169163
final response = await post(
170164
requestUrl,
171-
headers: {
172-
'Content-Type': 'application/json; charset=utf-8',
173-
},
165+
headers: jsonContentType,
174166
body: '{"a":1}',
175167
);
176168

@@ -197,9 +189,7 @@ void main() {
197189
final requestUrl = 'http://localhost:$autoPort/';
198190
final response = await post(
199191
requestUrl,
200-
headers: {
201-
'Content-Type': 'application/json; charset=utf-8',
202-
},
192+
headers: jsonContentType,
203193
body: '{"a":1}',
204194
);
205195
expect(response.statusCode, 200);
@@ -227,9 +217,7 @@ void main() {
227217
final requestUrl = 'http://localhost:$autoPort/';
228218
final response = await post(
229219
requestUrl,
230-
headers: {
231-
'Content-Type': 'application/json; charset=utf-8',
232-
},
220+
headers: jsonContentType,
233221
body: '{}',
234222
);
235223
expect(response.statusCode, 200);

test/hello/test/src/test_utils.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import 'package:http/http.dart' as http;
1818
import 'package:test/test.dart';
1919
import 'package:test_process/test_process.dart';
2020

21+
const jsonContentType = {
22+
'Content-Type': 'application/json; charset=utf-8',
23+
};
24+
2125
Future<http.Response> get(Object url, {Map<String, String>? headers}) =>
2226
http.get(url is String ? Uri.parse(url) : url as Uri, headers: headers);
2327

0 commit comments

Comments
 (0)