github.com/tarrant/terraform@v0.3.8-0.20150402012457-f68c9eee638e/state/remote/remote_test.go (about) 1 package remote 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/hashicorp/terraform/state" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 // testClient is a generic function to test any client. 12 func testClient(t *testing.T, c Client) { 13 var buf bytes.Buffer 14 s := state.TestStateInitial() 15 if err := terraform.WriteState(s, &buf); err != nil { 16 t.Fatalf("err: %s", err) 17 } 18 data := buf.Bytes() 19 20 if err := c.Put(data); err != nil { 21 t.Fatalf("put: %s", err) 22 } 23 24 p, err := c.Get() 25 if err != nil { 26 t.Fatalf("get: %s", err) 27 } 28 if !bytes.Equal(p.Data, data) { 29 t.Fatalf("bad: %#v", p) 30 } 31 32 if err := c.Delete(); err != nil { 33 t.Fatalf("delete: %s", err) 34 } 35 36 p, err = c.Get() 37 if err != nil { 38 t.Fatalf("get: %s", err) 39 } 40 if p != nil { 41 t.Fatalf("bad: %#v", p) 42 } 43 }