mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Refactor test objects to a separate package
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
kubectltesting "k8s.io/kubernetes/pkg/kubectl/testing"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
@@ -38,23 +39,12 @@ import (
|
||||
"github.com/ghodss/yaml"
|
||||
)
|
||||
|
||||
type testStruct struct {
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata,omitempty"`
|
||||
Key string `json:"Key"`
|
||||
Map map[string]int `json:"Map"`
|
||||
StringList []string `json:"StringList"`
|
||||
IntList []int `json:"IntList"`
|
||||
}
|
||||
|
||||
func (ts *testStruct) IsAnAPIObject() {}
|
||||
|
||||
func init() {
|
||||
api.Scheme.AddKnownTypes("", &testStruct{})
|
||||
api.Scheme.AddKnownTypes(testapi.Default.Version(), &testStruct{})
|
||||
api.Scheme.AddKnownTypes("", &kubectltesting.TestStruct{})
|
||||
api.Scheme.AddKnownTypes(testapi.Default.Version(), &kubectltesting.TestStruct{})
|
||||
}
|
||||
|
||||
var testData = testStruct{
|
||||
var testData = kubectltesting.TestStruct{
|
||||
Key: "testValue",
|
||||
Map: map[string]int{"TestSubkey": 1},
|
||||
StringList: []string{"a", "b", "c"},
|
||||
@@ -62,13 +52,13 @@ var testData = testStruct{
|
||||
}
|
||||
|
||||
func TestVersionedPrinter(t *testing.T) {
|
||||
original := &testStruct{Key: "value"}
|
||||
original := &kubectltesting.TestStruct{Key: "value"}
|
||||
p := NewVersionedPrinter(
|
||||
ResourcePrinterFunc(func(obj runtime.Object, w io.Writer) error {
|
||||
if obj == original {
|
||||
t.Fatalf("object should not be identical: %#v", obj)
|
||||
}
|
||||
if obj.(*testStruct).Key != "value" {
|
||||
if obj.(*kubectltesting.TestStruct).Key != "value" {
|
||||
t.Fatalf("object was not converted: %#v", obj)
|
||||
}
|
||||
return nil
|
||||
@@ -177,14 +167,14 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var poutput testStruct
|
||||
var poutput kubectltesting.TestStruct
|
||||
// Verify that given function runs without error.
|
||||
err = unmarshalFunc(buf.Bytes(), &poutput)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Use real decode function to undo the versioning process.
|
||||
poutput = testStruct{}
|
||||
poutput = kubectltesting.TestStruct{}
|
||||
err = runtime.YAMLDecoder(testapi.Default.Codec()).DecodeInto(buf.Bytes(), &poutput)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user