Change remote/http store to update, more consistent with doc

This commit is contained in:
Ross McFarland 2017-08-20 05:59:04 -07:00
parent 510563b67f
commit d889ac38b0
2 changed files with 21 additions and 21 deletions

View File

@ -22,16 +22,16 @@ func httpFactory(conf map[string]string) (Client, error) {
return nil, fmt.Errorf("missing 'address' configuration") return nil, fmt.Errorf("missing 'address' configuration")
} }
storeURL, err := url.Parse(address) updateURL, err := url.Parse(address)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse address URL: %s", err) return nil, fmt.Errorf("failed to parse address URL: %s", err)
} }
if storeURL.Scheme != "http" && storeURL.Scheme != "https" { if updateURL.Scheme != "http" && updateURL.Scheme != "https" {
return nil, fmt.Errorf("address must be HTTP or HTTPS") return nil, fmt.Errorf("address must be HTTP or HTTPS")
} }
storeMethod, ok := conf["store_method"] updateMethod, ok := conf["update_method"]
if !ok { if !ok {
storeMethod = "POST" updateMethod = "POST"
} }
var lockURL *url.URL var lockURL *url.URL
@ -89,8 +89,8 @@ func httpFactory(conf map[string]string) (Client, error) {
} }
ret := &HTTPClient{ ret := &HTTPClient{
URL: storeURL, URL: updateURL,
StoreMethod: storeMethod, UpdateMethod: updateMethod,
LockURL: lockURL, LockURL: lockURL,
LockMethod: lockMethod, LockMethod: lockMethod,
@ -109,9 +109,9 @@ func httpFactory(conf map[string]string) (Client, error) {
// HTTPClient is a remote client that stores data in Consul or HTTP REST. // HTTPClient is a remote client that stores data in Consul or HTTP REST.
type HTTPClient struct { type HTTPClient struct {
// Store & Retrieve // Update & Retrieve
URL *url.URL URL *url.URL
StoreMethod string UpdateMethod string
// Locking // Locking
LockURL *url.URL LockURL *url.URL
@ -302,8 +302,8 @@ func (c *HTTPClient) Put(data []byte) error {
*/ */
var method string = "POST" var method string = "POST"
if c.StoreMethod != "" { if c.UpdateMethod != "" {
method = c.StoreMethod method = c.UpdateMethod
} }
resp, err := c.httpRequest(method, &base, &data, "upload state") resp, err := c.httpRequest(method, &base, &data, "upload state")
if err != nil { if err != nil {

View File

@ -27,14 +27,14 @@ func TestHTTPClient(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
// Test basic get/store // Test basic get/update
client := &HTTPClient{URL: url, Client: cleanhttp.DefaultClient()} client := &HTTPClient{URL: url, Client: cleanhttp.DefaultClient()}
testClient(t, client) testClient(t, client)
// Test locking and alternative StoreMethod // Test locking and alternative UpdateMethod
a := &HTTPClient{ a := &HTTPClient{
URL: url, URL: url,
StoreMethod: "PUT", UpdateMethod: "PUT",
LockURL: url, LockURL: url,
LockMethod: "LOCK", LockMethod: "LOCK",
UnlockURL: url, UnlockURL: url,
@ -43,7 +43,7 @@ func TestHTTPClient(t *testing.T) {
} }
b := &HTTPClient{ b := &HTTPClient{
URL: url, URL: url,
StoreMethod: "PUT", UpdateMethod: "PUT",
LockURL: url, LockURL: url,
LockMethod: "LOCK", LockMethod: "LOCK",
UnlockURL: url, UnlockURL: url,
@ -79,8 +79,8 @@ func TestHTTPClientFactory(t *testing.T) {
if client.URL.String() != conf["address"] { if client.URL.String() != conf["address"] {
t.Fatalf("Expected address \"%s\", got \"%s\"", conf["address"], client.URL.String()) t.Fatalf("Expected address \"%s\", got \"%s\"", conf["address"], client.URL.String())
} }
if client.StoreMethod != "POST" { if client.UpdateMethod != "POST" {
t.Fatalf("Expected store_method \"%s\", got \"%s\"", "POST", client.StoreMethod) t.Fatalf("Expected update_method \"%s\", got \"%s\"", "POST", client.UpdateMethod)
} }
if client.LockURL != nil || client.LockMethod != "LOCK" { if client.LockURL != nil || client.LockMethod != "LOCK" {
t.Fatal("Unexpected lock_address or lock_method") t.Fatal("Unexpected lock_address or lock_method")
@ -95,7 +95,7 @@ func TestHTTPClientFactory(t *testing.T) {
// custom // custom
conf = map[string]string{ conf = map[string]string{
"address": "http://127.0.0.1:8888/foo", "address": "http://127.0.0.1:8888/foo",
"store_method": "BLAH", "update_method": "BLAH",
"lock_address": "http://127.0.0.1:8888/bar", "lock_address": "http://127.0.0.1:8888/bar",
"lock_method": "BLIP", "lock_method": "BLIP",
"unlock_address": "http://127.0.0.1:8888/baz", "unlock_address": "http://127.0.0.1:8888/baz",
@ -106,10 +106,10 @@ func TestHTTPClientFactory(t *testing.T) {
c, err = httpFactory(conf) c, err = httpFactory(conf)
client, _ = c.(*HTTPClient) client, _ = c.(*HTTPClient)
if client == nil || err != nil { if client == nil || err != nil {
t.Fatal("Unexpected failure, store_method") t.Fatal("Unexpected failure, update_method")
} }
if client.StoreMethod != "BLAH" { if client.UpdateMethod != "BLAH" {
t.Fatalf("Expected store_method \"%s\", got \"%s\"", "BLAH", client.StoreMethod) t.Fatalf("Expected update_method \"%s\", got \"%s\"", "BLAH", client.UpdateMethod)
} }
if client.LockURL.String() != conf["lock_address"] || client.LockMethod != "BLIP" { if client.LockURL.String() != conf["lock_address"] || client.LockMethod != "BLIP" {
t.Fatalf("Unexpected lock_address \"%s\" vs \"%s\" or lock_method \"%s\" vs \"%s\"", client.LockURL.String(), t.Fatalf("Unexpected lock_address \"%s\" vs \"%s\" or lock_method \"%s\" vs \"%s\"", client.LockURL.String(),