本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/runtime.NewScheme函数的典型用法代码示例。如果您正苦于以下问题:Golang NewScheme函数的具体用法?Golang NewScheme怎么用?Golang NewScheme使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewScheme函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestDeepCopyOfEmbeddedObject
// TestDeepCopyOfEmbeddedObject checks to make sure that EmbeddedObject's can be passed through DeepCopy with fidelity
func TestDeepCopyOfEmbeddedObject(t *testing.T) {
s := runtime.NewScheme()
s.AddKnownTypes("", &EmbeddedTest{})
s.AddKnownTypeWithName("v1test", "EmbeddedTest", &EmbeddedTestExternal{})
original := &EmbeddedTest{
ID: "outer",
Object: runtime.EmbeddedObject{
&EmbeddedTest{
ID: "inner",
},
},
}
originalData, err := s.EncodeToVersion(original, "v1test")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
t.Logf("originalRole = %v\n", string(originalData))
copyOfOriginal, err := conversion.DeepCopy(original)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
copiedData, err := s.EncodeToVersion(copyOfOriginal.(runtime.Object), "v1test")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
t.Logf("copyOfRole = %v\n", string(copiedData))
if !reflect.DeepEqual(original, copyOfOriginal) {
t.Errorf("expected \n%v\n, got \n%v", string(originalData), string(copiedData))
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:36,代码来源:embedded_test.go
示例2: newExternalScheme
func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName("", "Type", &internalType{})
scheme.AddKnownTypeWithName("unlikelyversion", "Type", &externalType{})
//This tests that kubectl will not confuse the external scheme with the internal scheme, even when they accidentally have versions of the same name.
scheme.AddKnownTypeWithName(testapi.Version(), "Type", &ExternalType2{})
codec := runtime.CodecFor(scheme, "unlikelyversion")
validVersion := testapi.Version()
mapper := meta.NewDefaultRESTMapper([]string{"unlikelyversion", validVersion}, func(version string) (*meta.VersionInterfaces, bool) {
return &meta.VersionInterfaces{
Codec: runtime.CodecFor(scheme, version),
ObjectConvertor: scheme,
MetadataAccessor: meta.NewAccessor(),
}, (version == validVersion || version == "unlikelyversion")
})
for _, version := range []string{"unlikelyversion", validVersion} {
for kind := range scheme.KnownTypes(version) {
mixedCase := false
scope := meta.RESTScopeNamespace
mapper.Add(scope, kind, version, mixedCase)
}
}
return scheme, mapper, codec
}
开发者ID:EricCheung3,项目名称:kubernetes,代码行数:26,代码来源:cmd_test.go
示例3: TestExternalToInternalMapping
func TestExternalToInternalMapping(t *testing.T) {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName("", "OptionalExtensionType", &InternalOptionalExtensionType{})
scheme.AddKnownTypeWithName("testExternal", "OptionalExtensionType", &ExternalOptionalExtensionType{})
table := []struct {
obj runtime.Object
encoded string
}{
{
&InternalOptionalExtensionType{Extension: runtime.EmbeddedObject{nil}},
`{"kind":"OptionalExtensionType","apiVersion":"testExternal"}`,
},
}
for _, item := range table {
gotDecoded, err := scheme.Decode([]byte(item.encoded))
if err != nil {
t.Errorf("unexpected error '%v' (%v)", err, item.encoded)
} else if e, a := item.obj, gotDecoded; !reflect.DeepEqual(e, a) {
var eEx, aEx runtime.Object
if obj, ok := e.(*InternalOptionalExtensionType); ok {
eEx = obj.Extension.Object
}
if obj, ok := a.(*InternalOptionalExtensionType); ok {
aEx = obj.Extension.Object
}
t.Errorf("expected %#v, got %#v (%#v, %#v)", e, a, eEx, aEx)
}
}
}
开发者ID:eghobo,项目名称:kubedash,代码行数:31,代码来源:scheme_test.go
示例4: TestRESTMapperRESTMapping
func TestRESTMapperRESTMapping(t *testing.T) {
testCases := []struct {
Kind string
APIVersions []string
MixedCase bool
DefaultVersions []string
Resource string
Version string
Err bool
}{
{Kind: "Unknown", Err: true},
{Kind: "InternalObject", Err: true},
{DefaultVersions: []string{"test"}, Kind: "Unknown", Err: true},
{DefaultVersions: []string{"test"}, Kind: "InternalObject", APIVersions: []string{"test"}, Resource: "internalobjects"},
{DefaultVersions: []string{"test"}, Kind: "InternalObject", APIVersions: []string{"test"}, Resource: "internalobjects"},
{DefaultVersions: []string{"test"}, Kind: "InternalObject", APIVersions: []string{"test"}, Resource: "internalobjects"},
{DefaultVersions: []string{"test"}, Kind: "InternalObject", APIVersions: []string{}, Resource: "internalobjects", Version: "test"},
{DefaultVersions: []string{"test"}, Kind: "InternalObject", APIVersions: []string{"test"}, Resource: "internalobjects"},
{DefaultVersions: []string{"test"}, Kind: "InternalObject", APIVersions: []string{"test"}, MixedCase: true, Resource: "internalObjects"},
// TODO: add test for a resource that exists in one version but not another
}
for i, testCase := range testCases {
mapper := NewDefaultRESTMapper(testCase.DefaultVersions, fakeInterfaces)
scheme := runtime.NewScheme()
scheme.AddKnownTypes("test", &InternalObject{})
mapper.Add(scheme, testCase.MixedCase, "test")
mapping, err := mapper.RESTMapping(testCase.Kind, testCase.APIVersions...)
hasErr := err != nil
if hasErr != testCase.Err {
t.Errorf("%d: unexpected error behavior %t: %v", i, testCase.Err, err)
}
if hasErr {
continue
}
if mapping.Resource != testCase.Resource {
t.Errorf("%d: unexpected resource: %#v", i, mapping)
}
version := testCase.Version
if version == "" {
version = testCase.APIVersions[0]
}
if mapping.APIVersion != version {
t.Errorf("%d: unexpected version: %#v", i, mapping)
}
if mapping.Codec == nil || mapping.MetadataAccessor == nil || mapping.ObjectConvertor == nil {
t.Errorf("%d: missing codec and accessor: %#v", i, mapping)
}
}
}
开发者ID:nhr,项目名称:kubernetes,代码行数:57,代码来源:restmapper_test.go
示例5: TestEmbeddedObject
func TestEmbeddedObject(t *testing.T) {
s := runtime.NewScheme()
s.AddKnownTypes("", &EmbeddedTest{})
s.AddKnownTypeWithName("v1test", "EmbeddedTest", &EmbeddedTestExternal{})
outer := &EmbeddedTest{
ID: "outer",
Object: runtime.EmbeddedObject{
&EmbeddedTest{
ID: "inner",
},
},
}
wire, err := s.EncodeToVersion(outer, "v1test")
if err != nil {
t.Fatalf("Unexpected encode error '%v'", err)
}
t.Logf("Wire format is:\n%v\n", string(wire))
decoded, err := s.Decode(wire)
if err != nil {
t.Fatalf("Unexpected decode error %v", err)
}
if e, a := outer, decoded; !reflect.DeepEqual(e, a) {
t.Errorf("Expected: %#v but got %#v", e, a)
}
// test JSON decoding of the external object, which should preserve
// raw bytes
var externalViaJSON EmbeddedTestExternal
err = json.Unmarshal(wire, &externalViaJSON)
if err != nil {
t.Fatalf("Unexpected decode error %v", err)
}
if externalViaJSON.Kind == "" || externalViaJSON.APIVersion == "" || externalViaJSON.ID != "outer" {
t.Errorf("Expected objects to have type info set, got %#v", externalViaJSON)
}
if !reflect.DeepEqual(externalViaJSON.EmptyObject.RawJSON, []byte("null")) || len(externalViaJSON.Object.RawJSON) == 0 {
t.Errorf("Expected deserialization of nested objects into bytes, got %#v", externalViaJSON)
}
// test JSON decoding, too, since Decode uses yaml unmarshalling.
// Generic Unmarshalling of JSON cannot load the nested objects because there is
// no default schema set. Consumers wishing to get direct JSON decoding must use
// the external representation
var decodedViaJSON EmbeddedTest
err = json.Unmarshal(wire, &decodedViaJSON)
if err != nil {
t.Fatalf("Unexpected decode error %v", err)
}
if a := decodedViaJSON; a.Object.Object != nil || a.EmptyObject.Object != nil {
t.Errorf("Expected embedded objects to be nil: %#v", a)
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:57,代码来源:embedded_test.go
示例6: TestDecodeEmptyRawExtensionAsObject
func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
s := runtime.NewScheme()
s.AddKnownTypes("", &ObjectTest{})
s.AddKnownTypeWithName("v1test", "ObjectTest", &ObjectTestExternal{})
_, err := s.Decode([]byte(`{"kind":"ObjectTest","apiVersion":"v1test","items":[{}]}`))
if err == nil {
t.Fatalf("unexpected non-error")
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:10,代码来源:embedded_test.go
示例7: TestRESTMapperRESTMappingSelectsVersion
func TestRESTMapperRESTMappingSelectsVersion(t *testing.T) {
mapper := NewDefaultRESTMapper([]string{"test1", "test2"}, fakeInterfaces)
scheme := runtime.NewScheme()
scheme.AddKnownTypes("test1", &InternalObject{})
scheme.AddKnownTypeWithName("test2", "OtherObject", &InternalObject{})
scheme.AddKnownTypeWithName("test3", "OtherObject", &InternalObject{})
mapper.Add(scheme, false, "test1", "test2")
// pick default matching object kind based on search order
mapping, err := mapper.RESTMapping("OtherObject")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if mapping.Resource != "otherobjects" || mapping.APIVersion != "test2" {
t.Errorf("unexpected mapping: %#v", mapping)
}
mapping, err = mapper.RESTMapping("InternalObject")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if mapping.Resource != "internalobjects" || mapping.APIVersion != "test1" {
t.Errorf("unexpected mapping: %#v", mapping)
}
// mismatch of version
mapping, err = mapper.RESTMapping("InternalObject", "test2")
if err == nil {
t.Errorf("unexpected non-error")
}
mapping, err = mapper.RESTMapping("OtherObject", "test1")
if err == nil {
t.Errorf("unexpected non-error")
}
// not in the search versions
mapping, err = mapper.RESTMapping("OtherObject", "test3")
if err == nil {
t.Errorf("unexpected non-error")
}
// explicit search order
mapping, err = mapper.RESTMapping("OtherObject", "test3", "test1")
if err == nil {
t.Errorf("unexpected non-error")
}
mapping, err = mapper.RESTMapping("OtherObject", "test3", "test2")
if err != nil {
t.Fatalf("unexpected non-error")
}
if mapping.Resource != "otherobjects" || mapping.APIVersion != "test2" {
t.Errorf("unexpected mapping: %#v", mapping)
}
}
开发者ID:nhr,项目名称:kubernetes,代码行数:55,代码来源:restmapper_test.go
示例8: TestStringMapConversion
func TestStringMapConversion(t *testing.T) {
scheme := runtime.NewScheme()
scheme.Log(t)
scheme.AddKnownTypeWithName("", "Complex", &InternalComplex{})
scheme.AddKnownTypeWithName("external", "Complex", &ExternalComplex{})
testCases := map[string]struct {
input map[string][]string
errFn func(error) bool
expected runtime.Object
}{
"ignores omitempty": {
input: map[string][]string{
"String": {"not_used"},
"string": {"value"},
"int": {"1"},
"Integer64": {"2"},
},
expected: &ExternalComplex{String: "value", Integer: 1},
},
"returns error on bad int": {
input: map[string][]string{
"int": {"a"},
},
errFn: func(err error) bool { return err != nil },
expected: &ExternalComplex{},
},
"parses int64": {
input: map[string][]string{
"Int64": {"-1"},
},
expected: &ExternalComplex{Int64: -1},
},
"returns error on bad int64": {
input: map[string][]string{
"Int64": {"a"},
},
errFn: func(err error) bool { return err != nil },
expected: &ExternalComplex{},
},
}
for k, tc := range testCases {
out := &ExternalComplex{}
if err := scheme.Convert(&tc.input, out); (tc.errFn == nil && err != nil) || (tc.errFn != nil && !tc.errFn(err)) {
t.Errorf("%s: unexpected error: %v", k, err)
continue
} else if err != nil {
continue
}
if !reflect.DeepEqual(out, tc.expected) {
t.Errorf("%s: unexpected output: %#v", k, out)
}
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:55,代码来源:conversion_test.go
示例9: TestRESTMapperReportsErrorOnBadVersion
func TestRESTMapperReportsErrorOnBadVersion(t *testing.T) {
mapper := NewDefaultRESTMapper([]string{"test1", "test2"}, unmatchedVersionInterfaces)
scheme := runtime.NewScheme()
scheme.AddKnownTypes("test1", &InternalObject{})
mapper.Add(scheme, false, "test1")
_, err := mapper.RESTMapping("InternalObject", "test1")
if err == nil {
t.Errorf("unexpected non-error")
}
}
开发者ID:nhr,项目名称:kubernetes,代码行数:11,代码来源:restmapper_test.go
示例10: init
func init() {
scheme = runtime.NewScheme()
scheme.AddKnownTypes("", &TestResource{})
scheme.AddKnownTypes(testapi.Version(), &TestResource{})
codec = runtime.CodecFor(scheme, testapi.Version())
scheme.AddConversionFuncs(
func(in *TestResource, out *TestResource, s conversion.Scope) error {
*out = *in
return nil
},
)
}
开发者ID:mbforbes,项目名称:kubernetes,代码行数:12,代码来源:etcd_helper_test.go
示例11: TestInvalidObjectValueKind
func TestInvalidObjectValueKind(t *testing.T) {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName("", "Simple", &InternalSimple{})
embedded := &runtime.EmbeddedObject{}
switch obj := embedded.Object.(type) {
default:
_, _, err := scheme.ObjectVersionAndKind(obj)
if err == nil {
t.Errorf("Expected error on invalid kind")
}
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:13,代码来源:scheme_test.go
示例12: TestBadJSONRejection
func TestBadJSONRejection(t *testing.T) {
scheme := runtime.NewScheme()
badJSONMissingKind := []byte(`{ }`)
if _, err := scheme.Decode(badJSONMissingKind); err == nil {
t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind)
}
badJSONUnknownType := []byte(`{"kind": "bar"}`)
if _, err1 := scheme.Decode(badJSONUnknownType); err1 == nil {
t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType)
}
/*badJSONKindMismatch := []byte(`{"kind": "Pod"}`)
if err2 := DecodeInto(badJSONKindMismatch, &Minion{}); err2 == nil {
t.Errorf("Kind is set but doesn't match the object type: %s", badJSONKindMismatch)
}*/
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:15,代码来源:scheme_test.go
示例13: TestExtensionMapping
func TestExtensionMapping(t *testing.T) {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName("", "ExtensionType", &InternalExtensionType{})
scheme.AddKnownTypeWithName("", "A", &ExtensionA{})
scheme.AddKnownTypeWithName("", "B", &ExtensionB{})
scheme.AddKnownTypeWithName("testExternal", "ExtensionType", &ExternalExtensionType{})
scheme.AddKnownTypeWithName("testExternal", "A", &ExtensionA{})
scheme.AddKnownTypeWithName("testExternal", "B", &ExtensionB{})
table := []struct {
obj runtime.Object
encoded string
}{
{
&InternalExtensionType{Extension: runtime.EmbeddedObject{&ExtensionA{TestString: "foo"}}},
`{"kind":"ExtensionType","apiVersion":"testExternal","extension":{"kind":"A","testString":"foo"}}`,
}, {
&InternalExtensionType{Extension: runtime.EmbeddedObject{&ExtensionB{TestString: "bar"}}},
`{"kind":"ExtensionType","apiVersion":"testExternal","extension":{"kind":"B","testString":"bar"}}`,
}, {
&InternalExtensionType{Extension: runtime.EmbeddedObject{nil}},
`{"kind":"ExtensionType","apiVersion":"testExternal","extension":null}`,
},
}
for _, item := range table {
gotEncoded, err := scheme.EncodeToVersion(item.obj, "testExternal")
if err != nil {
t.Errorf("unexpected error '%v' (%#v)", err, item.obj)
} else if e, a := item.encoded, string(gotEncoded); e != a {
t.Errorf("expected %v, got %v", e, a)
}
gotDecoded, err := scheme.Decode([]byte(item.encoded))
if err != nil {
t.Errorf("unexpected error '%v' (%v)", err, item.encoded)
} else if e, a := item.obj, gotDecoded; !reflect.DeepEqual(e, a) {
var eEx, aEx runtime.Object
if obj, ok := e.(*InternalExtensionType); ok {
eEx = obj.Extension.Object
}
if obj, ok := a.(*InternalExtensionType); ok {
aEx = obj.Extension.Object
}
t.Errorf("expected %#v, got %#v (%#v, %#v)", e, a, eEx, aEx)
}
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:48,代码来源:scheme_test.go
示例14: newExternalScheme
func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName("", "Type", &internalType{})
scheme.AddKnownTypeWithName("unlikelyversion", "Type", &externalType{})
codec := runtime.CodecFor(scheme, "unlikelyversion")
mapper := meta.NewDefaultRESTMapper([]string{"unlikelyversion"}, func(version string) (*meta.VersionInterfaces, bool) {
return &meta.VersionInterfaces{
Codec: codec,
ObjectConvertor: scheme,
MetadataAccessor: meta.NewAccessor(),
}, (version == "unlikelyversion")
})
mapper.Add(scheme, false, "unlikelyversion")
return scheme, mapper, codec
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:17,代码来源:cmd_test.go
示例15: TestArrayOfRuntimeObject
func TestArrayOfRuntimeObject(t *testing.T) {
s := runtime.NewScheme()
s.AddKnownTypes("", &EmbeddedTest{})
s.AddKnownTypeWithName("v1test", "EmbeddedTest", &EmbeddedTestExternal{})
s.AddKnownTypes("", &ObjectTest{})
s.AddKnownTypeWithName("v1test", "ObjectTest", &ObjectTestExternal{})
internal := &ObjectTest{
Items: []runtime.Object{
&EmbeddedTest{ID: "foo"},
&EmbeddedTest{ID: "bar"},
// TODO: until YAML is removed, this JSON must be in ascending key order to ensure consistent roundtrip serialization
&runtime.Unknown{RawJSON: []byte(`{"apiVersion":"unknown","foo":"bar","kind":"OtherTest"}`)},
&ObjectTest{
Items: []runtime.Object{
&EmbeddedTest{ID: "baz"},
},
},
},
}
wire, err := s.EncodeToVersion(internal, "v1test")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
t.Logf("Wire format is:\n%s\n", string(wire))
obj := &ObjectTestExternal{}
if err := json.Unmarshal(wire, obj); err != nil {
t.Fatalf("unexpected error: %v", err)
}
t.Logf("exact wire is: %#v", string(obj.Items[0].RawJSON))
decoded, err := s.Decode(wire)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
internal.Items[2].(*runtime.Unknown).Kind = "OtherTest"
internal.Items[2].(*runtime.Unknown).APIVersion = "unknown"
if e, a := internal, decoded; !reflect.DeepEqual(e, a) {
t.Log(string(decoded.(*ObjectTest).Items[2].(*runtime.Unknown).RawJSON))
t.Errorf("mismatched decoded: %s", util.ObjectDiff(e, a))
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:44,代码来源:embedded_test.go
示例16: TestEncode
func TestEncode(t *testing.T) {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName("", "Simple", &InternalSimple{})
scheme.AddKnownTypeWithName("externalVersion", "Simple", &ExternalSimple{})
codec := runtime.CodecFor(scheme, "externalVersion")
test := &InternalSimple{
TestString: "I'm the same",
}
obj := runtime.Object(test)
data, err := codec.Encode(obj)
obj2, err2 := codec.Decode(data)
if err != nil || err2 != nil {
t.Fatalf("Failure: '%v' '%v'", err, err2)
}
if _, ok := obj2.(*InternalSimple); !ok {
t.Fatalf("Got wrong type")
}
if !reflect.DeepEqual(obj2, test) {
t.Errorf("Expected:\n %#v,\n Got:\n %#v", &test, obj2)
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:21,代码来源:scheme_test.go
示例17: TestDecodeEmptyRawExtensionAsObject
func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
s := runtime.NewScheme()
s.AddKnownTypes("", &ObjectTest{})
s.AddKnownTypeWithName("v1test", "ObjectTest", &ObjectTestExternal{})
obj, err := s.Decode([]byte(`{"kind":"ObjectTest","apiVersion":"v1test","items":[{}]}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
test := obj.(*ObjectTest)
if unk, ok := test.Items[0].(*runtime.Unknown); !ok || unk.Kind != "" || unk.APIVersion != "" || string(unk.RawJSON) != "{}" {
t.Fatalf("unexpected object: %#v", test.Items[0])
}
obj, err = s.Decode([]byte(`{"kind":"ObjectTest","apiVersion":"v1test","items":[{"kind":"Other","apiVersion":"v1"}]}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
test = obj.(*ObjectTest)
if unk, ok := test.Items[0].(*runtime.Unknown); !ok || unk.Kind != "Other" || unk.APIVersion != "v1" || string(unk.RawJSON) != `{"kind":"Other","apiVersion":"v1"}` {
t.Fatalf("unexpected object: %#v", test.Items[0])
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:23,代码来源:embedded_test.go
示例18: newExternalScheme
func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName("", "Type", &internalType{})
scheme.AddKnownTypeWithName("unlikelyversion", "Type", &externalType{})
codec := runtime.CodecFor(scheme, "unlikelyversion")
mapper := meta.NewDefaultRESTMapper([]string{"unlikelyversion"}, func(version string) (*meta.VersionInterfaces, bool) {
return &meta.VersionInterfaces{
Codec: codec,
ObjectConvertor: scheme,
MetadataAccessor: meta.NewAccessor(),
}, (version == "unlikelyversion")
})
for _, version := range []string{"unlikelyversion"} {
for kind := range scheme.KnownTypes(version) {
mixedCase := false
scope := meta.RESTScopeNamespace
mapper.Add(scope, kind, version, mixedCase)
}
}
return scheme, mapper, codec
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:23,代码来源:cmd_test.go
示例19: TestRESTMapperVersionAndKindForResource
func TestRESTMapperVersionAndKindForResource(t *testing.T) {
testCases := []struct {
Resource string
Kind, APIVersion string
MixedCase bool
Err bool
}{
{Resource: "internalobjec", Err: true},
{Resource: "internalObjec", Err: true},
{Resource: "internalobject", Kind: "InternalObject", APIVersion: "test"},
{Resource: "internalobjects", Kind: "InternalObject", APIVersion: "test"},
{Resource: "internalobject", MixedCase: true, Kind: "InternalObject", APIVersion: "test"},
{Resource: "internalobjects", MixedCase: true, Kind: "InternalObject", APIVersion: "test"},
{Resource: "internalObject", MixedCase: true, Kind: "InternalObject", APIVersion: "test"},
{Resource: "internalObjects", MixedCase: true, Kind: "InternalObject", APIVersion: "test"},
}
for i, testCase := range testCases {
mapper := NewDefaultRESTMapper([]string{"test"}, fakeInterfaces)
scheme := runtime.NewScheme()
scheme.AddKnownTypes("test", &InternalObject{})
mapper.Add(scheme, testCase.MixedCase, "test")
v, k, err := mapper.VersionAndKindForResource(testCase.Resource)
hasErr := err != nil
if hasErr != testCase.Err {
t.Errorf("%d: unexpected error behavior %t: %v", i, testCase.Err, err)
continue
}
if v != testCase.APIVersion || k != testCase.Kind {
t.Errorf("%d: unexpected version and kind: %s %s", i, v, k)
}
}
}
开发者ID:nhr,项目名称:kubernetes,代码行数:36,代码来源:restmapper_test.go
示例20:
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package runtime_test
import (
"encoding/json"
"reflect"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
var scheme = runtime.NewScheme()
var Codec = runtime.CodecFor(scheme, "v1test")
type EmbeddedTest struct {
runtime.TypeMeta `yaml:",inline" json:",inline"`
ID string `yaml:"id,omitempty" json:"id,omitempty"`
Object runtime.EmbeddedObject `yaml:"object,omitempty" json:"object,omitempty"`
EmptyObject runtime.EmbeddedObject `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"`
}
type EmbeddedTestExternal struct {
runtime.TypeMeta `yaml:",inline" json:",inline"`
ID string `yaml:"id,omitempty" json:"id,omitempty"`
Object runtime.RawExtension `yaml:"object,omitempty" json:"object,omitempty"`
EmptyObject runtime.RawExtension `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"`
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:31,代码来源:embedded_test.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/runtime.NewScheme函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论