当前位置: 首页>>代码示例>>Golang>>正文


Golang Accumulator.ValidateTaggedFieldsValue方法代码示例

本文整理汇总了Golang中github.com/influxdb/telegraf/testutil.Accumulator.ValidateTaggedFieldsValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Accumulator.ValidateTaggedFieldsValue方法的具体用法?Golang Accumulator.ValidateTaggedFieldsValue怎么用?Golang Accumulator.ValidateTaggedFieldsValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/influxdb/telegraf/testutil.Accumulator的用法示例。


在下文中一共展示了Accumulator.ValidateTaggedFieldsValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestHttpJsonSingleValueTags

// Test that the proper values are ignored or collected
func TestHttpJsonSingleValueTags(t *testing.T) {

	jolokia := genJolokiaClientStub(validSingleValueJSON, 200, Servers, []Metric{UsedHeapMetric})

	var acc testutil.Accumulator
	err := jolokia.Gather(&acc)

	assert.Nil(t, err)
	assert.Equal(t, 1, len(acc.Points))
	assert.NoError(t, acc.ValidateTaggedFieldsValue("heap_memory_usage", map[string]interface{}{"value": 209274376.0}, map[string]string{"host": "127.0.0.1", "port": "8080", "server": "as1"}))
}
开发者ID:timjwright,项目名称:telegraf,代码行数:12,代码来源:jolokia_test.go

示例2: TestBasic

func TestBasic(t *testing.T) {
	js := `
{
  "_1": {
    "name": "foo",
    "tags": {
      "id": "ex1"
    },
    "values": {
      "i": -1,
      "f": 0.5,
      "b": true,
      "s": "string"
    }
  },
  "ignored": {
    "willBeRecorded": false
  },
  "ignoredAndNested": {
    "hash": {
      "is": "nested"
    }
  },
  "array": [
   "makes parsing more difficult than necessary"
  ],
  "string": "makes parsing more difficult than necessary",
  "_2": {
    "name": "bar",
    "tags": {
      "id": "ex2"
    },
    "values": {
      "x": "x"
    }
  },
  "pointWithoutFields_willNotBeIncluded": {
    "name": "asdf",
    "tags": {
      "id": "ex3"
    },
    "values": {}
  }
}
`
	fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.URL.Path == "/endpoint" {
			_, _ = w.Write([]byte(js))
		} else {
			w.WriteHeader(http.StatusNotFound)
		}
	}))
	defer fakeServer.Close()

	plugin := &influxdb.InfluxDB{
		URLs: []string{fakeServer.URL + "/endpoint"},
	}

	var acc testutil.Accumulator
	require.NoError(t, plugin.Gather(&acc))

	require.Len(t, acc.Points, 2)
	require.NoError(t, acc.ValidateTaggedFieldsValue(
		"foo",
		map[string]interface{}{
			// JSON will truncate floats to integer representations.
			// Since there's no distinction in JSON, we can't assume it's an int.
			"i": -1.0,
			"f": 0.5,
			"b": true,
			"s": "string",
		},
		map[string]string{
			"id":  "ex1",
			"url": fakeServer.URL + "/endpoint",
		},
	))
	require.NoError(t, acc.ValidateTaggedFieldsValue(
		"bar",
		map[string]interface{}{
			"x": "x",
		},
		map[string]string{
			"id":  "ex2",
			"url": fakeServer.URL + "/endpoint",
		},
	))
}
开发者ID:timjwright,项目名称:telegraf,代码行数:88,代码来源:influxdb_test.go


注:本文中的github.com/influxdb/telegraf/testutil.Accumulator.ValidateTaggedFieldsValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。