aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-plugin/testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-plugin/testing.go')
-rw-r--r--vendor/github.com/hashicorp/go-plugin/testing.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/vendor/github.com/hashicorp/go-plugin/testing.go b/vendor/github.com/hashicorp/go-plugin/testing.go
index df29593..2cf2c26 100644
--- a/vendor/github.com/hashicorp/go-plugin/testing.go
+++ b/vendor/github.com/hashicorp/go-plugin/testing.go
@@ -3,13 +3,28 @@ package plugin
3import ( 3import (
4 "bytes" 4 "bytes"
5 "context" 5 "context"
6 "io"
6 "net" 7 "net"
7 "net/rpc" 8 "net/rpc"
8 9
9 "github.com/mitchellh/go-testing-interface" 10 "github.com/mitchellh/go-testing-interface"
11 hclog "github.com/hashicorp/go-hclog"
12 "github.com/hashicorp/go-plugin/internal/plugin"
10 "google.golang.org/grpc" 13 "google.golang.org/grpc"
11) 14)
12 15
16// TestOptions allows specifying options that can affect the behavior of the
17// test functions
18type TestOptions struct {
19 //ServerStdout causes the given value to be used in place of a blank buffer
20 //for RPCServer's Stdout
21 ServerStdout io.ReadCloser
22
23 //ServerStderr causes the given value to be used in place of a blank buffer
24 //for RPCServer's Stderr
25 ServerStderr io.ReadCloser
26}
27
13// The testing file contains test helpers that you can use outside of 28// The testing file contains test helpers that you can use outside of
14// this package for making it easier to test plugins themselves. 29// this package for making it easier to test plugins themselves.
15 30
@@ -61,12 +76,20 @@ func TestRPCConn(t testing.T) (*rpc.Client, *rpc.Server) {
61 76
62// TestPluginRPCConn returns a plugin RPC client and server that are connected 77// TestPluginRPCConn returns a plugin RPC client and server that are connected
63// together and configured. 78// together and configured.
64func TestPluginRPCConn(t testing.T, ps map[string]Plugin) (*RPCClient, *RPCServer) { 79func TestPluginRPCConn(t testing.T, ps map[string]Plugin, opts *TestOptions) (*RPCClient, *RPCServer) {
65 // Create two net.Conns we can use to shuttle our control connection 80 // Create two net.Conns we can use to shuttle our control connection
66 clientConn, serverConn := TestConn(t) 81 clientConn, serverConn := TestConn(t)
67 82
68 // Start up the server 83 // Start up the server
69 server := &RPCServer{Plugins: ps, Stdout: new(bytes.Buffer), Stderr: new(bytes.Buffer)} 84 server := &RPCServer{Plugins: ps, Stdout: new(bytes.Buffer), Stderr: new(bytes.Buffer)}
85 if opts != nil {
86 if opts.ServerStdout != nil {
87 server.Stdout = opts.ServerStdout
88 }
89 if opts.ServerStderr != nil {
90 server.Stderr = opts.ServerStderr
91 }
92 }
70 go server.ServeConn(serverConn) 93 go server.ServeConn(serverConn)
71 94
72 // Connect the client to the server 95 // Connect the client to the server
@@ -119,9 +142,11 @@ func TestPluginGRPCConn(t testing.T, ps map[string]Plugin) (*GRPCClient, *GRPCSe
119 // Start up the server 142 // Start up the server
120 server := &GRPCServer{ 143 server := &GRPCServer{
121 Plugins: ps, 144 Plugins: ps,
145 DoneCh: make(chan struct{}),
122 Server: DefaultGRPCServer, 146 Server: DefaultGRPCServer,
123 Stdout: new(bytes.Buffer), 147 Stdout: new(bytes.Buffer),
124 Stderr: new(bytes.Buffer), 148 Stderr: new(bytes.Buffer),
149 logger: hclog.Default(),
125 } 150 }
126 if err := server.Init(); err != nil { 151 if err := server.Init(); err != nil {
127 t.Fatalf("err: %s", err) 152 t.Fatalf("err: %s", err)
@@ -144,10 +169,11 @@ func TestPluginGRPCConn(t testing.T, ps map[string]Plugin) (*GRPCClient, *GRPCSe
144 169
145 // Create the client 170 // Create the client
146 client := &GRPCClient{ 171 client := &GRPCClient{
147 Conn: conn, 172 Conn: conn,
148 Plugins: ps, 173 Plugins: ps,
149 broker: broker, 174 broker: broker,
150 doneCtx: context.Background(), 175 doneCtx: context.Background(),
176 controller: plugin.NewGRPCControllerClient(conn),
151 } 177 }
152 178
153 return client, server 179 return client, server