plugin: add ResourceProvisioner.Stop API
This commit is contained in:
parent
f8c7b639c9
commit
2e894c4ef7
|
@ -77,6 +77,19 @@ func (p *ResourceProvisioner) Apply(
|
|||
return err
|
||||
}
|
||||
|
||||
func (p *ResourceProvisioner) Stop() error {
|
||||
var resp ResourceProvisionerStopResponse
|
||||
err := p.Client.Call("Plugin.Stop", new(interface{}), &resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.Error != nil {
|
||||
err = resp.Error
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *ResourceProvisioner) Close() error {
|
||||
return p.Client.Close()
|
||||
}
|
||||
|
@ -100,6 +113,10 @@ type ResourceProvisionerApplyResponse struct {
|
|||
Error *plugin.BasicError
|
||||
}
|
||||
|
||||
type ResourceProvisionerStopResponse struct {
|
||||
Error *plugin.BasicError
|
||||
}
|
||||
|
||||
// ResourceProvisionerServer is a net/rpc compatible structure for serving
|
||||
// a ResourceProvisioner. This should not be used directly.
|
||||
type ResourceProvisionerServer struct {
|
||||
|
@ -143,3 +160,14 @@ func (s *ResourceProvisionerServer) Validate(
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ResourceProvisionerServer) Stop(
|
||||
_ interface{},
|
||||
reply *ResourceProvisionerStopResponse) error {
|
||||
err := s.Provisioner.Stop()
|
||||
*reply = ResourceProvisionerStopResponse{
|
||||
Error: plugin.NewBasicError(err),
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -14,6 +14,61 @@ func TestResourceProvisioner_impl(t *testing.T) {
|
|||
var _ terraform.ResourceProvisioner = new(ResourceProvisioner)
|
||||
}
|
||||
|
||||
func TestResourceProvisioner_stop(t *testing.T) {
|
||||
// Create a mock provider
|
||||
p := new(terraform.MockResourceProvisioner)
|
||||
client, _ := plugin.TestPluginRPCConn(t, pluginMap(&ServeOpts{
|
||||
ProvisionerFunc: testProvisionerFixed(p),
|
||||
}))
|
||||
defer client.Close()
|
||||
|
||||
// Request the provider
|
||||
raw, err := client.Dispense(ProvisionerPluginName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
provider := raw.(terraform.ResourceProvisioner)
|
||||
|
||||
// Stop
|
||||
e := provider.Stop()
|
||||
if !p.StopCalled {
|
||||
t.Fatal("stop should be called")
|
||||
}
|
||||
if e != nil {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceProvisioner_stopErrors(t *testing.T) {
|
||||
p := new(terraform.MockResourceProvisioner)
|
||||
p.StopReturnError = errors.New("foo")
|
||||
|
||||
// Create a mock provider
|
||||
client, _ := plugin.TestPluginRPCConn(t, pluginMap(&ServeOpts{
|
||||
ProvisionerFunc: testProvisionerFixed(p),
|
||||
}))
|
||||
defer client.Close()
|
||||
|
||||
// Request the provider
|
||||
raw, err := client.Dispense(ProvisionerPluginName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
provider := raw.(terraform.ResourceProvisioner)
|
||||
|
||||
// Stop
|
||||
e := provider.Stop()
|
||||
if !p.StopCalled {
|
||||
t.Fatal("stop should be called")
|
||||
}
|
||||
if e == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
if e.Error() != "foo" {
|
||||
t.Fatalf("bad: %s", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceProvisioner_apply(t *testing.T) {
|
||||
// Create a mock provider
|
||||
p := new(terraform.MockResourceProvisioner)
|
||||
|
|
Loading…
Reference in New Issue