Beispiel #1
0
func TestWorker_Shutdown_Cancel(t *testing.T) {
	l := builder.NewLogger(ioutil.Discard)
	b := new(mockCancelBuilder)
	f := func(options builder.BuildOptions) (builder.Logger, error) {
		return l, nil
	}
	q := make(chan BuildRequest, 1)
	w := &Worker{
		Builder:       b,
		LogFactory:    f,
		buildRequests: q,
		shutdown:      make(chan struct{}),
		done:          make(chan error),
	}

	done := make(chan struct{})
	go func() {
		w.Start()
		close(done)
	}()

	b.On("Cancel").Return(nil)
	err := w.Shutdown()

	<-done

	assert.NoError(t, err)
}
Beispiel #2
0
func TestWorker(t *testing.T) {
	l := builder.NewLogger(ioutil.Discard)
	b := new(mockBuilder)
	f := func(options builder.BuildOptions) (builder.Logger, error) {
		return l, nil
	}
	q := make(chan BuildRequest, 1)
	w := &Worker{
		Builder:       b,
		LogFactory:    f,
		buildRequests: q,
	}

	done := make(chan struct{})
	go func() {
		w.Start()
		close(done)
	}()

	b.On("Build", l, builder.BuildOptions{}).Return("", nil)

	q <- BuildRequest{
		Ctx:          context.Background(),
		BuildOptions: builder.BuildOptions{},
	}
	close(q)

	<-done
}