本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/storage.List函數的典型用法代碼示例。如果您正苦於以下問題:Golang List函數的具體用法?Golang List怎麽用?Golang List使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了List函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: TestListPopulatedList
func TestListPopulatedList(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.ChangeIndex = 1
fakeEtcdClient.Data["/images"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{Value: runtime.EncodeOrDie(latest.Codec, &api.Image{ObjectMeta: kapi.ObjectMeta{Name: "foo"}})},
{Value: runtime.EncodeOrDie(latest.Codec, &api.Image{ObjectMeta: kapi.ObjectMeta{Name: "bar"}})},
},
},
},
}
storage := NewREST(helper)
list, err := storage.List(kapi.NewDefaultContext(), labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("Unexpected non-nil error: %#v", err)
}
images := list.(*api.ImageList)
if e, a := 2, len(images.Items); e != a {
t.Errorf("Expected %v, got %v", e, a)
}
}
示例3: TestListImageStreamsPopulatedList
func TestListImageStreamsPopulatedList(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage, _ := NewREST(helper, noDefaultRegistry, &fakeSubjectAccessReviewRegistry{})
fakeEtcdClient.Data["/imagestreams/default"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{Value: runtime.EncodeOrDie(latest.Codec, &api.ImageStream{ObjectMeta: kapi.ObjectMeta{Name: "foo"}})},
{Value: runtime.EncodeOrDie(latest.Codec, &api.ImageStream{ObjectMeta: kapi.ObjectMeta{Name: "bar"}})},
},
},
},
}
list, err := storage.List(kapi.NewDefaultContext(), labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("Unexpected non-nil error: %#v", err)
}
imageStreams := list.(*api.ImageStreamList)
if e, a := 2, len(imageStreams.Items); e != a {
t.Errorf("Expected %v, got %v", e, a)
}
}
示例4: 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)
}
}
示例5: TestListEmptyResourceQuotaList
func TestListEmptyResourceQuotaList(t *testing.T) {
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
fakeEtcdClient.ChangeIndex = 1
storage, _ := NewStorage(etcdStorage)
ctx := api.NewContext()
key := storage.Etcd.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{},
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
}
resourcequotas, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(resourcequotas.(*api.ResourceQuotaList).Items) != 0 {
t.Errorf("Unexpected non-zero resourcequota list: %#v", resourcequotas)
}
if resourcequotas.(*api.ResourceQuotaList).ResourceVersion != "1" {
t.Errorf("Unexpected resource version: %#v", resourcequotas)
}
}
示例6: TestEtcdListControllers
func TestEtcdListControllers(t *testing.T) {
storage, fakeClient := newStorage(t)
ctx := api.NewDefaultContext()
key := makeControllerListKey(ctx)
key = etcdtest.AddPrefix(key)
controller := validController
controller.Name = "bar"
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, &validController),
},
{
Value: runtime.EncodeOrDie(latest.Codec, &controller),
},
},
},
},
E: nil,
}
objList, err := storage.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
controllers, _ := objList.(*api.ReplicationControllerList)
if len(controllers.Items) != 2 || controllers.Items[0].Name != validController.Name || controllers.Items[1].Name != controller.Name {
t.Errorf("Unexpected controller list: %#v", controllers)
}
}
示例7: TestListError
func TestListError(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.Err = fmt.Errorf("test error")
storage := NewREST(helper)
images, err := storage.List(kapi.NewDefaultContext(), labels.Everything(), fields.Everything())
if err != fakeEtcdClient.Err {
t.Fatalf("Expected %#v, Got %#v", fakeEtcdClient.Err, err)
}
if images != nil {
t.Errorf("Unexpected non-nil image list: %#v", images)
}
}
示例8: TestListError
func TestListError(t *testing.T) {
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
fakeEtcdClient.Err = fmt.Errorf("test error")
storage := NewStorage(etcdStorage, nil).Pod
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
if err != fakeEtcdClient.Err {
t.Fatalf("Expected %#v, Got %#v", fakeEtcdClient.Err, err)
}
if pods != nil {
t.Errorf("Unexpected non-nil pod list: %#v", pods)
}
}
示例9: TestListImageStreamsError
func TestListImageStreamsError(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.Err = fmt.Errorf("foo")
storage, _ := NewREST(helper, noDefaultRegistry, &fakeSubjectAccessReviewRegistry{})
imageStreams, err := storage.List(kapi.NewDefaultContext(), nil, nil)
if err != fakeEtcdClient.Err {
t.Errorf("Expected %#v, Got %#v", fakeEtcdClient.Err, err)
}
if imageStreams != nil {
t.Errorf("Unexpected non-nil imageStreams list: %#v", imageStreams)
}
}
示例10: TestListPodList
func TestListPodList(t *testing.T) {
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
ctx := api.NewDefaultContext()
storage := NewStorage(etcdStorage, nil).Pod
key := storage.Etcd.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Pod{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Spec: api.PodSpec{NodeName: "machine"},
Status: api.PodStatus{Phase: api.PodRunning},
}),
},
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Pod{
ObjectMeta: api.ObjectMeta{Name: "bar"},
Spec: api.PodSpec{NodeName: "machine"},
}),
},
},
},
},
}
podsObj, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
pods := podsObj.(*api.PodList)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(pods.Items) != 2 {
t.Errorf("Unexpected pod list: %#v", pods)
}
if pods.Items[0].Name != "foo" || pods.Items[0].Status.Phase != api.PodRunning || pods.Items[0].Spec.NodeName != "machine" {
t.Errorf("Unexpected pod: %#v", pods.Items[0])
}
if pods.Items[1].Name != "bar" || pods.Items[1].Spec.NodeName != "machine" {
t.Errorf("Unexpected pod: %#v", pods.Items[1])
}
}
示例11: TestEtcdListControllersNotFound
func TestEtcdListControllersNotFound(t *testing.T) {
storage, fakeClient := newStorage(t)
ctx := api.NewDefaultContext()
key := makeControllerListKey(ctx)
key = etcdtest.AddPrefix(key)
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{},
E: tools.EtcdErrorNotFound,
}
objList, err := storage.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
controllers, _ := objList.(*api.ReplicationControllerList)
if len(controllers.Items) != 0 {
t.Errorf("Unexpected controller list: %#v", controllers)
}
}
示例12: TestListImageStreamsEmptyList
func TestListImageStreamsEmptyList(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.ChangeIndex = 1
fakeEtcdClient.Data["/imagestreams/default"] = tools.EtcdResponseWithError{
R: &etcd.Response{},
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
}
storage, _ := NewREST(helper, noDefaultRegistry, &fakeSubjectAccessReviewRegistry{})
imageStreams, err := storage.List(kapi.NewDefaultContext(), labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("Unexpected non-nil error: %#v", err)
}
if len(imageStreams.(*api.ImageStreamList).Items) != 0 {
t.Errorf("Unexpected non-zero imageStreams list: %#v", imageStreams)
}
if imageStreams.(*api.ImageStreamList).ResourceVersion != "1" {
t.Errorf("Unexpected resource version: %#v", imageStreams)
}
}
示例13: 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])
}
}
示例14: 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])
}
}
示例15: TestListEmptyNamespaceList
func TestListEmptyNamespaceList(t *testing.T) {
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
fakeEtcdClient.ChangeIndex = 1
key := etcdtest.AddPrefix("/namespaces")
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{},
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
}
storage, _, _ := NewStorage(etcdStorage)
namespaces, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if len(namespaces.(*api.NamespaceList).Items) != 0 {
t.Errorf("Unexpected non-zero namespace list: %#v", namespaces)
}
if namespaces.(*api.NamespaceList).ResourceVersion != "1" {
t.Errorf("Unexpected resource version: %#v", namespaces)
}
}