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


Golang MetricType.Config_方法代码示例

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


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

示例1: TestGetMetricConfigItem

func TestGetMetricConfigItem(t *testing.T) {

	Convey("Get a value of items from Metrics Config with no error", t, func() {
		// create config
		config := cdata.NewNode()
		config.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
		config.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
		config.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
		config.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

		// create metric and set config
		metric := plugin.MetricType{}
		metric.Config_ = config

		Convey("string type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_string")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_str)
		})

		Convey("bool type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_bool")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_bool)
		})

		Convey("int type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_int")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_int)
		})

		Convey("float type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_float")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_float)
		})
	})

	Convey("Try to get a value of items not defined in Metrics Config", t, func() {
		config := cdata.NewNode()
		config.AddItem("foo", ctypes.ConfigValueStr{Value: "foo_val"})
		metric := plugin.MetricType{}
		metric.Config_ = config

		result, err := GetMetricConfigItem(metric, "foo_not_exist")
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})

	Convey("No item defined in Metrics Config", t, func() {
		metric := plugin.MetricType{}
		metric.Config_ = cdata.NewNode()

		result, err := GetMetricConfigItem(metric, "foo")
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:59,代码来源:config_test.go

示例2: TestGetMetricConfigItems

func TestGetMetricConfigItems(t *testing.T) {

	Convey("Get values of items from Metrics Config with no error", t, func() {

		// create config
		config := cdata.NewNode()
		config.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
		config.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
		config.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
		config.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

		// create metric and set config
		metric := plugin.MetricType{}
		metric.Config_ = config

		names := []string{"dummy_string", "dummy_bool", "dummy_int", "dummy_float"}

		result, err := GetMetricConfigItems(metric, names)
		So(err, ShouldBeNil)
		for _, name := range names {
			So(result[name], ShouldNotBeEmpty)
		}
	})

	Convey("Try to get values of items not defined in Metrics config", t, func() {
		config := cdata.NewNode()
		config.AddItem("foo", ctypes.ConfigValueStr{Value: "foo_val"})
		metric := plugin.MetricType{}
		metric.Config_ = config

		names := []string{"foo1", "foo2"}
		result, err := GetMetricConfigItems(metric, names)
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})

	Convey("No item defined in Metrics Config", t, func() {
		metric := plugin.MetricType{}
		metric.Config_ = cdata.NewNode()
		names := []string{"foo", "bar"}
		result, err := GetMetricConfigItems(metric, names)
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:45,代码来源:config_test.go

示例3: TestConfigItems

func TestConfigItems(t *testing.T) {
	names := []string{"dummy_string", "dummy_bool", "dummy_int", "dummy_float"}

	Convey("Get values of configuration items with no error", t, func() {

		Convey("Source: global config", func() {
			//create global config and add item (different types)
			cfg := plugin.NewPluginConfigType()
			cfg.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
			cfg.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
			cfg.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
			cfg.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

			result, err := GetConfigItems(cfg, names...)
			So(err, ShouldBeNil)
			for _, name := range names {
				So(result[name], ShouldNotBeEmpty)
			}
		})

		Convey("Source: metrics config", func() {
			// create metrics config
			config := cdata.NewNode()
			config.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
			config.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
			config.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
			config.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

			// create metric and set config
			metric := plugin.MetricType{}
			metric.Config_ = config

			result, err := GetConfigItems(metric, names...)
			So(err, ShouldBeNil)
			for _, name := range names {
				So(result[name], ShouldNotBeEmpty)
			}
		})
	})

	Convey("Try to get values of items from invalid config (unsupported type)", t, func() {
		invalid_cfg := []string{"invalid", "config", "source"}
		result, err := GetConfigItems(invalid_cfg, names...)
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})

}
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:48,代码来源:config_test.go

示例4: TestConfigItem

func TestConfigItem(t *testing.T) {

	Convey("Get a value of item with no error", t, func() {

		Convey("Source: global config", func() {
			//create global config and add item (different types)
			cfg := plugin.NewPluginConfigType()
			cfg.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
			cfg.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
			cfg.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
			cfg.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

			Convey("string type of item", func() {
				result, err := GetConfigItem(cfg, "dummy_string")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_str)
			})

			Convey("bool type of item", func() {
				result, err := GetConfigItem(cfg, "dummy_bool")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_bool)
			})

			Convey("int type of item", func() {
				result, err := GetConfigItem(cfg, "dummy_int")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_int)
			})

			Convey("float type of itemr", func() {
				result, err := GetConfigItem(cfg, "dummy_float")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_float)
			})
		})

		Convey("Source: metrics config", func() {
			// create metric's config
			config := cdata.NewNode()
			config.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
			config.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
			config.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
			config.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

			// create metric and set config
			metric := plugin.MetricType{}
			metric.Config_ = config

			Convey("string type of item", func() {
				result, err := GetConfigItem(metric, "dummy_string")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_str)
			})

			Convey("bool type of item", func() {
				result, err := GetConfigItem(metric, "dummy_bool")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_bool)
			})

			Convey("int type of item", func() {
				result, err := GetConfigItem(metric, "dummy_int")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_int)
			})

			Convey("float type of item", func() {
				result, err := GetConfigItem(metric, "dummy_float")
				So(err, ShouldBeNil)
				So(result, ShouldEqual, dummy_float)
			})
		})
	})

	Convey("Try to get a value of item not defined in config", t, func() {

		Convey("Source: metrics config", func() {
			config := cdata.NewNode()
			config.AddItem("foo", ctypes.ConfigValueStr{Value: "foo_val"})
			metric := plugin.MetricType{}
			metric.Config_ = config
			result, err := GetMetricConfigItem(metric, "foo_not_exist")
			So(err, ShouldNotBeNil)
			So(result, ShouldBeNil)
		})

		Convey("Source: global config", func() {
			cfg := plugin.NewPluginConfigType()
			cfg.AddItem("foo", ctypes.ConfigValueStr{Value: "foo"})
			names := []string{"foo1", "foo2"}
			result, err := GetGlobalConfigItems(cfg, names)
			So(err, ShouldNotBeNil)
			So(result, ShouldBeNil)
		})
	})

	Convey("No item defined in config", t, func() {

		Convey("Source: metrics config", func() {
//.........这里部分代码省略.........
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:101,代码来源:config_test.go


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