Change remote/http store to update, more consistent with doc
This commit is contained in:
parent
510563b67f
commit
d889ac38b0
|
@ -22,16 +22,16 @@ func httpFactory(conf map[string]string) (Client, error) {
|
|||
return nil, fmt.Errorf("missing 'address' configuration")
|
||||
}
|
||||
|
||||
storeURL, err := url.Parse(address)
|
||||
updateURL, err := url.Parse(address)
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
storeMethod, ok := conf["store_method"]
|
||||
updateMethod, ok := conf["update_method"]
|
||||
if !ok {
|
||||
storeMethod = "POST"
|
||||
updateMethod = "POST"
|
||||
}
|
||||
|
||||
var lockURL *url.URL
|
||||
|
@ -89,8 +89,8 @@ func httpFactory(conf map[string]string) (Client, error) {
|
|||
}
|
||||
|
||||
ret := &HTTPClient{
|
||||
URL: storeURL,
|
||||
StoreMethod: storeMethod,
|
||||
URL: updateURL,
|
||||
UpdateMethod: updateMethod,
|
||||
|
||||
LockURL: lockURL,
|
||||
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.
|
||||
type HTTPClient struct {
|
||||
// Store & Retrieve
|
||||
URL *url.URL
|
||||
StoreMethod string
|
||||
// Update & Retrieve
|
||||
URL *url.URL
|
||||
UpdateMethod string
|
||||
|
||||
// Locking
|
||||
LockURL *url.URL
|
||||
|
@ -302,8 +302,8 @@ func (c *HTTPClient) Put(data []byte) error {
|
|||
*/
|
||||
|
||||
var method string = "POST"
|
||||
if c.StoreMethod != "" {
|
||||
method = c.StoreMethod
|
||||
if c.UpdateMethod != "" {
|
||||
method = c.UpdateMethod
|
||||
}
|
||||
resp, err := c.httpRequest(method, &base, &data, "upload state")
|
||||
if err != nil {
|
||||
|
|
|
@ -27,14 +27,14 @@ func TestHTTPClient(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Test basic get/store
|
||||
// Test basic get/update
|
||||
client := &HTTPClient{URL: url, Client: cleanhttp.DefaultClient()}
|
||||
testClient(t, client)
|
||||
|
||||
// Test locking and alternative StoreMethod
|
||||
// Test locking and alternative UpdateMethod
|
||||
a := &HTTPClient{
|
||||
URL: url,
|
||||
StoreMethod: "PUT",
|
||||
UpdateMethod: "PUT",
|
||||
LockURL: url,
|
||||
LockMethod: "LOCK",
|
||||
UnlockURL: url,
|
||||
|
@ -43,7 +43,7 @@ func TestHTTPClient(t *testing.T) {
|
|||
}
|
||||
b := &HTTPClient{
|
||||
URL: url,
|
||||
StoreMethod: "PUT",
|
||||
UpdateMethod: "PUT",
|
||||
LockURL: url,
|
||||
LockMethod: "LOCK",
|
||||
UnlockURL: url,
|
||||
|
@ -79,8 +79,8 @@ func TestHTTPClientFactory(t *testing.T) {
|
|||
if client.URL.String() != conf["address"] {
|
||||
t.Fatalf("Expected address \"%s\", got \"%s\"", conf["address"], client.URL.String())
|
||||
}
|
||||
if client.StoreMethod != "POST" {
|
||||
t.Fatalf("Expected store_method \"%s\", got \"%s\"", "POST", client.StoreMethod)
|
||||
if client.UpdateMethod != "POST" {
|
||||
t.Fatalf("Expected update_method \"%s\", got \"%s\"", "POST", client.UpdateMethod)
|
||||
}
|
||||
if client.LockURL != nil || client.LockMethod != "LOCK" {
|
||||
t.Fatal("Unexpected lock_address or lock_method")
|
||||
|
@ -95,7 +95,7 @@ func TestHTTPClientFactory(t *testing.T) {
|
|||
// custom
|
||||
conf = map[string]string{
|
||||
"address": "http://127.0.0.1:8888/foo",
|
||||
"store_method": "BLAH",
|
||||
"update_method": "BLAH",
|
||||
"lock_address": "http://127.0.0.1:8888/bar",
|
||||
"lock_method": "BLIP",
|
||||
"unlock_address": "http://127.0.0.1:8888/baz",
|
||||
|
@ -106,10 +106,10 @@ func TestHTTPClientFactory(t *testing.T) {
|
|||
c, err = httpFactory(conf)
|
||||
client, _ = c.(*HTTPClient)
|
||||
if client == nil || err != nil {
|
||||
t.Fatal("Unexpected failure, store_method")
|
||||
t.Fatal("Unexpected failure, update_method")
|
||||
}
|
||||
if client.StoreMethod != "BLAH" {
|
||||
t.Fatalf("Expected store_method \"%s\", got \"%s\"", "BLAH", client.StoreMethod)
|
||||
if client.UpdateMethod != "BLAH" {
|
||||
t.Fatalf("Expected update_method \"%s\", got \"%s\"", "BLAH", client.UpdateMethod)
|
||||
}
|
||||
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(),
|
||||
|
|
Loading…
Reference in New Issue