mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Use pkg/util/json Marshal and Unmarshal instead of 'encoding/json' to preserve numbers, rather than casting to float64 automatically.
This commit is contained in:
parent
68451f301b
commit
15c7e93f14
@ -20,6 +20,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime: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/schema:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/json:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/util/jsonpath:go_default_library",
|
"//staging/src/k8s.io/client-go/util/jsonpath:go_default_library",
|
||||||
"//vendor/sigs.k8s.io/yaml:go_default_library",
|
"//vendor/sigs.k8s.io/yaml:go_default_library",
|
||||||
],
|
],
|
||||||
|
@ -18,13 +18,13 @@ package printers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoTemplatePrinter is an implementation of ResourcePrinter which formats data with a Go Template.
|
// GoTemplatePrinter is an implementation of ResourcePrinter which formats data with a Go Template.
|
||||||
|
@ -52,6 +52,14 @@ func TestTemplate(t *testing.T) {
|
|||||||
return "a base64 decode error", matched
|
return "a base64 decode error", matched
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "template 'eq' should not throw error for numbers",
|
||||||
|
template: "{{ eq .count 1}}",
|
||||||
|
obj: &v1.Event{
|
||||||
|
Count: 1,
|
||||||
|
},
|
||||||
|
expectOut: "true",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range testCase {
|
for _, test := range testCase {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user