fsouza / fake-gcs-server

Google Cloud Storage emulator & testing library.
https://pkg.go.dev/github.com/fsouza/fake-gcs-server/fakestorage?tab=doc
BSD 2-Clause "Simplified" License
1k stars 210 forks source link

Updating a bucket returns 404 #1651

Open airzym opened 1 week ago

airzym commented 1 week ago

I'm trying to create a bucket with versioning enabled.

I've followed Google Cloud documentation here, with the addition of creating the bucket, my code looks like the following:

public class LocalEmulatorStorageClientProvider : IStorageClientProvider
{
    public const string BucketName = "test-bucket";

    public async Task<StorageClient> CreateStorageClient()
    {
        var storageClient = await new StorageClientBuilder
        {
            BaseUri = "http://localhost:8083/storage/v1/",
            UnauthenticatedAccess = true,
        }.BuildAsync();

        if (!BucketExists(storageClient, BucketName))
        {
            await storageClient.CreateBucketAsync("test-project", BucketName);
            var bucket = await storageClient.GetBucketAsync(BucketName);
            bucket.Versioning = new Bucket.VersioningData
            {
                Enabled = true
            };
            await storageClient.UpdateBucketAsync(bucket);
        }

        return storageClient;
    }

    private bool BucketExists(StorageClient storageClient, string bucketName)
    {
        try
        {
            storageClient.GetBucket(bucketName);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
}

I'm running into a problem where the client throws when calling UpdateBucketAsync() with the following exception: The service storage has thrown an exception. HttpStatusCode is NotFound. Not Found which corresponds to the fake-gcs-server container logs:

2024-06-21 07:39:33 time=2024-06-21T06:39:33.521Z level=INFO msg="server started at http://0.0.0.0:8083"
2024-06-21 07:40:01 time=2024-06-21T06:40:01.553Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:01 +0000] \"GET /storage/v1/b/test-bucket HTTP/1.1\" 404 119\n"
2024-06-21 07:40:14 time=2024-06-21T06:40:14.256Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:14 +0000] \"POST /storage/v1/b?project=test-project HTTP/1.1\" 200 345\n"
2024-06-21 07:40:14 time=2024-06-21T06:40:14.291Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:14 +0000] \"GET /storage/v1/b/test-bucket HTTP/1.1\" 200 345\n"
2024-06-21 07:40:35 time=2024-06-21T06:40:35.034Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:35 +0000] \"PUT /storage/v1/b/test-bucket HTTP/1.1\" 404 119\n"

Theres nothing I can spot in the docs that suggest I'm missing something here.

christophergunn commented 1 week ago

It looks like your failing request is a PUT request to update a bucket. I'm no GoLang expert, but it seems that the code doesn't support PUT requests on that route:

server.go