mirror of
https://github.com/foss42/apidash.git
synced 2025-05-21 16:26:37 +08:00
Update dart_to_curl_test.dart
This commit is contained in:
@ -3,8 +3,12 @@ import 'package:curl_parser/curl_parser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('Basic HTTP Methods', () {
|
group(
|
||||||
test('GET request', () {
|
'Basic HTTP Methods',
|
||||||
|
() {
|
||||||
|
test(
|
||||||
|
'GET request',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
@ -13,9 +17,12 @@ void main() {
|
|||||||
curl.toCurlString(),
|
curl.toCurlString(),
|
||||||
'curl "https://api.apidash.dev"',
|
'curl "https://api.apidash.dev"',
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('POST request', () {
|
test(
|
||||||
|
'POST request',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
uri: Uri.parse('https://api.apidash.dev/test'),
|
uri: Uri.parse('https://api.apidash.dev/test'),
|
||||||
@ -24,7 +31,8 @@ void main() {
|
|||||||
curl.toCurlString(),
|
curl.toCurlString(),
|
||||||
'curl -X POST "https://api.apidash.dev/test"',
|
'curl -X POST "https://api.apidash.dev/test"',
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('HEAD request', () {
|
test('HEAD request', () {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
@ -36,10 +44,15 @@ void main() {
|
|||||||
'curl -I "https://api.apidash.dev"',
|
'curl -I "https://api.apidash.dev"',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
group('Headers and Data', () {
|
group(
|
||||||
test('request with headers', () {
|
'Headers and Data',
|
||||||
|
() {
|
||||||
|
test(
|
||||||
|
'request with headers',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
@ -54,7 +67,8 @@ void main() {
|
|||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Authorization: Bearer token123"''',
|
-H "Authorization: Bearer token123"''',
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('POST request with data', () {
|
test('POST request with data', () {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
@ -70,9 +84,12 @@ void main() {
|
|||||||
-d '{"key": "value"}'""",
|
-d '{"key": "value"}'""",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
group('Form Data', () {
|
group(
|
||||||
|
'Post with Form Data',
|
||||||
|
() {
|
||||||
test('request with form data', () {
|
test('request with form data', () {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -100,10 +117,15 @@ void main() {
|
|||||||
-F "name=test"''',
|
-F "name=test"''',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
group('Special Parameters', () {
|
group(
|
||||||
test('request with cookie', () {
|
'Special Parameters',
|
||||||
|
() {
|
||||||
|
test(
|
||||||
|
'request with cookie',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
@ -114,9 +136,12 @@ void main() {
|
|||||||
r"""curl "https://api.apidash.dev" \
|
r"""curl "https://api.apidash.dev" \
|
||||||
-b 'session=abc123'""",
|
-b 'session=abc123'""",
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('request with user credentials', () {
|
test(
|
||||||
|
'request with user credentials',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
@ -127,9 +152,12 @@ void main() {
|
|||||||
r"""curl "https://api.apidash.dev" \
|
r"""curl "https://api.apidash.dev" \
|
||||||
-u 'username:password'""",
|
-u 'username:password'""",
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('request with referer', () {
|
test(
|
||||||
|
'request with referer',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
@ -140,9 +168,12 @@ void main() {
|
|||||||
r"""curl "https://api.apidash.dev" \
|
r"""curl "https://api.apidash.dev" \
|
||||||
-e 'https://example.com'""",
|
-e 'https://example.com'""",
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('request with user agent', () {
|
test(
|
||||||
|
'request with user agent',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
@ -153,9 +184,12 @@ void main() {
|
|||||||
r"""curl "https://api.apidash.dev" \
|
r"""curl "https://api.apidash.dev" \
|
||||||
-A 'MyApp/1.0'""",
|
-A 'MyApp/1.0'""",
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('request with insecure flag', () {
|
test(
|
||||||
|
'request with insecure flag',
|
||||||
|
() {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
@ -165,7 +199,8 @@ void main() {
|
|||||||
curl.toCurlString(),
|
curl.toCurlString(),
|
||||||
r"""curl "https://api.apidash.dev" -k""",
|
r"""curl "https://api.apidash.dev" -k""",
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('request with location flag', () {
|
test('request with location flag', () {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
@ -178,9 +213,12 @@ void main() {
|
|||||||
r"""curl "https://api.apidash.dev" -L""",
|
r"""curl "https://api.apidash.dev" -L""",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
group('Complex Requests', () {
|
group(
|
||||||
|
'Complex Requests',
|
||||||
|
() {
|
||||||
test('request with all parameters', () {
|
test('request with all parameters', () {
|
||||||
final curl = Curl(
|
final curl = Curl(
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -209,5 +247,6 @@ void main() {
|
|||||||
-A 'MyApp/1.0' -k -L""",
|
-A 'MyApp/1.0' -k -L""",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user