[PR #6] [MERGED] Add filesystem backend #261

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

📋 Pull Request Information

Original PR: https://github.com/fsouza/fake-gcs-server/pull/6
Author: @gracenoah
Created: 4/13/2018
Status: Merged
Merged: 4/18/2018
Merged by: @fsouza

Base: masterHead: add-filesystem-backend


📝 Commits (4)

  • fb3eeb8 factor out inmemory storage backend
  • be9840e implement filesystem storage backend
  • fbeeaf4 clean up and improve error handling
  • 52b7b6c store CRCs unmodified

📊 Changes

9 files changed (+537 additions, -66 deletions)

View changed files

📝 fakestorage/bucket.go (+9 -6)
📝 fakestorage/object.go (+44 -39)
📝 fakestorage/server.go (+55 -17)
📝 fakestorage/upload.go (+16 -4)
internal/backend/backend_test.go (+136 -0)
internal/backend/fs.go (+131 -0)
internal/backend/memory.go (+120 -0)
internal/backend/object.go (+14 -0)
internal/backend/storage.go (+12 -0)

📄 Description

This PR adds the ability to persist stored files to disk. This is helpful when using this server in development (as opposed to just in tests). Usage looks like:

fakestorage.NewServerWithOptions(fakestorage.Options{
		InitialObjects: []fakestorage.Object{
			{
				BucketName: "bucket",
				Name:       "object",
				Content:    []byte("An example object."),
			},
		},
		Host:        "0.0.0.0",
		Port:        4443,
		StorageRoot: "/storage",
	})

This PR is broken up into 3 parts for easy reviewing:

  • Separate the storage details from the server implementation, including basic smoke tests for the storage backend
  • Implement an alternative filesystem implementation of the storage backend for persistence
  • Clean ups and better error handling.

I took special care to make sure I don't break the existing package API, but because some methods didn't have an error return argument, I had to add some panics. I think that's a reasonable tradeoff for now and the errors can be returned when you decide it's okay to break backwards compatibility.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fsouza/fake-gcs-server/pull/6 **Author:** [@gracenoah](https://github.com/gracenoah) **Created:** 4/13/2018 **Status:** ✅ Merged **Merged:** 4/18/2018 **Merged by:** [@fsouza](https://github.com/fsouza) **Base:** `master` ← **Head:** `add-filesystem-backend` --- ### 📝 Commits (4) - [`fb3eeb8`](https://github.com/fsouza/fake-gcs-server/commit/fb3eeb87bd7493a9ed4177a3ed287842af28980a) factor out inmemory storage backend - [`be9840e`](https://github.com/fsouza/fake-gcs-server/commit/be9840e4d5b2a84a4b4eec11774952e189f56a5e) implement filesystem storage backend - [`fbeeaf4`](https://github.com/fsouza/fake-gcs-server/commit/fbeeaf43b2abdedccaea7f2d43979f49fb70ec6d) clean up and improve error handling - [`52b7b6c`](https://github.com/fsouza/fake-gcs-server/commit/52b7b6c58a36da1dda709fe9c2dfeac8ac8b941b) store CRCs unmodified ### 📊 Changes **9 files changed** (+537 additions, -66 deletions) <details> <summary>View changed files</summary> 📝 `fakestorage/bucket.go` (+9 -6) 📝 `fakestorage/object.go` (+44 -39) 📝 `fakestorage/server.go` (+55 -17) 📝 `fakestorage/upload.go` (+16 -4) ➕ `internal/backend/backend_test.go` (+136 -0) ➕ `internal/backend/fs.go` (+131 -0) ➕ `internal/backend/memory.go` (+120 -0) ➕ `internal/backend/object.go` (+14 -0) ➕ `internal/backend/storage.go` (+12 -0) </details> ### 📄 Description This PR adds the ability to persist stored files to disk. This is helpful when using this server in development (as opposed to just in tests). Usage looks like: ```go fakestorage.NewServerWithOptions(fakestorage.Options{ InitialObjects: []fakestorage.Object{ { BucketName: "bucket", Name: "object", Content: []byte("An example object."), }, }, Host: "0.0.0.0", Port: 4443, StorageRoot: "/storage", }) ``` This PR is broken up into 3 parts for easy reviewing: - Separate the storage details from the server implementation, including basic smoke tests for the storage backend - Implement an alternative filesystem implementation of the storage backend for persistence - Clean ups and better error handling. I took special care to make sure I don't break the existing package API, but because some methods didn't have an error return argument, I had to add some panics. I think that's a reasonable tradeoff for now and the errors can be returned when you decide it's okay to break backwards compatibility. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 12:09:57 +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#261
No description provided.