예제 #1
0
func testObjectIterator(t *testing.T, bkt *BucketHandle, objects []string) {
	ctx := context.Background()
	// Collect the list of items we expect: ObjectAttrs in lexical order by name.
	names := make([]string, len(objects))
	copy(names, objects)
	sort.Strings(names)
	var attrs []*ObjectAttrs
	for _, name := range names {
		attr, err := bkt.Object(name).Attrs(ctx)
		if err != nil {
			t.Errorf("Object(%q).Attrs: %v", name, err)
			return
		}
		attrs = append(attrs, attr)
	}

	it := bkt.Objects(ctx, &Query{Prefix: "obj"})
	msg, ok := testutil.TestIteratorNext(attrs, Done, func() (interface{}, error) { return it.Next() })
	if !ok {
		t.Errorf("ObjectIterator.Next: %s", msg)
	}

	// TODO(jba): test pagination.
	// TODO(jba): test query.Delimiter != ""
}
예제 #2
0
func TestListMetrics(t *testing.T) {
	ctx := context.Background()

	var metrics []*Metric
	for i := 0; i < 10; i++ {
		metrics = append(metrics, &Metric{
			ID:          ltesting.UniqueID(testMetricIDPrefix),
			Description: "DESC",
			Filter:      "FILTER",
		})
	}
	for _, m := range metrics {
		if err := client.CreateMetric(ctx, m); err != nil {
			t.Fatalf("Create(%q): %v", m.ID, err)
		}
		defer client.DeleteMetric(ctx, m.ID)
	}

	it := client.Metrics(ctx)
	msg, ok := testutil.TestIteratorNext(metrics, iterator.Done, func() (interface{}, error) { return it.Next() })
	if !ok {
		t.Fatal(msg)
	}
	// TODO(jba): test exact paging.
}
예제 #3
0
func TestListSinks(t *testing.T) {
	ctx := context.Background()
	var sinks []*Sink
	for i := 0; i < 4; i++ {
		sinks = append(sinks, &Sink{
			ID:          ltesting.UniqueID(testSinkIDPrefix),
			Destination: testSinkDestination,
			Filter:      testFilter,
		})
	}
	for _, s := range sinks {
		if _, err := client.CreateSink(ctx, s); err != nil {
			t.Fatalf("Create(%q): %v", s.ID, err)
		}
		defer client.DeleteSink(ctx, s.ID)
	}

	it := client.Sinks(ctx)
	msg, ok := testutil.TestIteratorNext(sinks, iterator.Done, func() (interface{}, error) { return it.Next() })
	if !ok {
		t.Fatal(msg)
	}
	// TODO(jba): test exact paging.
}