mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-23 02:26:52 +00:00
fix all Sting method not check nil in "k8s.io/apimachinery"
This commit is contained in:
parent
1f0371bb3f
commit
307278029c
@ -262,22 +262,22 @@ func TestValidateCustomResource(t *testing.T) {
|
|||||||
},
|
},
|
||||||
failingObjects: []failingObject{
|
failingObjects: []failingObject{
|
||||||
{object: map[string]interface{}{"field": true}, expectErrs: []string{
|
{object: map[string]interface{}{"field": true}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "boolean": field in body must be of type integer,string: "boolean"`,
|
`field: Invalid value: "boolean": field in body must be of type integer,string: "boolean"`,
|
||||||
`field: Invalid value: "boolean": field in body must be of type integer: "boolean"`,
|
`field: Invalid value: "boolean": field in body must be of type integer: "boolean"`,
|
||||||
}},
|
}},
|
||||||
{object: map[string]interface{}{"field": 1.2}, expectErrs: []string{
|
{object: map[string]interface{}{"field": 1.2}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "number": field in body must be of type integer,string: "number"`,
|
`field: Invalid value: "number": field in body must be of type integer,string: "number"`,
|
||||||
`field: Invalid value: "number": field in body must be of type integer: "number"`,
|
`field: Invalid value: "number": field in body must be of type integer: "number"`,
|
||||||
}},
|
}},
|
||||||
{object: map[string]interface{}{"field": map[string]interface{}{}}, expectErrs: []string{
|
{object: map[string]interface{}{"field": map[string]interface{}{}}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "object": field in body must be of type integer,string: "object"`,
|
`field: Invalid value: "object": field in body must be of type integer,string: "object"`,
|
||||||
`field: Invalid value: "object": field in body must be of type integer: "object"`,
|
`field: Invalid value: "object": field in body must be of type integer: "object"`,
|
||||||
}},
|
}},
|
||||||
{object: map[string]interface{}{"field": []interface{}{}}, expectErrs: []string{
|
{object: map[string]interface{}{"field": []interface{}{}}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "array": field in body must be of type integer,string: "array"`,
|
`field: Invalid value: "array": field in body must be of type integer,string: "array"`,
|
||||||
`field: Invalid value: "array": field in body must be of type integer: "array"`,
|
`field: Invalid value: "array": field in body must be of type integer: "array"`,
|
||||||
}},
|
}},
|
||||||
@ -308,26 +308,26 @@ func TestValidateCustomResource(t *testing.T) {
|
|||||||
},
|
},
|
||||||
failingObjects: []failingObject{
|
failingObjects: []failingObject{
|
||||||
{object: map[string]interface{}{"field": true}, expectErrs: []string{
|
{object: map[string]interface{}{"field": true}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
`<nil>: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "boolean": field in body must be of type integer,string: "boolean"`,
|
`field: Invalid value: "boolean": field in body must be of type integer,string: "boolean"`,
|
||||||
`field: Invalid value: "boolean": field in body must be of type integer: "boolean"`,
|
`field: Invalid value: "boolean": field in body must be of type integer: "boolean"`,
|
||||||
}},
|
}},
|
||||||
{object: map[string]interface{}{"field": 1.2}, expectErrs: []string{
|
{object: map[string]interface{}{"field": 1.2}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
`<nil>: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "number": field in body must be of type integer,string: "number"`,
|
`field: Invalid value: "number": field in body must be of type integer,string: "number"`,
|
||||||
`field: Invalid value: "number": field in body must be of type integer: "number"`,
|
`field: Invalid value: "number": field in body must be of type integer: "number"`,
|
||||||
}},
|
}},
|
||||||
{object: map[string]interface{}{"field": map[string]interface{}{}}, expectErrs: []string{
|
{object: map[string]interface{}{"field": map[string]interface{}{}}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
`<nil>: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "object": field in body must be of type integer,string: "object"`,
|
`field: Invalid value: "object": field in body must be of type integer,string: "object"`,
|
||||||
`field: Invalid value: "object": field in body must be of type integer: "object"`,
|
`field: Invalid value: "object": field in body must be of type integer: "object"`,
|
||||||
}},
|
}},
|
||||||
{object: map[string]interface{}{"field": []interface{}{}}, expectErrs: []string{
|
{object: map[string]interface{}{"field": []interface{}{}}, expectErrs: []string{
|
||||||
`: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
`<nil>: Invalid value: "": "field" must validate all the schemas (allOf). None validated`,
|
||||||
`: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
`<nil>: Invalid value: "": "field" must validate at least one schema (anyOf)`,
|
||||||
`field: Invalid value: "array": field in body must be of type integer,string: "array"`,
|
`field: Invalid value: "array": field in body must be of type integer,string: "array"`,
|
||||||
`field: Invalid value: "array": field in body must be of type integer: "array"`,
|
`field: Invalid value: "array": field in body must be of type integer: "array"`,
|
||||||
}},
|
}},
|
||||||
|
@ -65,6 +65,9 @@ type DefaultRESTMapper struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *DefaultRESTMapper) String() string {
|
func (m *DefaultRESTMapper) String() string {
|
||||||
|
if m == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
return fmt.Sprintf("DefaultRESTMapper{kindToPluralResource=%v}", m.kindToPluralResource)
|
return fmt.Sprintf("DefaultRESTMapper{kindToPluralResource=%v}", m.kindToPluralResource)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,6 +598,9 @@ const int64QuantityExpectedBytes = 18
|
|||||||
// String is an expensive operation and caching this result significantly reduces the cost of
|
// String is an expensive operation and caching this result significantly reduces the cost of
|
||||||
// normal parse / marshal operations on Quantity.
|
// normal parse / marshal operations on Quantity.
|
||||||
func (q *Quantity) String() string {
|
func (q *Quantity) String() string {
|
||||||
|
if q == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
if len(q.s) == 0 {
|
if len(q.s) == 0 {
|
||||||
result := make([]byte, 0, int64QuantityExpectedBytes)
|
result := make([]byte, 0, int64QuantityExpectedBytes)
|
||||||
number, suffix := q.CanonicalizeBytes(result)
|
number, suffix := q.CanonicalizeBytes(result)
|
||||||
|
@ -34,6 +34,9 @@ type GroupResource struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gr *GroupResource) String() string {
|
func (gr *GroupResource) String() string {
|
||||||
|
if gr == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
if len(gr.Group) == 0 {
|
if len(gr.Group) == 0 {
|
||||||
return gr.Resource
|
return gr.Resource
|
||||||
}
|
}
|
||||||
@ -51,6 +54,9 @@ type GroupVersionResource struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gvr *GroupVersionResource) String() string {
|
func (gvr *GroupVersionResource) String() string {
|
||||||
|
if gvr == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
return strings.Join([]string{gvr.Group, "/", gvr.Version, ", Resource=", gvr.Resource}, "")
|
return strings.Join([]string{gvr.Group, "/", gvr.Version, ", Resource=", gvr.Resource}, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +70,9 @@ type GroupKind struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gk *GroupKind) String() string {
|
func (gk *GroupKind) String() string {
|
||||||
|
if gk == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
if len(gk.Group) == 0 {
|
if len(gk.Group) == 0 {
|
||||||
return gk.Kind
|
return gk.Kind
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,9 @@ func (intstr *IntOrString) UnmarshalJSON(value []byte) error {
|
|||||||
|
|
||||||
// String returns the string value, or the Itoa of the int value.
|
// String returns the string value, or the Itoa of the int value.
|
||||||
func (intstr *IntOrString) String() string {
|
func (intstr *IntOrString) String() string {
|
||||||
|
if intstr == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
if intstr.Type == String {
|
if intstr.Type == String {
|
||||||
return intstr.StrVal
|
return intstr.StrVal
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,9 @@ func (p *Path) Key(key string) *Path {
|
|||||||
|
|
||||||
// String produces a string representation of the Path.
|
// String produces a string representation of the Path.
|
||||||
func (p *Path) String() string {
|
func (p *Path) String() string {
|
||||||
|
if p == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
// make a slice to iterate
|
// make a slice to iterate
|
||||||
elems := []*Path{}
|
elems := []*Path{}
|
||||||
for ; p != nil; p = p.parent {
|
for ; p != nil; p = p.parent {
|
||||||
|
@ -195,6 +195,9 @@ func (v *Version) WithBuildMetadata(buildMetadata string) *Version {
|
|||||||
// ParseGeneric, this will not include the trailing uninterpreted portion of the version
|
// ParseGeneric, this will not include the trailing uninterpreted portion of the version
|
||||||
// number.
|
// number.
|
||||||
func (v *Version) String() string {
|
func (v *Version) String() string {
|
||||||
|
if v == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
for i, comp := range v.components {
|
for i, comp := range v.components {
|
||||||
|
Loading…
Reference in New Issue
Block a user