Exemplo n.º 1
0
func TestConnect(t *testing.T) {

	if testing.Short() {
		t.Skip("Skipping in short mode, because it requires Redis")
	}

	// Setup
	r := &MetricSeter{}

	config := helper.ModuleConfig{
		Hosts: []string{redis.GetRedisEnvHost() + ":" + redis.GetRedisEnvPort()},
	}
	module := &helper.Module{
		Config: config,
	}
	ms := helper.NewMetricSet("info", r, module)

	data, err := r.Fetch(ms)
	assert.NoError(t, err)

	// Check fields
	assert.Equal(t, 8, len(data[0]))

	server := data[0]["server"].(common.MapStr)

	assert.Equal(t, "3.0.7", server["redis_version"])
	assert.Equal(t, "standalone", server["redis_mode"])
}
Exemplo n.º 2
0
func TestConnect(t *testing.T) {

	if testing.Short() {
		t.Skip("Skipping in short mode, because it requires Redis")
	}

	// Setup
	redis.Module.BaseConfig.Hosts = []string{redis.GetRedisEnvHost() + ":" + redis.GetRedisEnvPort()}
	r := MetricSeter{}
	err := r.Setup()
	assert.NoError(t, err)

	data, err := r.Fetch()
	assert.NoError(t, err)

	// Check fields
	assert.Equal(t, 4, len(data[0]))
	assert.Equal(t, "3.0.6", data[0]["version"])
	assert.Equal(t, "standalone", data[0]["mode"])
}
Exemplo n.º 3
0
func TestData(t *testing.T) {
	f := mbtest.NewEventFetcher(t, getConfig(""))

	err := mbtest.WriteEvent(f, t)
	if err != nil {
		t.Fatal("write", err)
	}
}

// +build integration
const (
	password = "******"
)

var redisHost = redis.GetRedisEnvHost() + ":" + redis.GetRedisEnvPort()

func TestPasswords(t *testing.T) {
	// Add password and ensure it gets reset
	defer resetPassword(redisHost, password, "")
	err := addPassword(redisHost, password)
	if err != nil {
		t.Fatal("adding password", err)
	}

	// Test Fetch metrics with missing password
	f := mbtest.NewEventFetcher(t, getConfig(""))
	_, err = f.Fetch()
	if assert.Error(t, err, "missing password") {
		assert.Contains(t, err, "NOAUTH Authentication required.")
	}
Exemplo n.º 4
0
	"github.com/stretchr/testify/assert"

	"github.com/elastic/beats/libbeat/common"
	"github.com/elastic/beats/metricbeat/helper"
	"github.com/elastic/beats/metricbeat/module/redis"
)

// Test Redis specific struct
type RedisModuleConfig struct {
	Hosts    []string `config:"hosts"`
	Module   string   `config:"module"`
	Password string   `config:"password"`
}

var DEFAULT_PASS string = "foobared"
var LOCAL_REDIS string = redis.GetRedisEnvHost() + ":" + redis.GetRedisEnvPort()

func TestConnect(t *testing.T) {

	ms, msErr := getRedisMetricSet("")
	assert.NoError(t, msErr)

	// Setup metricset and metricseter
	err := ms.Setup()
	assert.NoError(t, err)
	err = ms.MetricSeter.Setup(ms)
	assert.NoError(t, err)

	// Check that host is correctly set
	assert.Equal(t, LOCAL_REDIS, ms.Config.Hosts[0])