|
| 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 | + |
| 18 | +use t::APISIX 'no_plan'; |
| 19 | + |
| 20 | +log_level("info"); |
| 21 | +repeat_each(1); |
| 22 | +no_long_string(); |
| 23 | +no_root_location(); |
| 24 | + |
| 25 | +add_block_preprocessor(sub { |
| 26 | + my ($block) = @_; |
| 27 | + |
| 28 | + if (!defined $block->request) { |
| 29 | + $block->set_value("request", "GET /t"); |
| 30 | + } |
| 31 | +}); |
| 32 | + |
| 33 | +BEGIN { |
| 34 | + $ENV{CLICK_HOUSE_USER} = "default"; |
| 35 | +} |
| 36 | + |
| 37 | +run_tests(); |
| 38 | + |
| 39 | +__DATA__ |
| 40 | +
|
| 41 | +=== TEST 1: pass clickhouse user via environment variable |
| 42 | +--- config |
| 43 | + location /t { |
| 44 | + content_by_lua_block { |
| 45 | + local t = require("lib.test_admin").test |
| 46 | + local code, body = t('/apisix/admin/routes/1', |
| 47 | + ngx.HTTP_PUT, |
| 48 | + [[{ |
| 49 | + "plugins": { |
| 50 | + "clickhouse-logger": { |
| 51 | + "user": "$ENV://CLICK_HOUSE_USER", |
| 52 | + "password": "", |
| 53 | + "database": "default", |
| 54 | + "logtable": "test", |
| 55 | + "endpoint_addr": "http://127.0.0.1:8123" |
| 56 | + } |
| 57 | + }, |
| 58 | + "upstream": { |
| 59 | + "nodes": { |
| 60 | + "127.0.0.1:1982": 1 |
| 61 | + }, |
| 62 | + "type": "roundrobin" |
| 63 | + }, |
| 64 | + "uri": "/opentracing" |
| 65 | + }]] |
| 66 | + ) |
| 67 | +
|
| 68 | + if code >= 300 then |
| 69 | + ngx.status = code |
| 70 | + end |
| 71 | + ngx.say(body) |
| 72 | + } |
| 73 | + } |
| 74 | +--- response_body |
| 75 | +passed |
| 76 | +
|
| 77 | +
|
| 78 | +
|
| 79 | +=== TEST 2: hit route |
| 80 | +--- request |
| 81 | +GET /opentracing |
| 82 | +--- error_code: 200 |
| 83 | +--- wait: 5 |
| 84 | +
|
| 85 | +
|
| 86 | +
|
| 87 | +=== TEST 3: get log |
| 88 | +--- exec |
| 89 | +echo "select * from default.test" | curl 'http://localhost:8123/' --data-binary @- |
| 90 | +--- response_body_like |
| 91 | +.*127.0.0.1.*1.* |
0 commit comments