Example #1
0
func (t *PrefixBucketTest) ListObjects_PrefixAndDelimeter() {
	var err error

	// Create a few objects.
	err = gcsutil.CreateObjects(
		t.ctx,
		t.wrapped,
		map[string][]byte{
			t.prefix + "burrito":     []byte(""),
			t.prefix + "burrito_0":   []byte(""),
			t.prefix + "burrito_1":   []byte(""),
			t.prefix + "enchilada_0": []byte(""),
			"some_other":             []byte(""),
		})

	AssertEq(nil, err)

	// List, with a delimiter and a prefix. Make things extra interesting by
	// using a delimiter that is contained within the bucket prefix.
	AssertNe(-1, strings.IndexByte(t.prefix, '_'))
	l, err := t.bucket.ListObjects(
		t.ctx,
		&gcs.ListObjectsRequest{
			Delimiter: "_",
			Prefix:    "burrito",
		})

	AssertEq(nil, err)
	AssertEq("", l.ContinuationToken)

	ExpectThat(l.CollapsedRuns, ElementsAre("burrito_"))

	AssertEq(1, len(l.Objects))
	ExpectEq("burrito", l.Objects[0].Name)
}
Example #2
0
func (t *PrefixBucketTest) ListObjects_Prefix() {
	var err error

	// Create a few objects.
	err = gcsutil.CreateObjects(
		t.ctx,
		t.wrapped,
		map[string][]byte{
			t.prefix + "burritn":  []byte(""),
			t.prefix + "burrito0": []byte(""),
			t.prefix + "burrito1": []byte(""),
			t.prefix + "burritp":  []byte(""),
			"some_other":          []byte(""),
		})

	AssertEq(nil, err)

	// List, with a prefix.
	l, err := t.bucket.ListObjects(
		t.ctx,
		&gcs.ListObjectsRequest{
			Prefix: "burrito",
		})

	AssertEq(nil, err)
	AssertEq("", l.ContinuationToken)
	AssertThat(l.CollapsedRuns, ElementsAre())

	AssertEq(2, len(l.Objects))
	ExpectEq("burrito0", l.Objects[0].Name)
	ExpectEq("burrito1", l.Objects[1].Name)
}
Example #3
0
func (t *PrefixBucketTest) ListObjects_NoOptions() {
	var err error

	// Create a few objects.
	err = gcsutil.CreateObjects(
		t.ctx,
		t.wrapped,
		map[string][]byte{
			t.prefix + "burrito":   []byte(""),
			t.prefix + "enchilada": []byte(""),
			t.prefix + "taco":      []byte(""),
			"some_other":           []byte(""),
		})

	AssertEq(nil, err)

	// List.
	l, err := t.bucket.ListObjects(
		t.ctx,
		&gcs.ListObjectsRequest{})

	AssertEq(nil, err)
	AssertEq("", l.ContinuationToken)
	AssertThat(l.CollapsedRuns, ElementsAre())

	AssertEq(3, len(l.Objects))
	ExpectEq("burrito", l.Objects[0].Name)
	ExpectEq("enchilada", l.Objects[1].Name)
	ExpectEq("taco", l.Objects[2].Name)
}
Example #4
0
func (t *fsTest) createObjects(in map[string]string) error {
	b := make(map[string][]byte)
	for k, v := range in {
		b[k] = []byte(v)
	}

	err := gcsutil.CreateObjects(t.ctx, t.bucket, b)
	return err
}
Example #5
0
func (t *PrefixBucketTest) ComposeObjects() {
	var err error

	suffix0 := "taco"
	contents0 := "foo"

	suffix1 := "burrito"
	contents1 := "bar"

	// Create two objects through the back door.
	err = gcsutil.CreateObjects(
		t.ctx,
		t.wrapped,
		map[string][]byte{
			t.prefix + suffix0: []byte(contents0),
			t.prefix + suffix1: []byte(contents1),
		})

	AssertEq(nil, err)

	// Compose them.
	newSuffix := "enchilada"
	o, err := t.bucket.ComposeObjects(
		t.ctx,
		&gcs.ComposeObjectsRequest{
			DstName: newSuffix,
			Sources: []gcs.ComposeSource{
				{Name: suffix0},
				{Name: suffix1},
			},
		})

	AssertEq(nil, err)
	ExpectEq(newSuffix, o.Name)

	// Read it through the back door.
	actual, err := gcsutil.ReadObject(t.ctx, t.wrapped, t.prefix+newSuffix)
	AssertEq(nil, err)
	ExpectEq(contents0+contents1, string(actual))
}
Example #6
0
func (t *fsTest) createObjects(in map[string]string) error {
	err := gcsutil.CreateObjects(t.ctx, t.bucket, in)
	return err
}