rfc5424.t 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. use t::APISIX 'no_plan';
  18. repeat_each(1);
  19. no_long_string();
  20. no_root_location();
  21. add_block_preprocessor(sub {
  22. my ($block) = @_;
  23. if (!defined $block->request) {
  24. $block->set_value("request", "GET /t");
  25. }
  26. });
  27. run_tests();
  28. __DATA__
  29. === TEST 1: Compatibility testing
  30. --- config
  31. location /t {
  32. content_by_lua_block {
  33. local rfc5424 = require("apisix.utils.rfc5424")
  34. local structured_data = {
  35. {name = "project", value = "apisix.apache.org"},
  36. {name = "logstore", value = "apisix.apache.org"},
  37. {name = "access-key-id", value = "apisix.sls.logger"},
  38. {name = "access-key-secret", value = "BD274822-96AA-4DA6-90EC-15940FB24444"}
  39. }
  40. local data = rfc5424.encode("SYSLOG", "INFO", "localhost", "apisix",
  41. 123456, "hello world", structured_data)
  42. ngx.say(data)
  43. }
  44. }
  45. --- response_body eval
  46. qr/<46>1.*localhost apisix 123456 - \[logservice project=\"apisix\.apache\.org\" logstore=\"apisix\.apache\.org\" access-key-id=\"apisix\.sls\.logger\" access-key-secret=\"BD274822-96AA-4DA6-90EC-15940FB24444\"\] hello world/
  47. === TEST 2: No structured data test
  48. --- config
  49. location /t {
  50. content_by_lua_block {
  51. local rfc5424 = require("apisix.utils.rfc5424")
  52. local data = rfc5424.encode("SYSLOG", "INFO", "localhost", "apisix",
  53. 123456, "hello world")
  54. ngx.say(data)
  55. }
  56. }
  57. --- response_body eval
  58. qr/<46>1.*localhost apisix 123456 - - hello world/
  59. === TEST 3: No host and appname test
  60. --- config
  61. location /t {
  62. content_by_lua_block {
  63. local rfc5424 = require("apisix.utils.rfc5424")
  64. local data = rfc5424.encode("SYSLOG", "INFO", nil, nil,
  65. 123456, "hello world")
  66. ngx.say(data)
  67. }
  68. }
  69. --- response_body eval
  70. qr/<46>1.*- - 123456 - - hello world/