mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
Implement required sync changes everywhere.
Make requests sync by default, so that usage of them doesn't have to change.
This commit is contained in:
@@ -43,9 +43,11 @@ import (
|
||||
// Begin a request with a verb (GET, POST, PUT, DELETE)
|
||||
func (c *Client) Verb(verb string) *Request {
|
||||
return &Request{
|
||||
verb: verb,
|
||||
c: c,
|
||||
path: "/api/v1beta1",
|
||||
verb: verb,
|
||||
c: c,
|
||||
path: "/api/v1beta1",
|
||||
sync: true,
|
||||
timeout: 10 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +82,7 @@ type Request struct {
|
||||
body io.Reader
|
||||
selector labels.Selector
|
||||
timeout time.Duration
|
||||
sync bool
|
||||
}
|
||||
|
||||
// Append an item to the request path. You must call Path at least once.
|
||||
@@ -91,6 +94,15 @@ func (r *Request) Path(item string) *Request {
|
||||
return r
|
||||
}
|
||||
|
||||
// Set sync/async call status.
|
||||
func (r *Request) Sync(sync bool) *Request {
|
||||
if r.err != nil {
|
||||
return r
|
||||
}
|
||||
r.sync = sync
|
||||
return r
|
||||
}
|
||||
|
||||
// Overwrite an existing path with the path parameter.
|
||||
func (r *Request) AbsPath(path string) *Request {
|
||||
if r.err != nil {
|
||||
@@ -168,8 +180,11 @@ func (r *Request) Do() Result {
|
||||
if r.selector != nil {
|
||||
query.Add("labels", r.selector.String())
|
||||
}
|
||||
if r.timeout != 0 {
|
||||
query.Add("timeout", r.timeout.String())
|
||||
if r.sync {
|
||||
query.Add("sync", "true")
|
||||
if r.timeout != 0 {
|
||||
query.Add("timeout", r.timeout.String())
|
||||
}
|
||||
}
|
||||
finalUrl += "?" + query.Encode()
|
||||
req, err := http.NewRequest(r.verb, finalUrl, r.body)
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestDoRequestNewWay(t *testing.T) {
|
||||
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
|
||||
}
|
||||
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz", "POST", &reqBody)
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo&timeout=1s" {
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo&sync=true&timeout=1s" {
|
||||
t.Errorf("Unexpected query: %v", fakeHandler.RequestReceived.URL.RawQuery)
|
||||
}
|
||||
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
||||
@@ -83,6 +83,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
|
||||
Path("foo/bar").
|
||||
Path("baz").
|
||||
Selector(labels.Set{"name": "foo"}.AsSelector()).
|
||||
Sync(false).
|
||||
Timeout(time.Second).
|
||||
Body(bytes.NewBuffer(reqBodyExpected)).
|
||||
Do().Get()
|
||||
@@ -97,7 +98,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz", "POST", &tmpStr)
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo&timeout=1s" {
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo" {
|
||||
t.Errorf("Unexpected query: %v", fakeHandler.RequestReceived.URL.RawQuery)
|
||||
}
|
||||
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
||||
@@ -136,7 +137,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz", "POST", &tmpStr)
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo&timeout=1s" {
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo&sync=true&timeout=1s" {
|
||||
t.Errorf("Unexpected query: %v", fakeHandler.RequestReceived.URL.RawQuery)
|
||||
}
|
||||
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
||||
@@ -181,7 +182,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz", "POST", &tmpStr)
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo&timeout=1s" {
|
||||
if fakeHandler.RequestReceived.URL.RawQuery != "labels=name%3Dfoo&sync=true&timeout=1s" {
|
||||
t.Errorf("Unexpected query: %v", fakeHandler.RequestReceived.URL.RawQuery)
|
||||
}
|
||||
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
||||
@@ -213,3 +214,19 @@ func TestAbsPath(t *testing.T) {
|
||||
t.Errorf("unexpected path: %s, expected %s", r.path, expectedPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSync(t *testing.T) {
|
||||
c := New("", nil)
|
||||
r := c.Get()
|
||||
if !r.sync {
|
||||
t.Errorf("sync has wrong default")
|
||||
}
|
||||
r.Sync(false)
|
||||
if r.sync {
|
||||
t.Errorf("'Sync' doesn't work")
|
||||
}
|
||||
r.Sync(true)
|
||||
if !r.sync {
|
||||
t.Errorf("'Sync' doesn't work")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user