test_wlan.lua 948 B

1234567891011121314151617181920212223242526272829303132333435
  1. test_wlan = {}
  2. gpio.setup(20, 1) -- 打开lan供电
  3. local url = "http://httpbin.air32.cn"
  4. -- 测试用例函数
  5. function test_wlan.test_wan()
  6. log.info("启动HTTP测试")
  7. local tests = { -- GET 方法测试
  8. {
  9. method = "GET",
  10. url = url .. "/get",
  11. headers = nil,
  12. body = nil,
  13. opts = {
  14. adapter = socket.LWIP_ETH
  15. },
  16. expected_code = 200,
  17. description = "GET方法,无请求头、body以及额外的附加数据"
  18. }}
  19. -- 调试输出
  20. local code = http.request("GET", "https://www.air32.cn/").wait()
  21. -- 验证返回值
  22. if code == tests.expected_code then
  23. log.info("本次测试的是", tests.description, "code 符合预期结果 code = ", code)
  24. else
  25. log.info("本次测试的是", tests.description, "预期结果为", tests.expected_code,
  26. "code 不符合预期结果 code =", code)
  27. end
  28. end
  29. return test_wlan