func NewRegistrar(registryFile string) (*Registrar, error) { r := &Registrar{ registryFile: registryFile, done: make(chan struct{}), state: input.NewStates(), Channel: make(chan []*FileEvent, 1), wg: sync.WaitGroup{}, } err := r.Init() return r, err }
func TestProspectorDefaultConfigs(t *testing.T) { prospector, err := NewProspector(common.NewConfig(), *input.NewStates(), nil) assert.NoError(t, err) // Default values expected assert.Equal(t, DefaultIgnoreOlder, prospector.config.IgnoreOlder) assert.Equal(t, DefaultScanFrequency, prospector.config.ScanFrequency) assert.Equal(t, config.DefaultHarvesterBufferSize, prospector.config.Harvester.BufferSize) assert.Equal(t, config.DefaultTailFiles, prospector.config.Harvester.TailFiles) assert.Equal(t, config.DefaultBackoff, prospector.config.Harvester.BackoffDuration) assert.Equal(t, config.DefaultBackoffFactor, prospector.config.Harvester.BackoffFactor) assert.Equal(t, config.DefaultMaxBackoff, prospector.config.Harvester.MaxBackoffDuration) assert.Equal(t, config.DefaultForceCloseFiles, prospector.config.Harvester.ForceCloseFiles) assert.Equal(t, config.DefaultMaxBytes, prospector.config.Harvester.MaxBytes) }
func TestProspectorInitInputTypeWrong(t *testing.T) { prospectorConfig := prospectorConfig{ Harvester: harvester.HarvesterConfig{ InputType: "wrong-type", }, } prospector := Prospector{ config: prospectorConfig, states: input.NewStates(), } err := prospector.Init() assert.Nil(t, err) assert.Equal(t, "log", prospector.config.Harvester.InputType) }
func TestProspectorInitInputTypeLog(t *testing.T) { prospectorConfig := prospectorConfig{ Paths: []string{"testpath1", "testpath2"}, Harvester: harvester.HarvesterConfig{ InputType: "log", }, } prospector := Prospector{ config: prospectorConfig, states: input.NewStates(), } err := prospector.Init() assert.Nil(t, err) assert.Equal(t, "log", prospector.config.Harvester.InputType) }
func TestProspectorFileExclude(t *testing.T) { prospectorConfig := prospectorConfig{ ExcludeFiles: []*regexp.Regexp{regexp.MustCompile(`\.gz$`)}, Harvester: harvester.HarvesterConfig{ BufferSize: 0, }, } prospector := Prospector{ config: prospectorConfig, states: input.NewStates(), } prospector.Init() prospectorer := prospector.prospectorer.(*ProspectorLog) assert.True(t, prospectorer.isFileExcluded("/tmp/log/logw.gz")) assert.False(t, prospectorer.isFileExcluded("/tmp/log/logw.log")) }