terraform/state/remote/remote_test.go

44 lines
769 B
Go
Raw Normal View History

2015-02-22 00:13:28 +01:00
package remote
import (
"bytes"
"testing"
2015-02-24 02:56:29 +01:00
"github.com/hashicorp/terraform/state"
"github.com/hashicorp/terraform/terraform"
2015-02-22 00:13:28 +01:00
)
// testClient is a generic function to test any client.
func testClient(t *testing.T, c Client) {
2015-02-24 02:56:29 +01:00
var buf bytes.Buffer
s := state.TestStateInitial()
if err := terraform.WriteState(s, &buf); err != nil {
t.Fatalf("err: %s", err)
}
data := buf.Bytes()
2015-02-22 00:13:28 +01:00
if err := c.Put(data); err != nil {
t.Fatalf("put: %s", err)
}
p, err := c.Get()
if err != nil {
t.Fatalf("get: %s", err)
}
if !bytes.Equal(p.Data, data) {
t.Fatalf("bad: %#v", p)
}
if err := c.Delete(); err != nil {
t.Fatalf("delete: %s", err)
}
p, err = c.Get()
if err != nil {
t.Fatalf("get: %s", err)
}
if p != nil {
t.Fatalf("bad: %#v", p)
}
}