Beispiel #1
0
func newFakePluginServer(mockCtrl *gomock.Controller) *fakePluginServer {
	serverReader, clientWriter := io.Pipe()
	clientReader, serverWriter := io.Pipe()

	server := frame.NewServer(serverReader, serverWriter)
	client := frame.NewClient(clientWriter, clientReader)

	mockPlugin := plugintest.NewMockPlugin(mockCtrl)
	mockServiceGenerator := plugintest.NewMockServiceGenerator(mockCtrl)

	handler := multiplex.NewHandler()
	handler.Put("Plugin", api.NewPluginHandler(mockPlugin))
	handler.Put("ServiceGenerator", api.NewServiceGeneratorHandler(mockServiceGenerator))

	done := make(chan error)
	go func() {
		err := server.Serve(envelope.NewServer(protocol.Binary, handler))
		if err != nil {
			done <- err
		}
		close(done)
	}()

	return &fakePluginServer{
		errCh:            done,
		server:           server,
		ClientTransport:  client,
		Plugin:           mockPlugin,
		ServiceGenerator: mockServiceGenerator,
	}
}
Beispiel #2
0
// NewClient starts up the given external process and communicates with it over
// stdin and stdout using framed requests and responses.
//
// The Cmd MUST NOT have Stdout or Stdin set.
func NewClient(cmd *exec.Cmd) (*Client, error) {
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, fmt.Errorf("failed to create stdout pipe to %q: %v", cmd.Path, err)
	}

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return nil, fmt.Errorf("failed to create stdin pipe to %q: %v", cmd.Path, err)
	}

	if err := cmd.Start(); err != nil {
		return nil, fmt.Errorf("failed to start %q: %v", cmd.Path, err)
	}

	return &Client{
		stdout:  stdout,
		stdin:   stdin,
		running: atomic.NewBool(true),
		client:  frame.NewClient(stdin, stdout),
		cmd:     cmd,
	}, nil
}
Beispiel #3
0
func fakeEnvelopeClient() (envelope.Client, func()) {
	in, out, done := fakeStreams()
	return envelope.NewClient(_proto, frame.NewClient(in, out)), done
}