remote: simplify client
This commit is contained in:
parent
b83b4a923f
commit
d077a82db2
|
@ -17,8 +17,8 @@ import (
|
||||||
// RemoteStatePayload is used to return the remote state
|
// RemoteStatePayload is used to return the remote state
|
||||||
// along with associated meta data when we do a remote fetch.
|
// along with associated meta data when we do a remote fetch.
|
||||||
type RemoteStatePayload struct {
|
type RemoteStatePayload struct {
|
||||||
MD5 []byte
|
MD5 []byte
|
||||||
R io.Reader
|
State []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetState is used to read the remote state
|
// GetState is used to read the remote state
|
||||||
|
@ -72,7 +72,7 @@ func GetState(conf *terraform.RemoteState) (*RemoteStatePayload, error) {
|
||||||
|
|
||||||
// Create the payload
|
// Create the payload
|
||||||
payload := &RemoteStatePayload{
|
payload := &RemoteStatePayload{
|
||||||
R: buf,
|
State: buf.Bytes(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is Consul
|
// Check if this is Consul
|
||||||
|
@ -88,11 +88,7 @@ func GetState(conf *terraform.RemoteState) (*RemoteStatePayload, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the reader to pull the value from Consul
|
// Setup the reader to pull the value from Consul
|
||||||
payload.R = bytes.NewReader(values[0].Value)
|
payload.State = values[0].Value
|
||||||
|
|
||||||
// Generate the MD5
|
|
||||||
hash := md5.Sum(values[0].Value)
|
|
||||||
payload.MD5 = hash[:md5.Size]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,9 +100,9 @@ func GetState(conf *terraform.RemoteState) (*RemoteStatePayload, error) {
|
||||||
}
|
}
|
||||||
payload.MD5 = md5
|
payload.MD5 = md5
|
||||||
|
|
||||||
} else if _, ok := payload.R.(*bytes.Buffer); ok {
|
} else {
|
||||||
// Generate the MD5
|
// Generate the MD5
|
||||||
hash := md5.Sum(buf.Bytes())
|
hash := md5.Sum(payload.State)
|
||||||
payload.MD5 = hash[:md5.Size]
|
payload.MD5 = hash[:md5.Size]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package remote
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -63,9 +62,7 @@ REQ:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the body
|
// Check the body
|
||||||
var buf bytes.Buffer
|
if string(payload.State) != "testing" {
|
||||||
io.Copy(&buf, payload.R)
|
|
||||||
if string(buf.Bytes()) != "testing" {
|
|
||||||
t.Fatalf("Bad body")
|
t.Fatalf("Bad body")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,9 +148,7 @@ func TestGetState(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tc.Body != nil {
|
if tc.Body != nil {
|
||||||
buf := bytes.NewBuffer(nil)
|
if !bytes.Equal(payload.State, tc.Body) {
|
||||||
io.Copy(buf, payload.R)
|
|
||||||
if !bytes.Equal(buf.Bytes(), tc.Body) {
|
|
||||||
t.Fatalf("bad: %#v", payload)
|
t.Fatalf("bad: %#v", payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue