Merge pull request #107971 from liggitt/kubelet-round-trip

Fix kubelet cri round trip test
This commit is contained in:
Kubernetes Prow Robot 2022-02-07 02:01:45 -08:00 committed by GitHub
commit a266805f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ package remote
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"regexp"
"strings" "strings"
"testing" "testing"
@ -81,8 +82,8 @@ func assertEqualTypes(t *testing.T, path []string, a, b reflect.Type) {
if aField.Name != bField.Name { if aField.Name != bField.Name {
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field name %d: %s %s", i, aField.Name, bField.Name)) fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field name %d: %s %s", i, aField.Name, bField.Name))
} }
if aField.Tag != bField.Tag { if aTag, bTag := stripEnum(aField.Tag), stripEnum(bField.Tag); aTag != bTag {
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field tag %d: %s %s", i, aField.Tag, bField.Tag)) fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field tag %d:\n%s\n%s\n", i, aTag, bTag))
} }
if aField.Offset != bField.Offset { if aField.Offset != bField.Offset {
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field offset %d: %v %v", i, aField.Offset, bField.Offset)) fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field offset %d: %v %v", i, aField.Offset, bField.Offset))
@ -99,17 +100,25 @@ func assertEqualTypes(t *testing.T, path []string, a, b reflect.Type) {
} }
case reflect.Ptr, reflect.Slice: case reflect.Ptr, reflect.Slice:
aElem := a.Elem() aElemType := a.Elem()
bElem := b.Elem() bElemType := b.Elem()
aElemType := reflect.TypeOf(aElem)
bElemType := reflect.TypeOf(bElem)
assertEqualTypes(t, path, aElemType, bElemType) assertEqualTypes(t, path, aElemType, bElemType)
case reflect.Int32:
if a.Kind() != b.Kind() {
fatalTypeError(t, path, a, b, "incompatible types")
}
default: default:
fatalTypeError(t, path, a, b, "unhandled kind") fatalTypeError(t, path, a, b, "unhandled kind")
} }
} }
// strip the enum value from the protobuf tag, since that doesn't impact the wire serialization and differs by package
func stripEnum(tagValue reflect.StructTag) reflect.StructTag {
return reflect.StructTag(regexp.MustCompile(",enum=[^,]+").ReplaceAllString(string(tagValue), ""))
}
func fatalTypeError(t *testing.T, path []string, a, b reflect.Type, message string) { func fatalTypeError(t *testing.T, path []string, a, b reflect.Type, message string) {
t.Helper() t.Helper()
t.Fatalf("%s: %s: %s %s", strings.Join(path, ""), message, a, b) t.Fatalf("%s: %s: %s %s", strings.Join(path, ""), message, a, b)