[GH-ISSUE #1966] cannot delete using object.delete but deletion using http request works in testcontainers #237

Closed
opened 2026-03-03 12:09:21 +03:00 by kerem · 0 comments
Owner

Originally created by @surajsharma on GitHub (May 16, 2025).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1966

using fake-gcs-server in a testcontainer, i am facing a peculiar problem whereby certain actions like bucket creation etc work via http requests only and not as direct sdk calls, for example this works

func (p *testGCSStorageProvider) Delete(ctx context.Context, key string) error {
	req, _ := http.NewRequest("DELETE", fmt.Sprintf("%s/storage/v1/b/%s/o/%s", os.Getenv("STORAGE_EMULATOR_HOST"), p.bucketName, url.QueryEscape(key)), nil)
	_, err := http.DefaultClient.Do(req)
	return err
}

but this doesn't


func (p *testGCSStorageProvider) Delete(ctx context.Context, key string) error {
	bucket := p.client.Bucket(p.bucketName)
	obj := bucket.Object(key)
	return obj.Delete(ctx)
}

at the same time, this and similar functionality works

func (p *testGCSStorageProvider) Download(ctx context.Context, key string) (io.ReadCloser, models.FileMetadata, error) {
	// First check if the object exists to provide a clear error
	obj := p.client.Bucket(p.bucketName).Object(key)

	// Get file reader
	reader, err := obj.NewReader(ctx)
	if err != nil {
		return nil, models.FileMetadata{}, fmt.Errorf("failed to open reader: %w", err)
	}

...
}


a fix around this would be appreciated.

Originally created by @surajsharma on GitHub (May 16, 2025). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1966 using fake-gcs-server in a testcontainer, i am facing a peculiar problem whereby certain actions like bucket creation etc work via http requests only and not as direct sdk calls, for example this works ```go func (p *testGCSStorageProvider) Delete(ctx context.Context, key string) error { req, _ := http.NewRequest("DELETE", fmt.Sprintf("%s/storage/v1/b/%s/o/%s", os.Getenv("STORAGE_EMULATOR_HOST"), p.bucketName, url.QueryEscape(key)), nil) _, err := http.DefaultClient.Do(req) return err } ``` but this doesn't ```go func (p *testGCSStorageProvider) Delete(ctx context.Context, key string) error { bucket := p.client.Bucket(p.bucketName) obj := bucket.Object(key) return obj.Delete(ctx) } ``` at the same time, this and similar functionality works ```go func (p *testGCSStorageProvider) Download(ctx context.Context, key string) (io.ReadCloser, models.FileMetadata, error) { // First check if the object exists to provide a clear error obj := p.client.Bucket(p.bucketName).Object(key) // Get file reader reader, err := obj.NewReader(ctx) if err != nil { return nil, models.FileMetadata{}, fmt.Errorf("failed to open reader: %w", err) } ... } ``` a fix around this would be appreciated.
kerem closed this issue 2026-03-03 12:09:21 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#237
No description provided.