mirror of https://github.com/k3s-io/k3s
kubectl replace legacyscheme with kubectl scheme in two tests
parent
3c43f089b2
commit
a20ba98b87
|
@ -36,7 +36,6 @@ go_test(
|
||||||
],
|
],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/legacyscheme:go_default_library",
|
|
||||||
"//pkg/api/testapi:go_default_library",
|
"//pkg/api/testapi:go_default_library",
|
||||||
"//pkg/api/testing:go_default_library",
|
"//pkg/api/testing:go_default_library",
|
||||||
"//pkg/kubectl/scheme:go_default_library",
|
"//pkg/kubectl/scheme:go_default_library",
|
||||||
|
|
|
@ -57,8 +57,8 @@ go_test(
|
||||||
srcs = ["cani_test.go"],
|
srcs = ["cani_test.go"],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/legacyscheme:go_default_library",
|
|
||||||
"//pkg/kubectl/cmd/testing:go_default_library",
|
"//pkg/kubectl/cmd/testing:go_default_library",
|
||||||
|
"//pkg/kubectl/scheme:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/rest/fake:go_default_library",
|
"//staging/src/k8s.io/client-go/rest/fake:go_default_library",
|
||||||
|
|
|
@ -27,8 +27,8 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/rest/fake"
|
"k8s.io/client-go/rest/fake"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
|
||||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunAccessCheck(t *testing.T) {
|
func TestRunAccessCheck(t *testing.T) {
|
||||||
|
@ -124,7 +124,7 @@ func TestRunAccessCheck(t *testing.T) {
|
||||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||||
defer tf.Cleanup()
|
defer tf.Cleanup()
|
||||||
|
|
||||||
ns := legacyscheme.Codecs
|
ns := scheme.Codecs
|
||||||
|
|
||||||
tf.Client = &fake.RESTClient{
|
tf.Client = &fake.RESTClient{
|
||||||
GroupVersion: schema.GroupVersion{Group: "", Version: "v1"},
|
GroupVersion: schema.GroupVersion{Group: "", Version: "v1"},
|
||||||
|
|
|
@ -21,16 +21,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
api "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
func encodeOrDie(obj runtime.Object) []byte {
|
func encodeOrDie(obj runtime.Object) []byte {
|
||||||
data, err := runtime.Encode(legacyscheme.Codecs.LegacyCodec(api.SchemeGroupVersion), obj)
|
data, err := runtime.Encode(scheme.Codecs.LegacyCodec(corev1.SchemeGroupVersion), obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -40,19 +40,19 @@ func encodeOrDie(obj runtime.Object) []byte {
|
||||||
func TestSortingPrinter(t *testing.T) {
|
func TestSortingPrinter(t *testing.T) {
|
||||||
intPtr := func(val int32) *int32 { return &val }
|
intPtr := func(val int32) *int32 { return &val }
|
||||||
|
|
||||||
a := &api.Pod{
|
a := &corev1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "a",
|
Name: "a",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
b := &api.Pod{
|
b := &corev1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "b",
|
Name: "b",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &api.Pod{
|
c := &corev1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "c",
|
Name: "c",
|
||||||
},
|
},
|
||||||
|
@ -67,8 +67,8 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "in-order-already",
|
name: "in-order-already",
|
||||||
obj: &api.PodList{
|
obj: &corev1.PodList{
|
||||||
Items: []api.Pod{
|
Items: []corev1.Pod{
|
||||||
{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "a",
|
Name: "a",
|
||||||
|
@ -86,8 +86,8 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sort: &api.PodList{
|
sort: &corev1.PodList{
|
||||||
Items: []api.Pod{
|
Items: []corev1.Pod{
|
||||||
{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "a",
|
Name: "a",
|
||||||
|
@ -109,8 +109,8 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "reverse-order",
|
name: "reverse-order",
|
||||||
obj: &api.PodList{
|
obj: &corev1.PodList{
|
||||||
Items: []api.Pod{
|
Items: []corev1.Pod{
|
||||||
{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "b",
|
Name: "b",
|
||||||
|
@ -128,8 +128,8 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sort: &api.PodList{
|
sort: &corev1.PodList{
|
||||||
Items: []api.Pod{
|
Items: []corev1.Pod{
|
||||||
{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "a",
|
Name: "a",
|
||||||
|
@ -151,8 +151,8 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "random-order-timestamp",
|
name: "random-order-timestamp",
|
||||||
obj: &api.PodList{
|
obj: &corev1.PodList{
|
||||||
Items: []api.Pod{
|
Items: []corev1.Pod{
|
||||||
{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
CreationTimestamp: metav1.Unix(300, 0),
|
CreationTimestamp: metav1.Unix(300, 0),
|
||||||
|
@ -170,8 +170,8 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sort: &api.PodList{
|
sort: &corev1.PodList{
|
||||||
Items: []api.Pod{
|
Items: []corev1.Pod{
|
||||||
{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
CreationTimestamp: metav1.Unix(100, 0),
|
CreationTimestamp: metav1.Unix(100, 0),
|
||||||
|
@ -193,39 +193,39 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "random-order-numbers",
|
name: "random-order-numbers",
|
||||||
obj: &api.ReplicationControllerList{
|
obj: &corev1.ReplicationControllerList{
|
||||||
Items: []api.ReplicationController{
|
Items: []corev1.ReplicationController{
|
||||||
{
|
{
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: corev1.ReplicationControllerSpec{
|
||||||
Replicas: intPtr(5),
|
Replicas: intPtr(5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: corev1.ReplicationControllerSpec{
|
||||||
Replicas: intPtr(1),
|
Replicas: intPtr(1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: corev1.ReplicationControllerSpec{
|
||||||
Replicas: intPtr(9),
|
Replicas: intPtr(9),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sort: &api.ReplicationControllerList{
|
sort: &corev1.ReplicationControllerList{
|
||||||
Items: []api.ReplicationController{
|
Items: []corev1.ReplicationController{
|
||||||
{
|
{
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: corev1.ReplicationControllerSpec{
|
||||||
Replicas: intPtr(1),
|
Replicas: intPtr(1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: corev1.ReplicationControllerSpec{
|
||||||
Replicas: intPtr(5),
|
Replicas: intPtr(5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: corev1.ReplicationControllerSpec{
|
||||||
Replicas: intPtr(9),
|
Replicas: intPtr(9),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -235,14 +235,14 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "v1.List in order",
|
name: "v1.List in order",
|
||||||
obj: &api.List{
|
obj: &corev1.List{
|
||||||
Items: []runtime.RawExtension{
|
Items: []runtime.RawExtension{
|
||||||
{Raw: encodeOrDie(a)},
|
{Raw: encodeOrDie(a)},
|
||||||
{Raw: encodeOrDie(b)},
|
{Raw: encodeOrDie(b)},
|
||||||
{Raw: encodeOrDie(c)},
|
{Raw: encodeOrDie(c)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sort: &api.List{
|
sort: &corev1.List{
|
||||||
Items: []runtime.RawExtension{
|
Items: []runtime.RawExtension{
|
||||||
{Raw: encodeOrDie(a)},
|
{Raw: encodeOrDie(a)},
|
||||||
{Raw: encodeOrDie(b)},
|
{Raw: encodeOrDie(b)},
|
||||||
|
@ -253,14 +253,14 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "v1.List in reverse",
|
name: "v1.List in reverse",
|
||||||
obj: &api.List{
|
obj: &corev1.List{
|
||||||
Items: []runtime.RawExtension{
|
Items: []runtime.RawExtension{
|
||||||
{Raw: encodeOrDie(c)},
|
{Raw: encodeOrDie(c)},
|
||||||
{Raw: encodeOrDie(b)},
|
{Raw: encodeOrDie(b)},
|
||||||
{Raw: encodeOrDie(a)},
|
{Raw: encodeOrDie(a)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sort: &api.List{
|
sort: &corev1.List{
|
||||||
Items: []runtime.RawExtension{
|
Items: []runtime.RawExtension{
|
||||||
{Raw: encodeOrDie(a)},
|
{Raw: encodeOrDie(a)},
|
||||||
{Raw: encodeOrDie(b)},
|
{Raw: encodeOrDie(b)},
|
||||||
|
@ -372,16 +372,16 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "model-invalid-fields",
|
name: "model-invalid-fields",
|
||||||
obj: &api.ReplicationControllerList{
|
obj: &corev1.ReplicationControllerList{
|
||||||
Items: []api.ReplicationController{
|
Items: []corev1.ReplicationController{
|
||||||
{
|
{
|
||||||
Status: api.ReplicationControllerStatus{},
|
Status: corev1.ReplicationControllerStatus{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Status: api.ReplicationControllerStatus{},
|
Status: corev1.ReplicationControllerStatus{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Status: api.ReplicationControllerStatus{},
|
Status: corev1.ReplicationControllerStatus{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -391,7 +391,7 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
sort := &SortingPrinter{SortField: tt.field, Decoder: legacyscheme.Codecs.UniversalDecoder()}
|
sort := &SortingPrinter{SortField: tt.field, Decoder: scheme.Codecs.UniversalDecoder()}
|
||||||
err := sort.sortObj(tt.obj)
|
err := sort.sortObj(tt.obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(tt.expectedErr) > 0 {
|
if len(tt.expectedErr) > 0 {
|
||||||
|
@ -415,8 +415,8 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
func TestRuntimeSortLess(t *testing.T) {
|
func TestRuntimeSortLess(t *testing.T) {
|
||||||
var testobj runtime.Object
|
var testobj runtime.Object
|
||||||
|
|
||||||
testobj = &api.PodList{
|
testobj = &corev1.PodList{
|
||||||
Items: []api.Pod{
|
Items: []corev1.Pod{
|
||||||
{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "b",
|
Name: "b",
|
||||||
|
|
Loading…
Reference in New Issue