mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
refactor testapi and test scripts to prepare for multiple API groups.
This commit is contained in:
@@ -512,7 +512,7 @@ func TestResourceByNameAndEmptySelector(t *testing.T) {
|
||||
|
||||
func TestSelector(t *testing.T) {
|
||||
pods, svc := testData()
|
||||
labelKey := api.LabelSelectorQueryParam(testapi.Version())
|
||||
labelKey := api.LabelSelectorQueryParam(testapi.Default.Version())
|
||||
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
|
||||
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
||||
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
|
||||
@@ -808,7 +808,7 @@ func TestSingularRootScopedObject(t *testing.T) {
|
||||
|
||||
func TestListObject(t *testing.T) {
|
||||
pods, _ := testData()
|
||||
labelKey := api.LabelSelectorQueryParam(testapi.Version())
|
||||
labelKey := api.LabelSelectorQueryParam(testapi.Default.Version())
|
||||
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
|
||||
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
||||
})).
|
||||
@@ -841,7 +841,7 @@ func TestListObject(t *testing.T) {
|
||||
|
||||
func TestListObjectWithDifferentVersions(t *testing.T) {
|
||||
pods, svc := testData()
|
||||
labelKey := api.LabelSelectorQueryParam(testapi.Version())
|
||||
labelKey := api.LabelSelectorQueryParam(testapi.Default.Version())
|
||||
obj, err := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
|
||||
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
||||
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
func objBody(obj runtime.Object) io.ReadCloser {
|
||||
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(testapi.Codec(), obj))))
|
||||
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(testapi.Default.Codec(), obj))))
|
||||
}
|
||||
|
||||
// splitPath returns the segments for a URL path.
|
||||
@@ -93,7 +93,7 @@ func TestHelperDelete(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
client := &client.FakeRESTClient{
|
||||
Codec: testapi.Codec(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
Resp: test.Resp,
|
||||
Err: test.HttpErr,
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func TestHelperCreate(t *testing.T) {
|
||||
}
|
||||
for i, test := range tests {
|
||||
client := &client.FakeRESTClient{
|
||||
Codec: testapi.Codec(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
Resp: test.Resp,
|
||||
Err: test.HttpErr,
|
||||
}
|
||||
@@ -193,13 +193,13 @@ func TestHelperCreate(t *testing.T) {
|
||||
}
|
||||
modifier := &Helper{
|
||||
RESTClient: client,
|
||||
Codec: testapi.Codec(),
|
||||
Versioner: testapi.MetadataAccessor(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
Versioner: testapi.Default.MetadataAccessor(),
|
||||
NamespaceScoped: true,
|
||||
}
|
||||
data := []byte{}
|
||||
if test.Object != nil {
|
||||
data = []byte(runtime.EncodeOrDie(testapi.Codec(), test.Object))
|
||||
data = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.Object))
|
||||
}
|
||||
_, err := modifier.Create("bar", test.Modify, data)
|
||||
if (err != nil) != test.Err {
|
||||
@@ -218,7 +218,7 @@ func TestHelperCreate(t *testing.T) {
|
||||
t.Logf("got body: %s", string(body))
|
||||
expect := []byte{}
|
||||
if test.ExpectObject != nil {
|
||||
expect = []byte(runtime.EncodeOrDie(testapi.Codec(), test.ExpectObject))
|
||||
expect = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.ExpectObject))
|
||||
}
|
||||
if !reflect.DeepEqual(expect, body) {
|
||||
t.Errorf("%d: unexpected body: %s", i, string(body))
|
||||
@@ -270,7 +270,7 @@ func TestHelperGet(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
client := &client.FakeRESTClient{
|
||||
Codec: testapi.Codec(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
Resp: test.Resp,
|
||||
Err: test.HttpErr,
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func TestHelperList(t *testing.T) {
|
||||
t.Errorf("url doesn't contain name: %#v", req.URL)
|
||||
return false
|
||||
}
|
||||
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != labels.SelectorFromSet(labels.Set{"foo": "baz"}).String() {
|
||||
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != labels.SelectorFromSet(labels.Set{"foo": "baz"}).String() {
|
||||
t.Errorf("url doesn't contain query parameters: %#v", req.URL)
|
||||
return false
|
||||
}
|
||||
@@ -341,7 +341,7 @@ func TestHelperList(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
client := &client.FakeRESTClient{
|
||||
Codec: testapi.Codec(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
Resp: test.Resp,
|
||||
Err: test.HttpErr,
|
||||
}
|
||||
@@ -349,7 +349,7 @@ func TestHelperList(t *testing.T) {
|
||||
RESTClient: client,
|
||||
NamespaceScoped: true,
|
||||
}
|
||||
obj, err := modifier.List("bar", testapi.Version(), labels.SelectorFromSet(labels.Set{"foo": "baz"}))
|
||||
obj, err := modifier.List("bar", testapi.Default.Version(), labels.SelectorFromSet(labels.Set{"foo": "baz"}))
|
||||
if (err != nil) != test.Err {
|
||||
t.Errorf("unexpected error: %t %v", test.Err, err)
|
||||
}
|
||||
@@ -444,7 +444,7 @@ func TestHelperReplace(t *testing.T) {
|
||||
}
|
||||
for i, test := range tests {
|
||||
client := &client.FakeRESTClient{
|
||||
Codec: testapi.Codec(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
Resp: test.Resp,
|
||||
Err: test.HttpErr,
|
||||
}
|
||||
@@ -453,13 +453,13 @@ func TestHelperReplace(t *testing.T) {
|
||||
}
|
||||
modifier := &Helper{
|
||||
RESTClient: client,
|
||||
Codec: testapi.Codec(),
|
||||
Versioner: testapi.MetadataAccessor(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
Versioner: testapi.Default.MetadataAccessor(),
|
||||
NamespaceScoped: true,
|
||||
}
|
||||
data := []byte{}
|
||||
if test.Object != nil {
|
||||
data = []byte(runtime.EncodeOrDie(testapi.Codec(), test.Object))
|
||||
data = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.Object))
|
||||
}
|
||||
_, err := modifier.Replace("bar", "foo", test.Overwrite, data)
|
||||
if (err != nil) != test.Err {
|
||||
@@ -478,7 +478,7 @@ func TestHelperReplace(t *testing.T) {
|
||||
t.Logf("got body: %s", string(body))
|
||||
expect := []byte{}
|
||||
if test.ExpectObject != nil {
|
||||
expect = []byte(runtime.EncodeOrDie(testapi.Codec(), test.ExpectObject))
|
||||
expect = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.ExpectObject))
|
||||
}
|
||||
if !reflect.DeepEqual(expect, body) {
|
||||
t.Errorf("%d: unexpected body: %s", i, string(body))
|
||||
|
||||
Reference in New Issue
Block a user