func setupCfg() plugin.ConfigType {
	master := os.Getenv("SNAP_MESOS_MASTER")
	if master == "" {
		master = "127.0.0.1:5050"
	}
	agent := os.Getenv("SNAP_MESOS_AGENT")
	if agent == "" {
		agent = "127.0.0.1:5051"
	}
	node := cdata.NewNode()
	node.AddItem("master", ctypes.ConfigValueStr{Value: master})
	node.AddItem("agent", ctypes.ConfigValueStr{Value: agent})
	return plugin.ConfigType{ConfigDataNode: node}
}
setupCfg builds a new ConfigDataNode that specifies the Mesos master and agent host / port
to use in the integration test(s).
package mesos
import (
	"bytes"
	"fmt"
	"net/http"
	"net/url"
	"os"
	"os/exec"
	"testing"
	"time"
	"github.com/intelsdi-x/snap-plugin-collector-mesos/mesos/agent"
	"github.com/intelsdi-x/snap-plugin-collector-mesos/mesos/master"
	"github.com/intelsdi-x/snap-plugin-utilities/config"
	"github.com/intelsdi-x/snap/control/plugin"
	"github.com/intelsdi-x/snap/core"
	"github.com/intelsdi-x/snap/core/cdata"
	"github.com/intelsdi-x/snap/core/ctypes"
	. "github.com/smartystreets/goconvey/convey"
)
func TestMesos_GetMetricTypes(t *testing.T) {
	cfg := setupCfg()
	mc := NewMesosCollector()
	mts, err := mc.GetMetricTypes(cfg)
	if err != nil {
		panic(err)
	}
	var namespaces []string
	for i := 0; i < len(mts); i++ {
		namespaces = append(namespaces, mts[i].Namespace().String())
	}
	Convey("Should return metric types for the master and agent", t, func() {
		So(err, ShouldBeNil)
		So(len(mts), ShouldBeGreaterThan, 1)
		So(namespaces, ShouldContain, "/intel/mesos/master/system/cpus_total")
		So(namespaces, ShouldContain, "/intel/mesos/master/*/resources/cpus")
		So(namespaces, ShouldContain, "/intel/mesos/agent/system/cpus_total")
		So(namespaces, ShouldContain, "/intel/mesos/agent/*/*/cpus_limit")
	})
	Convey("Should only return metrics for available features on a Mesos agent", t, func() {
		So(namespaces, ShouldNotContain, "/intel/mesos/agent/*/*/net_rx_bytes")
	})
}
func TestMesos_CollectMetrics(t *testing.T) {
	cfg := setupCfg()
	cfgItems, err := config.GetConfigItems(cfg, []string{"master", "agent"}...)
	if err != nil {
		panic(err)
	}
	teardown(cfgItems["master"].(string))
	launchTasks(cfgItems["master"].(string), cfgItems["agent"].(string))
	Convey("Collect metrics from a Mesos master and agent", t, func() {
		mc := NewMesosCollector()
		_, err := mc.GetMetricTypes(cfg)
		if err != nil {
			panic(err)
		}
		Convey("Should collect requested metrics from the master", func() {
			mts := []plugin.MetricType{
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "master", "master", "tasks_running"),
					Config_:    cfg.ConfigDataNode,
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "master", "registrar", "state_store_ms", "p99"),
					Config_:    cfg.ConfigDataNode,
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "master", "system", "load_5min"),
					Config_:    cfg.ConfigDataNode,
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "master").
						AddDynamicElement("framework_id", "Framework ID").
						AddStaticElements("used_resources", "cpus"),
					Config_: cfg.ConfigDataNode,
				},
			}
			metrics, err := mc.CollectMetrics(mts)
			So(err, ShouldBeNil)
			So(metrics, ShouldNotBeNil)
			So(len(metrics), ShouldEqual, 5)
			So(metrics[0].Namespace().String(), ShouldEqual, "/intel/mesos/master/master/tasks_running")
			So(metrics[1].Namespace().String(), ShouldEqual, "/intel/mesos/master/registrar/state_store_ms/p99")
			So(metrics[2].Namespace().String(), ShouldEqual, "/intel/mesos/master/system/load_5min")
			So(metrics[3].Namespace().Strings()[4], ShouldEqual, "used_resources")
		})
		Convey("Should collect requested metrics from the agent", func() {
			mts := []plugin.MetricType{
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "agent", "slave", "tasks_running"),
					Config_:    cfg.ConfigDataNode,
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "agent", "system", "load_5min"),
					Config_:    cfg.ConfigDataNode,
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "agent").
						AddDynamicElement("framework_id", "Framework ID").
						AddDynamicElement("executor_id", "Executor ID").
						AddStaticElement("cpus_system_time_secs"),
					Config_: cfg.ConfigDataNode,
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "agent").
						AddDynamicElement("framework_id", "Framework ID").
						AddDynamicElement("executor_id", "Executor ID").
						AddStaticElement("disk_used_bytes"),
					Config_: cfg.ConfigDataNode,
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "agent").
						AddDynamicElement("framework_id", "Framework ID").
						AddDynamicElement("executor_id", "Executor ID").
						AddStaticElement("mem_total_bytes"),
					Config_: cfg.ConfigDataNode,
				},
			}
			metrics, err := mc.CollectMetrics(mts)
			So(err, ShouldBeNil)
			So(metrics, ShouldNotBeNil)
			So(len(metrics), ShouldEqual, 8)
			So(metrics[0].Namespace().String(), ShouldEqual, "/intel/mesos/agent/slave/tasks_running")
			So(metrics[1].Namespace().String(), ShouldEqual, "/intel/mesos/agent/system/load_5min")
			So(metrics[2].Namespace().Strings()[5], ShouldEqual, "cpus_system_time_secs")
			So(metrics[4].Namespace().Strings()[5], ShouldEqual, "disk_used_bytes")
			So(metrics[6].Namespace().Strings()[5], ShouldEqual, "mem_total_bytes")
		})
		Convey("Should return an error if an invalid metric was requested", func() {
			mts := []plugin.MetricType{
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "mesos", "master", "foo", "bar", "baz"),
					Config_:    cfg.ConfigDataNode,
				},
			}
			metrics, err := mc.CollectMetrics(mts)
			So(metrics, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
	})
	teardown(cfgItems["master"].(string))
}