本文整理匯總了Golang中k8s/io/kubernetes/pkg/storage.KeyRootFunc函數的典型用法代碼示例。如果您正苦於以下問題:Golang KeyRootFunc函數的具體用法?Golang KeyRootFunc怎麽用?Golang KeyRootFunc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了KeyRootFunc函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestEtcdListPersistentVolumes
func TestEtcdListPersistentVolumes(t *testing.T) {
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
key := storage.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, validNewPersistentVolume("foo")),
},
{
Value: runtime.EncodeOrDie(latest.Codec, validNewPersistentVolume("bar")),
},
},
},
},
E: nil,
}
pvObj, err := storage.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
pvs := pvObj.(*api.PersistentVolumeList)
if len(pvs.Items) != 2 || pvs.Items[0].Name != "foo" || pvs.Items[1].Name != "bar" {
t.Errorf("Unexpected persistentVolume list: %#v", pvs)
}
}
示例2: TestEtcdListNodes
func TestEtcdListNodes(t *testing.T) {
ctx := api.NewContext()
storage, fakeClient := newStorage(t)
key := storage.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Node{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}),
},
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Node{
ObjectMeta: api.ObjectMeta{Name: "bar"},
}),
},
},
},
},
E: nil,
}
nodesObj, err := storage.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
nodes := nodesObj.(*api.NodeList)
if len(nodes.Items) != 2 || nodes.Items[0].Name != "foo" || nodes.Items[1].Name != "bar" {
t.Errorf("Unexpected nodes list: %#v", nodes)
}
}
示例3: TestEtcdListPersistentVolumes
func TestEtcdListPersistentVolumes(t *testing.T) {
storage, _, fakeClient, _ := newStorage(t)
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
persistentVolume := validNewPersistentVolume("foo")
test.TestList(
persistentVolume,
func(objects []runtime.Object) []runtime.Object {
return registrytest.SetObjectsForKey(fakeClient, key, objects)
},
func(resourceVersion uint64) {
registrytest.SetResourceVersion(fakeClient, resourceVersion)
})
}
示例4: TestEtcdListEndpoints
func TestEtcdListEndpoints(t *testing.T) {
storage, fakeClient := newStorage(t)
test := resttest.New(t, storage, fakeClient.SetError)
endpoints := validNewEndpoints()
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
test.TestList(
endpoints,
func(objects []runtime.Object) []runtime.Object {
return registrytest.SetObjectsForKey(fakeClient, key, objects)
},
func(resourceVersion uint64) {
registrytest.SetResourceVersion(fakeClient, resourceVersion)
})
}
示例5: TestList
func TestList(t *testing.T) {
storage, fakeEtcdClient, _ := newStorage(t)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
autoscaler := validNewHorizontalPodAutoscaler("foo")
test.TestList(
autoscaler,
func(objects []runtime.Object) []runtime.Object {
return registrytest.SetObjectsForKey(fakeEtcdClient, key, objects)
},
func(resourceVersion uint64) {
registrytest.SetResourceVersion(fakeEtcdClient, resourceVersion)
})
}
示例6: TestListPersistentVolumesList
func TestListPersistentVolumesList(t *testing.T) {
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
fakeClient.ChangeIndex = 1
key := storage.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, &api.PersistentVolume{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}),
},
{
Value: runtime.EncodeOrDie(latest.Codec, &api.PersistentVolume{
ObjectMeta: api.ObjectMeta{Name: "bar"},
}),
},
},
},
},
}
persistentVolumeObj, err := storage.List(ctx, labels.Everything(), fields.Everything())
persistentVolumeList := persistentVolumeObj.(*api.PersistentVolumeList)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(persistentVolumeList.Items) != 2 {
t.Errorf("Unexpected persistentVolume list: %#v", persistentVolumeList)
}
if persistentVolumeList.Items[0].Name != "foo" {
t.Errorf("Unexpected persistentVolume: %#v", persistentVolumeList.Items[0])
}
if persistentVolumeList.Items[1].Name != "bar" {
t.Errorf("Unexpected persistentVolume: %#v", persistentVolumeList.Items[1])
}
}
示例7: TestListEndpointsList
func TestListEndpointsList(t *testing.T) {
ctx := api.NewDefaultContext()
storage, fakeClient := newStorage(t)
fakeClient.ChangeIndex = 1
key := storage.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}),
},
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{
ObjectMeta: api.ObjectMeta{Name: "bar"},
}),
},
},
},
},
}
endpointsObj, err := storage.List(ctx, labels.Everything(), fields.Everything())
endpoints := endpointsObj.(*api.EndpointsList)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(endpoints.Items) != 2 {
t.Errorf("Unexpected endpoints list: %#v", endpoints)
}
if endpoints.Items[0].Name != "foo" {
t.Errorf("Unexpected endpoints: %#v", endpoints.Items[0])
}
if endpoints.Items[1].Name != "bar" {
t.Errorf("Unexpected endpoints: %#v", endpoints.Items[1])
}
}
示例8: TestEtcdListEndpoints
func TestEtcdListEndpoints(t *testing.T) {
ctx := api.NewDefaultContext()
storage, fakeClient := newStorage(t)
key := storage.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Subsets: []api.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Port: 8345, Protocol: "TCP"}},
}},
}),
},
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{
ObjectMeta: api.ObjectMeta{Name: "bar"},
}),
},
},
},
},
E: nil,
}
endpointsObj, err := storage.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
endpoints := endpointsObj.(*api.EndpointsList)
if len(endpoints.Items) != 2 || endpoints.Items[0].Name != "foo" || endpoints.Items[1].Name != "bar" {
t.Errorf("Unexpected endpoints list: %#v", endpoints)
}
}
示例9: TestListEmptyPersistentVolumesList
func TestListEmptyPersistentVolumesList(t *testing.T) {
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
fakeClient.ChangeIndex = 1
key := storage.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{},
E: fakeClient.NewError(tools.EtcdErrorCodeNotFound),
}
persistentVolume, err := storage.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(persistentVolume.(*api.PersistentVolumeList).Items) != 0 {
t.Errorf("Unexpected non-zero pod list: %#v", persistentVolume)
}
if persistentVolume.(*api.PersistentVolumeList).ResourceVersion != "1" {
t.Errorf("Unexpected resource version: %#v", persistentVolume)
}
}