Exemplo n.º 1
0
func TestNoStagesWithLogger(t *testing.T) {
	logger := log.New(os.Stdout, "", 0)
	cfg := pipeline.DefaultConfig()
	cfg.Logger, cfg.Verbose = logger, true
	p := pipeline.NewWithConfig(cfg)

	generator := &EmptyGenerator{}
	p.SetGenerator(generator)

	err := p.Run()
	if err == nil {
		t.Errorf(`error should be nil`)
	}

	if err != pipeline.ErrNoStages {
		t.Errorf(`the pipeline should have no stages`)
	}

	if generator.NextCount != 0 {
		t.Errorf("expected generator.NextCount == 0")
	}

	if generator.AbortCount != 0 {
		t.Errorf("expected generator.AbortCount == 0")
	}
}
Exemplo n.º 2
0
func TestOneStageWithLoggerNoBuffer(t *testing.T) {
	//boost our code coverage of logging output

	logger := log.New(os.Stdout, "", 0)
	cfg := pipeline.DefaultConfig()
	cfg.Logger, cfg.Verbose, cfg.Buffered = logger, true, false
	p := pipeline.NewWithConfig(cfg)
	generator := &CountsToTenGenerator{}
	p.SetGenerator(generator)

	stage := &CountingStage{}
	p.AddStage(stage)

	err := p.Run()
	if err != nil {
		t.Errorf(`error should be nil`)
	}
	if generator.NextCount != 11 {
		t.Errorf("expected generator.NextCount == 11")
	}

	if stage.ProcessCount != 10 {
		t.Errorf("expected stage.ProcessCount == 10")
	}
}
Exemplo n.º 3
0
func TestNoGeneratorWithLogger(t *testing.T) {
	logger := log.New(os.Stdout, "", 0)
	cfg := pipeline.DefaultConfig()
	cfg.Logger, cfg.Verbose = logger, true
	p := pipeline.NewWithConfig(cfg)

	err := p.Run()
	if err != pipeline.ErrNilGenerator {
		t.Errorf(`the pipeline generator should be nil`)
	}

	err = p.Abort()
	if err != pipeline.ErrNilGenerator {
		t.Errorf(`the pipeline generator should be nil`)
	}
}
Exemplo n.º 4
0
func main() {

	logger := log.New(os.Stdout, "", 0)
	cfg := pipeline.DefaultConfig()
	cfg.Logger = logger
	// for debugging/understanding -- eliminate concurrency and buffering
	cfg.NoConcurrency = !flagConcurrent
	cfg.Buffered = flagBuffer
	cfg.Depth = 0
	cfg.Verbose = flagVerbose
	p := pipeline.NewWithConfig(cfg)

	generator.Generator.Initialize(os.Getenv("GOPATH"), `.*\.go$`, logger)
	p.SetGenerator(generator.Generator)

	hash.Stage.SetLogger(logger)
	p.AddStage(hash.Stage)

	delay.Stage.SetLogger(logger)
	p.AddStage(delay.Stage)

	echo.Stage.SetLogger(logger)
	p.AddStage(echo.Stage)

	terminus.Stage.SetLogger(logger)
	p.AddStage(terminus.Stage)

	//example; stop the generator after 5 seconds
	time.AfterFunc(time.Second*5, func() {
		p.Abort()
	})

	// or stop the generator on Ctrl+C
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			sig.Signal()
			p.Abort()
		}
	}()

	// blocks until complete
	p.Run()
}