2017-02-18 02:26:38 +01:00
|
|
|
package inmem
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
|
2020-08-11 17:43:01 +02:00
|
|
|
"github.com/hashicorp/terraform/states/remote"
|
|
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
2017-02-18 02:26:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// RemoteClient is a remote client that stores data in memory for testing.
|
|
|
|
type RemoteClient struct {
|
|
|
|
Data []byte
|
|
|
|
MD5 []byte
|
2017-08-01 18:11:04 +02:00
|
|
|
Name string
|
2017-02-18 02:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *RemoteClient) Get() (*remote.Payload, error) {
|
|
|
|
if c.Data == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &remote.Payload{
|
|
|
|
Data: c.Data,
|
|
|
|
MD5: c.MD5,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *RemoteClient) Put(data []byte) error {
|
|
|
|
md5 := md5.Sum(data)
|
|
|
|
|
|
|
|
c.Data = data
|
|
|
|
c.MD5 = md5[:]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *RemoteClient) Delete() error {
|
|
|
|
c.Data = nil
|
|
|
|
c.MD5 = nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-11 17:43:01 +02:00
|
|
|
func (c *RemoteClient) Lock(info *statemgr.LockInfo) (string, error) {
|
2017-08-01 18:11:04 +02:00
|
|
|
return locks.lock(c.Name, info)
|
2017-02-18 02:26:38 +01:00
|
|
|
}
|
|
|
|
func (c *RemoteClient) Unlock(id string) error {
|
2017-08-01 18:11:04 +02:00
|
|
|
return locks.unlock(c.Name, id)
|
2017-02-18 02:26:38 +01:00
|
|
|
}
|