Skip to content

Commit

Permalink
Merge pull request kubernetes#78309 from liggitt/proto-fixtures
Browse files Browse the repository at this point in the history
Add json/protobuf/yaml fixtures
  • Loading branch information
k8s-ci-robot authored Jun 2, 2019
2 parents 71fe27e + fcea91c commit 4b4420f
Show file tree
Hide file tree
Showing 703 changed files with 99,780 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pkg/api/testing/serialization_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
)

func TestUniversalDeserializer(t *testing.T) {
expected := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test"}}
expected := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test"}, TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Pod"}}
d := legacyscheme.Codecs.UniversalDeserializer()
for _, mediaType := range []string{"application/json", "application/yaml", "application/vnd.kubernetes.protobuf"} {
info, ok := runtime.SerializerInfoForMediaType(legacyscheme.Codecs.SupportedMediaTypes(), mediaType)
Expand Down
3 changes: 1 addition & 2 deletions staging/src/k8s.io/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = ["roundtrip_test.go"],
data = glob(["testdata/**"]),
deps = [
"//staging/src/k8s.io/api/admission/v1beta1:go_default_library",
"//staging/src/k8s.io/api/admissionregistration/v1beta1:go_default_library",
Expand Down Expand Up @@ -38,9 +39,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/api/apitesting/fuzzer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/fuzzer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
],
Expand Down
56 changes: 11 additions & 45 deletions staging/src/k8s.io/api/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ import (
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
genericfuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
)

Expand Down Expand Up @@ -97,55 +95,23 @@ var groups = []runtime.SchemeBuilder{
}

func TestRoundTripExternalTypes(t *testing.T) {
scheme := runtime.NewScheme()
codecs := serializer.NewCodecFactory(scheme)
for _, builder := range groups {
scheme := runtime.NewScheme()
codecs := serializer.NewCodecFactory(scheme)

require.NoError(t, builder.AddToScheme(scheme))
seed := rand.Int63()
// I'm only using the generic fuzzer funcs, but at some point in time we might need to
// switch to specialized. For now we're happy with the current serialization test.
fuzzer := fuzzer.FuzzerFor(genericfuzzer.Funcs, rand.NewSource(seed), codecs)

roundtrip.RoundTripExternalTypes(t, scheme, codecs, fuzzer, nil)
}
}

func TestFailRoundTrip(t *testing.T) {
scheme := runtime.NewScheme()
codecs := serializer.NewCodecFactory(scheme)
groupVersion := schema.GroupVersion{Group: "broken", Version: "v1"}
builder := runtime.NewSchemeBuilder(func(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(groupVersion, &BrokenType{})
metav1.AddToGroupVersion(scheme, groupVersion)
return nil
})
require.NoError(t, builder.AddToScheme(scheme))
seed := rand.Int63()
// I'm only using the generic fuzzer funcs, but at some point in time we might need to
// switch to specialized. For now we're happy with the current serialization test.
fuzzer := fuzzer.FuzzerFor(genericfuzzer.Funcs, rand.NewSource(seed), codecs)
tmpT := new(testing.T)
roundtrip.RoundTripExternalTypes(tmpT, scheme, codecs, fuzzer, nil)
// It's very hacky way of making sure the DeepCopy is actually invoked inside RoundTripExternalTypes
// used in the other test. If for some reason this tests starts passing we need to fail b/c we're not testing
// the DeepCopy in the other method which we care so much about.
if !tmpT.Failed() {
t.Log("RoundTrip should've failed on DeepCopy but it did not!")
t.FailNow()
}
}

type BrokenType struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Field1 string `json:"field1,omitempty"`
Field2 string `json:"field2,omitempty"`
}

func (in *BrokenType) DeepCopy() *BrokenType {
return new(BrokenType)
roundtrip.RoundTripExternalTypes(t, scheme, codecs, fuzzer, nil)
}

func (in *BrokenType) DeepCopyObject() runtime.Object {
return in.DeepCopy()
func TestCompatibility(t *testing.T) {
scheme := runtime.NewScheme()
for _, builder := range groups {
require.NoError(t, builder.AddToScheme(scheme))
}
roundtrip.NewCompatibilityTestOptions(scheme).Complete(t).Run(t)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"request": {
"uid": "ő岅ȕHH壬%龺ǟ橸章蒪ʤǎ",
"kind": {
"group": "2",
"version": "3",
"kind": "4"
},
"resource": {
"group": "5",
"version": "6",
"resource": "7"
},
"subResource": "8",
"requestKind": {
"group": "9",
"version": "10",
"kind": "11"
},
"requestResource": {
"group": "12",
"version": "13",
"resource": "14"
},
"requestSubResource": "15",
"name": "16",
"namespace": "17",
"operation": "¡ıŵDz",
"userInfo": {
"username": "18",
"uid": "19",
"groups": [
"20"
],
"extra": {
"21": [
"22"
]
}
},
"object": {"apiVersion":"example.com/v1","kind":"CustomType","spec":{"replicas":1},"status":{"available":1}},
"oldObject": {"apiVersion":"example.com/v1","kind":"CustomType","spec":{"replicas":1},"status":{"available":1}},
"dryRun": false,
"options": {"apiVersion":"example.com/v1","kind":"CustomType","spec":{"replicas":1},"status":{"available":1}}
},
"response": {
"uid": "輂]¨\u0026桰]]æȌ殸2爟¼ªov鈶",
"allowed": false,
"status": {
"metadata": {
"selfLink": "(湗Ć]ʪƬ滈憴Uą飋ī",
"resourceVersion": "71208173751669476"
},
"status": "23",
"message": "24",
"reason": "Hr鯹)晿\u003co,c鮽ort昍řČ扷5Ɨ",
"details": {
"name": "25",
"group": "26",
"kind": "27",
"uid": "Ƣ6/ʕVŚ(ĿȊ甞",
"causes": [
{
"reason": "颋Dž",
"message": "28",
"field": "29"
}
],
"retryAfterSeconds": 1001983654
},
"code": 153738858
},
"patch": "fQ==",
"patchType": "-Ǐ忄*齧獚敆Ȏțê",
"auditAnnotations": {
"30": "31"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: admission.k8s.io/v1beta1
kind: AdmissionReview
request:
dryRun: false
kind:
group: "2"
kind: "4"
version: "3"
name: "16"
namespace: "17"
object:
apiVersion: example.com/v1
kind: CustomType
spec:
replicas: 1
status:
available: 1
oldObject:
apiVersion: example.com/v1
kind: CustomType
spec:
replicas: 1
status:
available: 1
operation: ¡ıŵDz
options:
apiVersion: example.com/v1
kind: CustomType
spec:
replicas: 1
status:
available: 1
requestKind:
group: "9"
kind: "11"
version: "10"
requestResource:
group: "12"
resource: "14"
version: "13"
requestSubResource: "15"
resource:
group: "5"
resource: "7"
version: "6"
subResource: "8"
uid: ő岅ȕHH壬%龺ǟ橸章蒪ʤǎ
userInfo:
extra:
"21":
- "22"
groups:
- "20"
uid: "19"
username: "18"
response:
allowed: false
auditAnnotations:
"30": "31"
patch: fQ==
patchType: -Ǐ忄*齧獚敆Ȏțê
status:
code: 153738858
details:
causes:
- field: "29"
message: "28"
reason: 颋Dž
group: "26"
kind: "27"
name: "25"
retryAfterSeconds: 1001983654
uid: Ƣ6/ʕVŚ(ĿȊ甞
message: "24"
metadata:
resourceVersion: "71208173751669476"
selfLink: (湗Ć]ʪƬ滈憴Uą飋ī
reason: Hr鯹)晿<o,c鮽ort昍řČ扷5Ɨ
status: "23"
uid: 輂]¨&桰]]æȌ殸2爟¼ªov鈶
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"kind": "MutatingWebhookConfiguration",
"apiVersion": "admissionregistration.k8s.io/v1beta1",
"metadata": {
"name": "2",
"generateName": "3",
"namespace": "4",
"selfLink": "5",
"uid": "ą飋īqJ枊a8衍`Ĩɘ.蘯6ċV夸e",
"resourceVersion": "16964250748386560239",
"generation": 8071137005907523419,
"creationTimestamp": null,
"deletionGracePeriodSeconds": -4955867275792137171,
"labels": {
"7": "8"
},
"annotations": {
"9": "10"
},
"ownerReferences": [
{
"apiVersion": "11",
"kind": "12",
"name": "13",
"uid": "Dz廔ȇ{sŊƏp",
"controller": false,
"blockOwnerDeletion": true
}
],
"finalizers": [
"14"
],
"clusterName": "15",
"managedFields": [
{
"manager": "16",
"operation": "鐊唊飙Ş-U圴÷a/ɔ}摁(湗Ć]",
"apiVersion": "17",
"fields": {"18":{"19":null}}
}
]
},
"webhooks": [
{
"name": "24",
"clientConfig": {
"url": "25",
"service": {
"namespace": "26",
"name": "27",
"path": "28",
"port": 2114329341
},
"caBundle": "RA=="
},
"rules": [
{
"operations": [
"ʕVŚ(ĿȊ甞谐颋DžSǡƏS$+½H牗"
],
"apiGroups": [
"29"
],
"apiVersions": [
"30"
],
"resources": [
"31"
],
"scope": "ȎțêɘIJ斬³;Ơ歿"
}
],
"failurePolicy": "狞夌碕ʂɭ",
"matchPolicy": "cP$Iņɖ橙9",
"namespaceSelector": {
"matchLabels": {
"MHLU..8._bQw.-dG6c-.6--_x.--0wmZk1_8.3": "U-_Bq.m_4"
},
"matchExpressions": [
{
"key": "p503---477-49p---o61---4fy--9---7--9-9s-0-u5lj2--10pq-0-7-9-2-0/fP81.-.9Vdx.TB_M-H_5_.t..bG0",
"operator": "In",
"values": [
"D07.a_.y_y_o0_5qN2_---_M.N_._a6.9bHjdH.-.5_.I8__n"
]
}
]
},
"objectSelector": {
"matchLabels": {
"81po6c-m6173y.390q-6-i2d020hj--a-8g--z-nt-b-6-17-58-n---5df19/H.__.h-J-M.9_T.q-o7.y-SQ.9A-F-.4--_vLW.jj-.5B.._.5_3-_4.3i": "i.Fg.Cs_.8-EA"
},
"matchExpressions": [
{
"key": "4m-s0833--52-9guv59s-3------6tv27r-m8w-6d/5w9-Wm_AO-l8VKLyHA_.-F_E2_QOuQ_8.-1_57__JR.N-1zL-4--6o-B",
"operator": "DoesNotExist"
}
]
},
"sideEffects": "ŴĿ",
"timeoutSeconds": 1525829664,
"admissionReviewVersions": [
"44"
],
"reinvocationPolicy": "ȉ彂"
}
]
}
Binary file not shown.
Loading

0 comments on commit 4b4420f

Please sign in to comment.