小编Ric*_*ich的帖子

使用Sinon在javascript中存储Redis交互

我在node.js工作.我的应用程序通过node_redis模块与Redis交互.我正在使用mocha和sinon自动测试我的应用程序.我的应用程序看起来像这样:

...snip
var redisClient = redis.createClient(redisPort, redisHost);
var someValue = redisClient.get("someKey");
return someValue;
....
Run Code Online (Sandbox Code Playgroud)

我想将调用存根到redisClient.get().要做到这一点,我还需要将调用存根到redis.createClient() - 我想......这是我的测试代码:

...
var redis = require("redis");
var redisClient;
...
sinon.stub(redisClient, 'get').returns("someValue");
sinon.stub(redis, "createClient").returns(redisClient);
...
assert.equal(redis_client_underTest.call_to_redis(), "someValue");
...
Run Code Online (Sandbox Code Playgroud)

测试失败了 AssertionError: false == "someValue"

我该如何存根redisClient,或者这甚至可能?

javascript mocha.js redis node.js sinon

12
推荐指数
1
解决办法
4529
查看次数

fluentd 不解析 JSON 日志文件条目

我在 Stackoverflow 上看到了许多类似的问题,包括这个。但没有一个解决我的特殊问题。

该应用程序部署在 Kubernetes (v1.15) 集群中。我正在使用基于fluent/fluentd-docker-image GitHub 存储库的docker 镜像v1.9/armhf,修改为包含 elasticsearch 插件。Elasticsearch 和 Kibana 都是version 7.6.0.

日志将进入标准输出,如下所示:

{"Application":"customer","HTTPMethod":"GET","HostName":"","RemoteAddr":"10.244.4.154:51776","URLPath":"/customers","level":"info","msg":"HTTP request received","time":"2020-03-10T20:17:32Z"}
Run Code Online (Sandbox Code Playgroud)

在 Kibana 中,我看到了这样的事情:

{
  "_index": "logstash-2020.03.10",
  "_type": "_doc",
  "_id": "p-UZxnABBcooPsDQMBy_",
  "_version": 1,
  "_score": null,
  "_source": {
    "log": "{\"Application\":\"customer\",\"HTTPMethod\":\"GET\",\"HostName\":\"\",\"RemoteAddr\":\"10.244.4.154:46160\",\"URLPath\":\"/customers\",\"level\":\"info\",\"msg\":\"HTTP request received\",\"time\":\"2020-03-10T20:18:18Z\"}\n",
    "stream": "stdout",
    "docker": {
      "container_id": "cd1634b0ce410f3c89fe63f508fe6208396be87adf1f27fa9d47a01d81ff7904"
    },
    "kubernetes": {
Run Code Online (Sandbox Code Playgroud)

我期待看到从log:值中提取的 JSON有点像这样(缩写):

{
  "_index": "logstash-2020.03.10",
  ...
  "_source": {
    "log": "...",   
    "Application":"customer",
    "HTTPMethod":"GET",
    "HostName":"",
    "RemoteAddr":"10.244.4.154:46160",
    "URLPath":"/customers",
    "level":"info",
    "msg":"HTTP request received",
    "time":"2020-03-10T20:18:18Z",
    "stream": …
Run Code Online (Sandbox Code Playgroud)

json elasticsearch fluentd kibana

3
推荐指数
1
解决办法
4395
查看次数

标签 统计

elasticsearch ×1

fluentd ×1

javascript ×1

json ×1

kibana ×1

mocha.js ×1

node.js ×1

redis ×1

sinon ×1