This commit is contained in:
Chao Xu 2015-10-08 18:30:38 -07:00
parent d1d10f8361
commit 50a2c4c643
19 changed files with 36 additions and 36 deletions

View File

@ -307,7 +307,7 @@ func handleVersion(req *restful.Request, resp *restful.Response) {
func APIVersionHandler(versions ...string) restful.RouteFunction { func APIVersionHandler(versions ...string) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) { return func(req *restful.Request, resp *restful.Response) {
// TODO: use restful's Response methods // TODO: use restful's Response methods
writeRawJSON(http.StatusOK, api.APIVersions{Versions: versions}, resp.ResponseWriter) writeRawJSON(http.StatusOK, unversioned.APIVersions{Versions: versions}, resp.ResponseWriter)
} }
} }

View File

@ -54,7 +54,7 @@ func buildLocation(resourcePath string, query url.Values) string {
} }
func TestListWatchesCanList(t *testing.T) { func TestListWatchesCanList(t *testing.T) {
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Default.Version()) fieldSelectorQueryParamName := unversioned.FieldSelectorQueryParam(testapi.Default.Version())
table := []struct { table := []struct {
location string location string
resource string resource string
@ -104,7 +104,7 @@ func TestListWatchesCanList(t *testing.T) {
} }
func TestListWatchesCanWatch(t *testing.T) { func TestListWatchesCanWatch(t *testing.T) {
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Default.Version()) fieldSelectorQueryParamName := unversioned.FieldSelectorQueryParam(testapi.Default.Version())
table := []struct { table := []struct {
rv string rv string
location string location string

View File

@ -116,7 +116,7 @@ func (c *Client) ComponentStatuses() ComponentStatusInterface {
// VersionInterface has a method to retrieve the server version. // VersionInterface has a method to retrieve the server version.
type VersionInterface interface { type VersionInterface interface {
ServerVersion() (*version.Info, error) ServerVersion() (*version.Info, error)
ServerAPIVersions() (*api.APIVersions, error) ServerAPIVersions() (*unversioned.APIVersions, error)
} }
// APIStatus is exposed by errors that can be converted to an api.Status object // APIStatus is exposed by errors that can be converted to an api.Status object
@ -146,12 +146,12 @@ func (c *Client) ServerVersion() (*version.Info, error) {
} }
// ServerAPIVersions retrieves and parses the list of API versions the server supports. // ServerAPIVersions retrieves and parses the list of API versions the server supports.
func (c *Client) ServerAPIVersions() (*api.APIVersions, error) { func (c *Client) ServerAPIVersions() (*unversioned.APIVersions, error) {
body, err := c.Get().UnversionedPath("").Do().Raw() body, err := c.Get().UnversionedPath("").Do().Raw()
if err != nil { if err != nil {
return nil, err return nil, err
} }
var v api.APIVersions var v unversioned.APIVersions
err = json.Unmarshal(body, &v) err = json.Unmarshal(body, &v)
if err != nil { if err != nil {
return nil, fmt.Errorf("got '%s': %v", string(body), err) return nil, fmt.Errorf("got '%s': %v", string(body), err)

View File

@ -149,9 +149,9 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
validator, ok := c.QueryValidator[key] validator, ok := c.QueryValidator[key]
if !ok { if !ok {
switch key { switch key {
case api.LabelSelectorQueryParam(testapi.Default.Version()): case unversioned.LabelSelectorQueryParam(testapi.Default.Version()):
validator = validateLabels validator = validateLabels
case api.FieldSelectorQueryParam(testapi.Default.Version()): case unversioned.FieldSelectorQueryParam(testapi.Default.Version()):
validator = validateFields validator = validateFields
default: default:
validator = func(a, b string) bool { return a == b } validator = func(a, b string) bool { return a == b }
@ -272,7 +272,7 @@ func TestGetServerVersion(t *testing.T) {
func TestGetServerAPIVersions(t *testing.T) { func TestGetServerAPIVersions(t *testing.T) {
versions := []string{"v1", "v2", "v3"} versions := []string{"v1", "v2", "v3"}
expect := api.APIVersions{Versions: versions} expect := unversioned.APIVersions{Versions: versions}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
output, err := json.Marshal(expect) output, err := json.Marshal(expect)
if err != nil { if err != nil {
@ -300,7 +300,7 @@ func swaggerSchemaFakeServer() (*httptest.Server, error) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
var resp interface{} var resp interface{}
if request == 1 { if request == 1 {
resp = api.APIVersions{Versions: []string{"v1", "v2", "v3"}} resp = unversioned.APIVersions{Versions: []string{"v1", "v2", "v3"}}
request++ request++
} else { } else {
resp = swagger.ApiDeclaration{} resp = swagger.ApiDeclaration{}

View File

@ -34,12 +34,12 @@ func TestEventSearch(t *testing.T) {
Method: "GET", Method: "GET",
Path: testapi.Default.ResourcePath("events", "baz", ""), Path: testapi.Default.ResourcePath("events", "baz", ""),
Query: url.Values{ Query: url.Values{
api.FieldSelectorQueryParam(testapi.Default.Version()): []string{ unversioned.FieldSelectorQueryParam(testapi.Default.Version()): []string{
getInvolvedObjectNameFieldLabel(testapi.Default.Version()) + "=foo,", getInvolvedObjectNameFieldLabel(testapi.Default.Version()) + "=foo,",
"involvedObject.namespace=baz,", "involvedObject.namespace=baz,",
"involvedObject.kind=Pod", "involvedObject.kind=Pod",
}, },
api.LabelSelectorQueryParam(testapi.Default.Version()): []string{}, unversioned.LabelSelectorQueryParam(testapi.Default.Version()): []string{},
}, },
}, },
Response: Response{StatusCode: 200, Body: &api.EventList{}}, Response: Response{StatusCode: 200, Body: &api.EventList{}},

View File

@ -63,12 +63,12 @@ func (c *ExperimentalClient) ServerVersion() (*version.Info, error) {
// ServerAPIVersions retrieves and parses the list of experimental API versions the // ServerAPIVersions retrieves and parses the list of experimental API versions the
// server supports. // server supports.
func (c *ExperimentalClient) ServerAPIVersions() (*api.APIVersions, error) { func (c *ExperimentalClient) ServerAPIVersions() (*unversioned.APIVersions, error) {
body, err := c.Get().UnversionedPath("").Do().Raw() body, err := c.Get().UnversionedPath("").Do().Raw()
if err != nil { if err != nil {
return nil, err return nil, err
} }
var v api.APIVersions var v unversioned.APIVersions
err = json.Unmarshal(body, &v) err = json.Unmarshal(body, &v)
if err != nil { if err != nil {
return nil, fmt.Errorf("got '%s': %v", string(body), err) return nil, fmt.Errorf("got '%s': %v", string(body), err)

View File

@ -90,10 +90,10 @@ func TestNegotiateVersion(t *testing.T) {
Codec: codec, Codec: codec,
Resp: &http.Response{ Resp: &http.Response{
StatusCode: 200, StatusCode: 200,
Body: objBody(&api.APIVersions{Versions: test.serverVersions}), Body: objBody(&unversioned.APIVersions{Versions: test.serverVersions}),
}, },
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: objBody(&api.APIVersions{Versions: test.serverVersions})}, nil return &http.Response{StatusCode: 200, Body: objBody(&unversioned.APIVersions{Versions: test.serverVersions})}, nil
}), }),
} }
c := unversioned.NewOrDie(test.config) c := unversioned.NewOrDie(test.config)

View File

@ -45,7 +45,7 @@ func TestListNodes(t *testing.T) {
} }
func TestListNodesLabels(t *testing.T) { func TestListNodesLabels(t *testing.T) {
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version()) labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",

View File

@ -64,7 +64,7 @@ func TestListPods(t *testing.T) {
func TestListPodsLabels(t *testing.T) { func TestListPodsLabels(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version()) labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",

View File

@ -372,7 +372,7 @@ func (r *Request) FieldsSelectorParam(s fields.Selector) *Request {
r.err = err r.err = err
return r return r
} }
return r.setParam(api.FieldSelectorQueryParam(r.apiVersion), s2.String()) return r.setParam(unversioned.FieldSelectorQueryParam(r.apiVersion), s2.String())
} }
// LabelsSelectorParam adds the given selector as a query parameter // LabelsSelectorParam adds the given selector as a query parameter
@ -386,7 +386,7 @@ func (r *Request) LabelsSelectorParam(s labels.Selector) *Request {
if s.Empty() { if s.Empty() {
return r return r
} }
return r.setParam(api.LabelSelectorQueryParam(r.apiVersion), s.String()) return r.setParam(unversioned.LabelSelectorQueryParam(r.apiVersion), s.String())
} }
// UintParam creates a query parameter with the given value. // UintParam creates a query parameter with the given value.

View File

@ -777,7 +777,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
} }
tmpStr := string(reqBodyExpected) tmpStr := string(reqBodyExpected)
requestURL := testapi.Default.ResourcePathWithPrefix("foo", "bar", "", "baz") requestURL := testapi.Default.ResourcePathWithPrefix("foo", "bar", "", "baz")
requestURL += "?" + api.LabelSelectorQueryParam(testapi.Default.Version()) + "=name%3Dfoo&timeout=1s" requestURL += "?" + unversioned.LabelSelectorQueryParam(testapi.Default.Version()) + "=name%3Dfoo&timeout=1s"
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr) fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
if fakeHandler.RequestReceived.Header["Authorization"] == nil { if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived) t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
@ -819,7 +819,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
} }
tmpStr := string(reqBodyExpected) tmpStr := string(reqBodyExpected)
requestURL := testapi.Default.ResourcePath("foo", "", "bar/baz") requestURL := testapi.Default.ResourcePath("foo", "", "bar/baz")
requestURL += "?" + api.LabelSelectorQueryParam(testapi.Default.Version()) + "=name%3Dfoo&timeout=1s" requestURL += "?" + unversioned.LabelSelectorQueryParam(testapi.Default.Version()) + "=name%3Dfoo&timeout=1s"
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr) fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
if fakeHandler.RequestReceived.Header["Authorization"] == nil { if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived) t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)

View File

@ -60,7 +60,7 @@ func TestListServices(t *testing.T) {
func TestListServicesLabels(t *testing.T) { func TestListServicesLabels(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version()) labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",

View File

@ -281,13 +281,13 @@ func (c *Fake) ServerVersion() (*version.Info, error) {
return &versionInfo, nil return &versionInfo, nil
} }
func (c *Fake) ServerAPIVersions() (*api.APIVersions, error) { func (c *Fake) ServerAPIVersions() (*unversioned.APIVersions, error) {
action := ActionImpl{} action := ActionImpl{}
action.Verb = "get" action.Verb = "get"
action.Resource = "apiversions" action.Resource = "apiversions"
c.Invokes(action, nil) c.Invokes(action, nil)
return &api.APIVersions{Versions: registered.RegisteredVersions}, nil return &unversioned.APIVersions{Versions: registered.RegisteredVersions}, nil
} }
func (c *Fake) ComponentStatuses() client.ComponentStatusInterface { func (c *Fake) ComponentStatuses() client.ComponentStatusInterface {

View File

@ -57,7 +57,7 @@ func RunApiVersions(f *cmdutil.Factory, w io.Writer) error {
os.Exit(1) os.Exit(1)
} }
var expAPIVersions *api.APIVersions var expAPIVersions *unversioned.APIVersions
expAPIVersions, err = client.Experimental().ServerAPIVersions() expAPIVersions, err = client.Experimental().ServerAPIVersions()
fmt.Fprintf(w, "Available Server Api Versions: %#v\n", *apiVersions) fmt.Fprintf(w, "Available Server Api Versions: %#v\n", *apiVersions)

View File

@ -416,12 +416,12 @@ func TestDeleteMultipleSelector(t *testing.T) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/pods" && m == "GET": case p == "/namespaces/test/pods" && m == "GET":
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" { if req.URL.Query().Get(unversioned.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil
case p == "/namespaces/test/services" && m == "GET": case p == "/namespaces/test/services" && m == "GET":
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" { if req.URL.Query().Get(unversioned.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil

View File

@ -507,7 +507,7 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
Codec: codec, Codec: codec,
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" { if req.URL.Query().Get(unversioned.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
switch req.URL.Path { switch req.URL.Path {
@ -633,7 +633,7 @@ func TestWatchSelector(t *testing.T) {
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
Codec: codec, Codec: codec,
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" { if req.URL.Query().Get(unversioned.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
switch req.URL.Path { switch req.URL.Path {

View File

@ -504,7 +504,7 @@ func TestResourceByNameAndEmptySelector(t *testing.T) {
func TestSelector(t *testing.T) { func TestSelector(t *testing.T) {
pods, svc := testData() pods, svc := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Default.Version()) labelKey := unversioned.LabelSelectorQueryParam(testapi.Default.Version())
b := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClientWith("", t, map[string]string{ b := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), pods), "/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), svc), "/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), svc),
@ -905,7 +905,7 @@ func TestSingularRootScopedObject(t *testing.T) {
func TestListObject(t *testing.T) { func TestListObject(t *testing.T) {
pods, _ := testData() pods, _ := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Default.Version()) labelKey := unversioned.LabelSelectorQueryParam(testapi.Default.Version())
b := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClientWith("", t, map[string]string{ b := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), pods), "/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), pods),
})). })).
@ -938,7 +938,7 @@ func TestListObject(t *testing.T) {
func TestListObjectWithDifferentVersions(t *testing.T) { func TestListObjectWithDifferentVersions(t *testing.T) {
pods, svc := testData() pods, svc := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Default.Version()) labelKey := unversioned.LabelSelectorQueryParam(testapi.Default.Version())
obj, err := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClientWith("", t, map[string]string{ obj, err := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), pods), "/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), svc), "/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(testapi.Default.Codec(), svc),

View File

@ -328,7 +328,7 @@ func TestHelperList(t *testing.T) {
t.Errorf("url doesn't contain name: %#v", req.URL) t.Errorf("url doesn't contain name: %#v", req.URL)
return false return false
} }
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != labels.SelectorFromSet(labels.Set{"foo": "baz"}).String() { if req.URL.Query().Get(unversioned.LabelSelectorQueryParam(testapi.Default.Version())) != labels.SelectorFromSet(labels.Set{"foo": "baz"}).String() {
t.Errorf("url doesn't contain query parameters: %#v", req.URL) t.Errorf("url doesn't contain query parameters: %#v", req.URL)
return false return false
} }

View File

@ -723,12 +723,12 @@ func checkOutput(output string, required [][]string) {
} }
} }
func getAPIVersions(apiEndpoint string) (*api.APIVersions, error) { func getAPIVersions(apiEndpoint string) (*unversioned.APIVersions, error) {
body, err := curl(apiEndpoint) body, err := curl(apiEndpoint)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed http.Get of %s: %v", apiEndpoint, err) return nil, fmt.Errorf("Failed http.Get of %s: %v", apiEndpoint, err)
} }
var apiVersions api.APIVersions var apiVersions unversioned.APIVersions
if err := json.Unmarshal([]byte(body), &apiVersions); err != nil { if err := json.Unmarshal([]byte(body), &apiVersions); err != nil {
return nil, fmt.Errorf("Failed to parse /api output %s: %v", body, err) return nil, fmt.Errorf("Failed to parse /api output %s: %v", body, err)
} }