mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Update tests to handle codec changes
This commit is contained in:
parent
2fd38a7dc0
commit
33085c0cf2
@ -211,7 +211,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
|
||||
taskInfo, err := podTask.BuildTaskInfo()
|
||||
assert.Equal(t, nil, err, "must be able to build task info")
|
||||
|
||||
data, err := testapi.Default.Codec().Encode(pod)
|
||||
data, err := runtime.Encode(testapi.Default.Codec(), pod)
|
||||
assert.Equal(t, nil, err, "must be able to encode a pod's spec data")
|
||||
|
||||
taskInfo.Data = data
|
||||
@ -410,7 +410,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
|
||||
taskInfo, err := podTask.BuildTaskInfo()
|
||||
assert.Equal(t, nil, err, "must be able to build task info")
|
||||
|
||||
data, _ := testapi.Default.Codec().Encode(pod)
|
||||
data, _ := runtime.Encode(testapi.Default.Codec(), pod)
|
||||
taskInfo.Data = data
|
||||
|
||||
mockDriver.On(
|
||||
|
@ -421,7 +421,7 @@ func TestExampleObjectSchemas(t *testing.T) {
|
||||
return
|
||||
}
|
||||
if strings.Contains(name, "scheduler-policy-config") {
|
||||
if err := schedulerapilatest.Codec.DecodeInto(data, expectedType); err != nil {
|
||||
if err := runtime.DecodeInto(schedulerapilatest.Codec, data, expectedType); err != nil {
|
||||
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
|
||||
return
|
||||
}
|
||||
@ -516,14 +516,14 @@ func TestReadme(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("%s could not be converted to JSON: %v\n%s", path, err, string(content))
|
||||
}
|
||||
if err := testapi.Default.Codec().DecodeInto(json, expectedType); err != nil {
|
||||
if err := runtime.DecodeInto(testapi.Default.Codec(), json, expectedType); err != nil {
|
||||
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(content))
|
||||
continue
|
||||
}
|
||||
if errors := validateObject(expectedType); len(errors) > 0 {
|
||||
t.Errorf("%s did not validate correctly: %v", path, errors)
|
||||
}
|
||||
_, err = testapi.Default.Codec().Encode(expectedType)
|
||||
_, err = runtime.Encode(testapi.Default.Codec(), expectedType)
|
||||
if err != nil {
|
||||
t.Errorf("Could not encode object: %v", err)
|
||||
continue
|
||||
|
@ -17,7 +17,12 @@ limitations under the License.
|
||||
package testapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// TODO these tests don't add much value for testing things that have groups
|
||||
@ -61,3 +66,61 @@ func TestResourcePath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var status = &unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: 200,
|
||||
Reason: unversioned.StatusReasonUnknown,
|
||||
Message: "",
|
||||
}
|
||||
|
||||
func TestV1EncodeDecodeStatus(t *testing.T) {
|
||||
v1Codec := Default.Codec()
|
||||
|
||||
encoded, err := runtime.Encode(v1Codec, status)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
typeMeta := unversioned.TypeMeta{}
|
||||
if err := json.Unmarshal(encoded, &typeMeta); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if typeMeta.Kind != "Status" {
|
||||
t.Errorf("Kind is not set to \"Status\". Got %v", string(encoded))
|
||||
}
|
||||
if typeMeta.APIVersion != "v1" {
|
||||
t.Errorf("APIVersion is not set to \"v1\". Got %v", string(encoded))
|
||||
}
|
||||
decoded, err := runtime.Decode(v1Codec, encoded)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(status, decoded) {
|
||||
t.Errorf("expected: %#v, got: %#v", status, decoded)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExperimentalEncodeDecodeStatus(t *testing.T) {
|
||||
extensionCodec := Extensions.Codec()
|
||||
encoded, err := runtime.Encode(extensionCodec, status)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
typeMeta := unversioned.TypeMeta{}
|
||||
if err := json.Unmarshal(encoded, &typeMeta); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if typeMeta.Kind != "Status" {
|
||||
t.Errorf("Kind is not set to \"Status\". Got %s", encoded)
|
||||
}
|
||||
if typeMeta.APIVersion != "v1" {
|
||||
t.Errorf("APIVersion is not set to \"\". Got %s", encoded)
|
||||
}
|
||||
decoded, err := runtime.Decode(extensionCodec, encoded)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(status, decoded) {
|
||||
t.Errorf("expected: %v, got: %v", status, decoded)
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
|
@ -17,14 +17,10 @@ limitations under the License.
|
||||
package registered
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apimachinery"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
func TestAllPreferredGroupVersions(t *testing.T) {
|
||||
@ -70,61 +66,3 @@ func TestAllPreferredGroupVersions(t *testing.T) {
|
||||
reset()
|
||||
}
|
||||
}
|
||||
|
||||
var status = &unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: 200,
|
||||
Reason: unversioned.StatusReasonUnknown,
|
||||
Message: "",
|
||||
}
|
||||
|
||||
func TestV1EncodeDecodeStatus(t *testing.T) {
|
||||
v1Codec := testapi.Default.Codec()
|
||||
|
||||
encoded, err := runtime.Encode(v1Codec, status)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
typeMeta := unversioned.TypeMeta{}
|
||||
if err := json.Unmarshal(encoded, &typeMeta); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if typeMeta.Kind != "Status" {
|
||||
t.Errorf("Kind is not set to \"Status\". Got %v", string(encoded))
|
||||
}
|
||||
if typeMeta.APIVersion != "v1" {
|
||||
t.Errorf("APIVersion is not set to \"v1\". Got %v", string(encoded))
|
||||
}
|
||||
decoded, err := runtime.Decode(v1Codec, encoded)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(status, decoded) {
|
||||
t.Errorf("expected: %#v, got: %#v", status, decoded)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExperimentalEncodeDecodeStatus(t *testing.T) {
|
||||
extensionCodec := testapi.Extensions.Codec()
|
||||
encoded, err := runtime.Encode(extensionCodec, status)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
typeMeta := unversioned.TypeMeta{}
|
||||
if err := json.Unmarshal(encoded, &typeMeta); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if typeMeta.Kind != "Status" {
|
||||
t.Errorf("Kind is not set to \"Status\". Got %s", encoded)
|
||||
}
|
||||
if typeMeta.APIVersion != "v1" {
|
||||
t.Errorf("APIVersion is not set to \"\". Got %s", encoded)
|
||||
}
|
||||
decoded, err := runtime.Decode(extensionCodec, encoded)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(status, decoded) {
|
||||
t.Errorf("expected: %v, got: %v", status, decoded)
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||
|
@ -30,7 +30,6 @@ import (
|
||||
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/strategicpatch"
|
||||
|
@ -30,8 +30,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/version"
|
||||
)
|
||||
|
||||
const nameRequiredError = "resource name may not be empty"
|
||||
|
||||
func TestGetServerVersion(t *testing.T) {
|
||||
expect := version.Info{
|
||||
Major: "foo",
|
||||
|
@ -71,7 +71,7 @@ func TestNegotiateVersion(t *testing.T) {
|
||||
{
|
||||
name: "explicit version supported",
|
||||
config: &unversioned.Config{GroupVersion: testapi.Default.GroupVersion()},
|
||||
serverVersions: []string{"/ersion1", testapi.Default.GroupVersion().String()},
|
||||
serverVersions: []string{"/version1", testapi.Default.GroupVersion().String()},
|
||||
clientVersions: []uapi.GroupVersion{{Version: "version1"}, *testapi.Default.GroupVersion()},
|
||||
expectedVersion: testapi.Default.GroupVersion(),
|
||||
},
|
||||
|
@ -212,7 +212,7 @@ func TestCreatePods(t *testing.T) {
|
||||
Spec: controllerSpec.Spec.Template.Spec,
|
||||
}
|
||||
fakeHandler.ValidateRequest(t, testapi.Default.ResourcePath("pods", api.NamespaceDefault, ""), "POST", nil)
|
||||
actualPod, err := client.Codec.Decode([]byte(fakeHandler.RequestBody))
|
||||
actualPod, err := runtime.Decode(client.Codec, []byte(fakeHandler.RequestBody))
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %#v", err)
|
||||
}
|
||||
|
@ -275,8 +275,9 @@ func TestExampleObjects(t *testing.T) {
|
||||
}
|
||||
|
||||
for name, scenario := range scenarios {
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/"+name, o, api.Scheme); err != nil {
|
||||
codec := api.Codecs.UniversalDecoder()
|
||||
o := testclient.NewObjects(api.Scheme, codec)
|
||||
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/"+name, o, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -332,11 +333,12 @@ func TestExampleObjects(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBindingWithExamples(t *testing.T) {
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, api.Scheme); err != nil {
|
||||
codec := api.Codecs.UniversalDecoder()
|
||||
o := testclient.NewObjects(api.Scheme, codec)
|
||||
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/volumes/local-01.yaml", o, api.Scheme); err != nil {
|
||||
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/volumes/local-01.yaml", o, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
|
||||
// TODO: Ideally we should create the necessary package structure in e.g.,
|
||||
// pkg/conversion/test/... instead of importing pkg/api here.
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
|
@ -441,7 +441,7 @@ func refJson(t *testing.T, o runtime.Object) string {
|
||||
}
|
||||
|
||||
_, _, codec := NewAPIFactory()
|
||||
json, err := codec.Encode(&api.SerializedReference{Reference: *ref})
|
||||
json, err := runtime.Encode(codec, &api.SerializedReference{Reference: *ref})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -24,9 +24,10 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/securitycontext"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
//"github.com/ghodss/yaml"
|
||||
)
|
||||
|
||||
func noDefault(*api.Pod) error { return nil }
|
||||
@ -56,7 +57,7 @@ func TestDecodeSinglePod(t *testing.T) {
|
||||
SecurityContext: &api.PodSecurityContext{},
|
||||
},
|
||||
}
|
||||
json, err := testapi.Default.Codec().Encode(pod)
|
||||
json, err := runtime.Encode(testapi.Default.Codec(), pod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@ -72,15 +73,12 @@ func TestDecodeSinglePod(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, gv := range registered.EnabledVersionsForGroup(api.GroupName) {
|
||||
externalPod, err := testapi.Default.Converter().ConvertToVersion(pod, gv.String())
|
||||
s, _ := api.Codecs.SerializerForFileExtension("yaml")
|
||||
encoder := api.Codecs.EncoderForVersion(s, gv)
|
||||
yaml, err := runtime.Encode(encoder, pod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
yaml, err := yaml.Marshal(externalPod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
parsed, podOut, err = tryDecodeSinglePod(yaml, noDefault)
|
||||
if !parsed {
|
||||
t.Errorf("expected to have parsed file: (%s)", string(yaml))
|
||||
@ -122,7 +120,7 @@ func TestDecodePodList(t *testing.T) {
|
||||
podList := &api.PodList{
|
||||
Items: []api.Pod{*pod},
|
||||
}
|
||||
json, err := testapi.Default.Codec().Encode(podList)
|
||||
json, err := runtime.Encode(testapi.Default.Codec(), podList)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@ -138,21 +136,21 @@ func TestDecodePodList(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, gv := range registered.EnabledVersionsForGroup(api.GroupName) {
|
||||
externalPodList, err := testapi.Default.Converter().ConvertToVersion(podList, gv.String())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
yaml, err := yaml.Marshal(externalPodList)
|
||||
s, _ := api.Codecs.SerializerForFileExtension("yaml")
|
||||
encoder := api.Codecs.EncoderForVersion(s, gv)
|
||||
yaml, err := runtime.Encode(encoder, podList)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
parsed, podListOut, err = tryDecodePodList(yaml, noDefault)
|
||||
if !parsed {
|
||||
t.Errorf("expected to have parsed file: (%s)", string(yaml))
|
||||
t.Errorf("expected to have parsed file: (%s): %v", string(yaml), err)
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v (%s)", err, string(yaml))
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(podList, &podListOut) {
|
||||
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", pod, &podListOut, string(yaml))
|
||||
|
@ -132,7 +132,7 @@ func TestReadPodsFromFile(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("%s: error in versioning the pod: %v", testCase.desc, err)
|
||||
}
|
||||
fileContents, err := testapi.Default.Codec().Encode(versionedPod)
|
||||
fileContents, err := runtime.Encode(testapi.Default.Codec(), versionedPod)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err)
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("%s: error in versioning the pods: %s", testCase.desc, err)
|
||||
}
|
||||
data, err := testapi.Default.Codec().Encode(versionedPods)
|
||||
data, err := runtime.Encode(testapi.Default.Codec(), versionedPods)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err)
|
||||
}
|
||||
|
@ -22,9 +22,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/intstr"
|
||||
)
|
||||
|
||||
@ -107,7 +108,7 @@ func TestLabels(t *testing.T) {
|
||||
pod.DeletionGracePeriodSeconds = &deletionGracePeriod
|
||||
pod.Spec.TerminationGracePeriodSeconds = &terminationGracePeriod
|
||||
container.Lifecycle = lifecycle
|
||||
data, err := registered.GroupOrDie(api.GroupName).Codec.Encode(pod)
|
||||
data, err := runtime.Encode(testapi.Default.Codec(), pod)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to encode pod %q into string: %v", format.Pod(pod), err)
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
uexec "k8s.io/kubernetes/pkg/util/exec"
|
||||
@ -448,7 +449,7 @@ func TestKillContainerInPodWithPreStop(t *testing.T) {
|
||||
},
|
||||
{Name: "bar"}}},
|
||||
}
|
||||
podString, err := testapi.Default.Codec().Encode(pod)
|
||||
podString, err := runtime.Encode(testapi.Default.Codec(), pod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
etcd "github.com/coreos/etcd/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -30,6 +31,7 @@ import (
|
||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/conversion"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/serializer"
|
||||
"k8s.io/kubernetes/pkg/storage"
|
||||
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
|
||||
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
|
||||
@ -39,20 +41,25 @@ import (
|
||||
|
||||
const validEtcdVersion = "etcd 2.0.9"
|
||||
|
||||
var scheme *runtime.Scheme
|
||||
var codec runtime.Codec
|
||||
|
||||
func init() {
|
||||
scheme = runtime.NewScheme()
|
||||
scheme.AddKnownTypes(testapi.Default.InternalGroupVersion(), &storagetesting.TestResource{})
|
||||
func testScheme(t *testing.T) (*runtime.Scheme, runtime.Codec) {
|
||||
scheme := runtime.NewScheme()
|
||||
scheme.Log(t)
|
||||
scheme.AddKnownTypes(*testapi.Default.GroupVersion(), &storagetesting.TestResource{})
|
||||
codec = runtime.CodecFor(scheme, *testapi.Default.GroupVersion())
|
||||
scheme.AddConversionFuncs(
|
||||
scheme.AddKnownTypes(testapi.Default.InternalGroupVersion(), &storagetesting.TestResource{})
|
||||
if err := scheme.AddConversionFuncs(
|
||||
func(in *storagetesting.TestResource, out *storagetesting.TestResource, s conversion.Scope) error {
|
||||
*out = *in
|
||||
return nil
|
||||
},
|
||||
)
|
||||
func(in, out *time.Time, s conversion.Scope) error {
|
||||
*out = *in
|
||||
return nil
|
||||
},
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
codec := serializer.NewCodecFactory(scheme).LegacyCodec(*testapi.Default.GroupVersion())
|
||||
return scheme, codec
|
||||
}
|
||||
|
||||
func newEtcdHelper(client etcd.Client, codec runtime.Codec, prefix string) etcdHelper {
|
||||
@ -61,7 +68,7 @@ func newEtcdHelper(client etcd.Client, codec runtime.Codec, prefix string) etcdH
|
||||
|
||||
// Returns an encoded version of api.Pod with the given name.
|
||||
func getEncodedPod(name string) string {
|
||||
pod, _ := testapi.Default.Codec().Encode(&api.Pod{
|
||||
pod, _ := runtime.Encode(testapi.Default.Codec(), &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: name},
|
||||
})
|
||||
return string(pod)
|
||||
@ -258,7 +265,7 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
_, err = testapi.Default.Codec().Encode(obj)
|
||||
_, err = runtime.Encode(testapi.Default.Codec(), obj)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
@ -266,7 +273,7 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
_, err = testapi.Default.Codec().Encode(returnedObj)
|
||||
_, err = runtime.Encode(testapi.Default.Codec(), returnedObj)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
@ -374,6 +381,7 @@ func TestSetNilOutParam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGuaranteedUpdate(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
server := etcdtesting.NewEtcdTestClientServer(t)
|
||||
defer server.Terminate(t)
|
||||
key := etcdtest.AddPrefix("/some/key")
|
||||
@ -418,6 +426,7 @@ func TestGuaranteedUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGuaranteedUpdateNoChange(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
server := etcdtesting.NewEtcdTestClientServer(t)
|
||||
defer server.Terminate(t)
|
||||
key := etcdtest.AddPrefix("/some/key")
|
||||
@ -447,6 +456,7 @@ func TestGuaranteedUpdateNoChange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGuaranteedUpdateKeyNotFound(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
server := etcdtesting.NewEtcdTestClientServer(t)
|
||||
defer server.Terminate(t)
|
||||
key := etcdtest.AddPrefix("/some/key")
|
||||
@ -473,6 +483,7 @@ func TestGuaranteedUpdateKeyNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGuaranteedUpdate_CreateCollision(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
server := etcdtesting.NewEtcdTestClientServer(t)
|
||||
defer server.Terminate(t)
|
||||
key := etcdtest.AddPrefix("/some/key")
|
||||
|
@ -169,6 +169,7 @@ func TestWatchInterpretations(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWatchInterpretation_ResponseNotSet(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
w := newEtcdWatcher(false, nil, storage.Everything, codec, versioner, nil, &fakeEtcdCache{})
|
||||
w.emit = func(e watch.Event) {
|
||||
t.Errorf("Unexpected emit: %v", e)
|
||||
@ -181,6 +182,7 @@ func TestWatchInterpretation_ResponseNotSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWatchInterpretation_ResponseNoNode(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
actions := []string{"create", "set", "compareAndSwap", "delete"}
|
||||
for _, action := range actions {
|
||||
w := newEtcdWatcher(false, nil, storage.Everything, codec, versioner, nil, &fakeEtcdCache{})
|
||||
@ -195,6 +197,7 @@ func TestWatchInterpretation_ResponseNoNode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWatchInterpretation_ResponseBadData(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
actions := []string{"create", "set", "compareAndSwap", "delete"}
|
||||
for _, action := range actions {
|
||||
w := newEtcdWatcher(false, nil, storage.Everything, codec, versioner, nil, &fakeEtcdCache{})
|
||||
@ -448,6 +451,7 @@ func TestWatchListIgnoresRootKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWatchPurposefulShutdown(t *testing.T) {
|
||||
_, codec := testScheme(t)
|
||||
server := etcdtesting.NewEtcdTestClientServer(t)
|
||||
defer server.Terminate(t)
|
||||
key := "/some/key"
|
||||
|
@ -93,7 +93,7 @@ func testFailJSONPath(tests []jsonpathTest, t *testing.T) {
|
||||
out = err.Error()
|
||||
}
|
||||
if out != test.expect {
|
||||
t.Errorf("in %s, expect to get error %s, got %s", test.name, test.expect, out)
|
||||
t.Errorf("in %s, expect to get error %q, got %q", test.name, test.expect, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,7 +160,7 @@ func TestStructInput(t *testing.T) {
|
||||
testJSONPath(storeTests, t)
|
||||
|
||||
failStoreTests := []jsonpathTest{
|
||||
{"invalid identfier", "{hello}", storeData, "unrecongnized identifier hello"},
|
||||
{"invalid identfier", "{hello}", storeData, "unrecognized identifier hello"},
|
||||
{"nonexistent field", "{.hello}", storeData, "hello is not found"},
|
||||
{"invalid array", "{.Labels[0]}", storeData, "map[string]int is not array or slice"},
|
||||
{"invalid filter operator", "{.Book[?(@.Price<>10)]}", storeData, "unrecognized filter operator <>"},
|
||||
|
@ -62,7 +62,7 @@ func TestSplitYAMLDocument(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGuessJSON(t *testing.T) {
|
||||
if r, isJSON := guessJSONStream(bytes.NewReader([]byte(" \n{}")), 100); !isJSON {
|
||||
if r, isJSON := GuessJSONStream(bytes.NewReader([]byte(" \n{}")), 100); !isJSON {
|
||||
t.Fatalf("expected stream to be JSON")
|
||||
} else {
|
||||
b := make([]byte, 30)
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
@ -259,11 +258,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
||||
if err != nil {
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
@ -231,11 +230,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
@ -274,11 +273,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
||||
if err != nil {
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/exec"
|
||||
@ -193,12 +192,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
o.Add(ep)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim, ep)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
@ -256,11 +255,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
@ -231,11 +230,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
@ -233,11 +232,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
|
@ -234,11 +234,7 @@ func TestNewBuilder(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, item := range tests {
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(item.pv)
|
||||
o.Add(item.claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, api.RESTMapper))
|
||||
client := testclient.NewSimpleFake(item.pv, item.claim)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(testProbeVolumePlugins(), newTestHost(t, client))
|
||||
@ -289,11 +285,7 @@ func TestNewBuilderClaimNotBound(t *testing.T) {
|
||||
ClaimName: "claimC",
|
||||
},
|
||||
}
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, api.RESTMapper))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(testProbeVolumePlugins(), newTestHost(t, client))
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
@ -188,11 +187,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
o.Add(pv)
|
||||
o.Add(claim)
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
client := testclient.NewSimpleFake(pv, claim)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
|
@ -39,7 +39,7 @@ func TestDecoder(t *testing.T) {
|
||||
expect := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
|
||||
encoder := json.NewEncoder(in)
|
||||
go func() {
|
||||
data, err := testapi.Default.Codec().Encode(expect)
|
||||
data, err := runtime.Encode(testapi.Default.Codec(), expect)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
|
||||
latestschedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api/latest"
|
||||
"k8s.io/kubernetes/plugin/pkg/scheduler/factory"
|
||||
@ -92,16 +93,14 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
|
||||
for v, tc := range schedulerFiles {
|
||||
policy := schedulerapi.Policy{}
|
||||
err := latestschedulerapi.Codec.DecodeInto([]byte(tc.JSON), &policy)
|
||||
if err != nil {
|
||||
if err := runtime.DecodeInto(latestschedulerapi.Codec, []byte(tc.JSON), &policy); err != nil {
|
||||
t.Errorf("%s: Error decoding: %v", v, err)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(policy, tc.ExpectedPolicy) {
|
||||
t.Errorf("%s: Expected:\n\t%#v\nGot:\n\t%#v", v, tc.ExpectedPolicy, policy)
|
||||
}
|
||||
_, err = factory.NewConfigFactory(nil, "some-scheduler-name").CreateFromConfig(policy)
|
||||
if err != nil {
|
||||
if _, err := factory.NewConfigFactory(nil, "some-scheduler-name").CreateFromConfig(policy); err != nil {
|
||||
t.Errorf("%s: Error constructing: %v", v, err)
|
||||
continue
|
||||
}
|
||||
|
@ -87,8 +87,7 @@ func TestCreateFromConfig(t *testing.T) {
|
||||
{"name" : "PriorityOne", "weight" : 2},
|
||||
{"name" : "PriorityTwo", "weight" : 1} ]
|
||||
}`)
|
||||
err := latestschedulerapi.Codec.DecodeInto(configData, &policy)
|
||||
if err != nil {
|
||||
if err := runtime.DecodeInto(latestschedulerapi.Codec, configData, &policy); err != nil {
|
||||
t.Errorf("Invalid configuration: %v", err)
|
||||
}
|
||||
|
||||
@ -111,8 +110,7 @@ func TestCreateFromEmptyConfig(t *testing.T) {
|
||||
factory := NewConfigFactory(client, api.DefaultSchedulerName)
|
||||
|
||||
configData = []byte(`{}`)
|
||||
err := latestschedulerapi.Codec.DecodeInto(configData, &policy)
|
||||
if err != nil {
|
||||
if err := runtime.DecodeInto(latestschedulerapi.Codec, configData, &policy); err != nil {
|
||||
t.Errorf("Invalid configuration: %v", err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user