104
|
1 -- for these tests, we issue HTTP requests to httpbin.org that performs smart echo (it returns all data/headers it has received + some extra data)
|
|
2
|
102
|
3 testSucceeded = true
|
|
4
|
|
5 local payload = {}
|
|
6 payload['stringMember'] = 'toto'
|
|
7 payload['intMember'] = 2
|
|
8
|
|
9 local httpHeaders = {}
|
|
10 httpHeaders['Content-Type'] = 'application/json'
|
|
11 httpHeaders['Toto'] = 'Tutu'
|
|
12
|
|
13 -- Issue HttpPost with body
|
|
14 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders))
|
|
15 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
|
|
16 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
|
104
|
17 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end
|
102
|
18
|
|
19 -- Issue HttpPost without body
|
|
20 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders))
|
|
21 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
|
104
|
22 testSucceeded = testSucceeded and (response['data'] == '')
|
|
23 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end
|
102
|
24
|
|
25 -- Issue HttpPut with body
|
|
26 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders))
|
|
27 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
|
104
|
28 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
|
|
29 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end
|
102
|
30
|
|
31 -- Issue HttpPut without body
|
|
32 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders))
|
|
33 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
|
104
|
34 testSucceeded = testSucceeded and (response['data'] == '')
|
|
35 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end
|
102
|
36
|
|
37 -- Issue HttpDelete (juste make sure it is issued, we can't check the response)
|
|
38 HttpDelete('http://httpbin.org/delete', httpHeaders)
|
|
39
|
|
40 -- Issue HttpGet
|
|
41 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
|
|
42 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
|
104
|
43 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end
|
102
|
44
|
|
45 if testSucceeded then
|
|
46 print('OK')
|
|
47 else
|
|
48 print('FAILED')
|
|
49 end
|