示例#1
0
func Test_main(t *testing.T) {
	var (
		assert   = assert.New(t)
		err      error
		conftest config.Config
	)

	log.SetLevel(log.DebugLevel)

	conftest, err = config.LoadConfig("config_test.json")
	assert.NoError(err)

	inputs := conftest.Input()
	assert.Len(inputs, 1)
	if len(inputs) > 0 {
		input := inputs[0].(*InputConfig)
		assert.IsType(&InputConfig{}, input)
		assert.Equal("docker", input.GetType())

		eventChan := make(chan config.LogEvent, 10)
		go func() {
			for {
				event := <-eventChan
				t.Log(event)
			}
		}()
		err = input.Event(eventChan)
		assert.NoError(err)

		waitsec := 10
		log.Debugf("Wait for %d seconds", waitsec)
		time.Sleep(time.Duration(waitsec) * time.Second)
	}
}
示例#2
0
func Test_main(t *testing.T) {
	var (
		assert   = assert.New(t)
		err      error
		conftest config.Config
	)

	log.SetLevel(log.DebugLevel)

	conftest, err = config.LoadConfig("config_test.json")
	assert.NoError(err)

	outputs := conftest.Output()
	assert.Len(outputs, 1)
	if len(outputs) > 0 {
		output := outputs[0].(*OutputConfig)
		assert.IsType(&OutputConfig{}, output)
		assert.Equal("redis", output.GetType())

		output.Event(config.LogEvent{
			Timestamp: time.Now(),
			Message:   "outputredis test message",
		})

		// test random time event only
		//test_random_time_event(t, output)
	}
}
示例#3
0
func Test_main(t *testing.T) {
	var (
		assert   = assert.New(t)
		err      error
		conftest config.Config
	)

	log.SetLevel(log.DebugLevel)

	conftest, err = config.LoadConfig("config_test.json")
	assert.NoError(err)

	outputs := conftest.Output()
	assert.Len(outputs, 1)
	if len(outputs) > 0 {
		output := outputs[0].(*OutputConfig)
		assert.IsType(&OutputConfig{}, output)
		assert.Equal("report", output.GetType())
		assert.Equal(1, output.Interval)

		event := config.LogEvent{
			Timestamp: time.Now(),
			Message:   "outputreport test message",
		}

		output.Event(event)
		output.Event(event)
		time.Sleep(2 * time.Second)

		output.Event(event)
		time.Sleep(2 * time.Second)

		output.Event(event)
		output.Event(event)
		output.Event(event)
		output.Event(event)
		time.Sleep(2 * time.Second)
	}
}