From c177cf097a47ca66e397cd68c7a5f58ae7d89024 Mon Sep 17 00:00:00 2001 From: Lucas Marques Date: Tue, 4 Jun 2024 17:51:16 +0200 Subject: [PATCH] feat(datastore): add mock storage option (#289) * feat(datastore): add mock storage option * fix(config): remove unused config --- deploy/charts/burrito/values.yaml | 1 + internal/burrito/config/config.go | 1 + internal/datastore/storage/common.go | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/deploy/charts/burrito/values.yaml b/deploy/charts/burrito/values.yaml index 40d53b5c..e0f257f2 100644 --- a/deploy/charts/burrito/values.yaml +++ b/deploy/charts/burrito/values.yaml @@ -43,6 +43,7 @@ config: datastore: serviceAccounts: [] storage: + mock: false # -- Use in-memory storage for testing - not intended for production use gcs: {} azure: {} aws: {} diff --git a/internal/burrito/config/config.go b/internal/burrito/config/config.go index c830035b..79297979 100644 --- a/internal/burrito/config/config.go +++ b/internal/burrito/config/config.go @@ -29,6 +29,7 @@ type StorageConfig struct { GCS GCSConfig `mapstructure:"gcs"` S3 S3Config `mapstructure:"s3"` Azure AzureConfig `mapstructure:"azure"` + Mock bool `mapstructure:"mock"` } type GCSConfig struct { diff --git a/internal/datastore/storage/common.go b/internal/datastore/storage/common.go index e5bae46d..e69c349d 100644 --- a/internal/datastore/storage/common.go +++ b/internal/datastore/storage/common.go @@ -4,10 +4,13 @@ import ( "fmt" "strconv" + log "github.com/sirupsen/logrus" + "github.com/padok-team/burrito/internal/burrito/config" "github.com/padok-team/burrito/internal/datastore/storage/azure" errors "github.com/padok-team/burrito/internal/datastore/storage/error" "github.com/padok-team/burrito/internal/datastore/storage/gcs" + "github.com/padok-team/burrito/internal/datastore/storage/mock" "github.com/padok-team/burrito/internal/datastore/storage/s3" ) @@ -68,6 +71,9 @@ func New(config config.Config) Storage { return Storage{Backend: gcs.New(config.Datastore.Storage.GCS)} case config.Datastore.Storage.S3.Bucket != "": return Storage{Backend: s3.New(config.Datastore.Storage.S3)} + case config.Datastore.Storage.Mock: + log.Warn("Using mock storage backend - for testing only - no data will only be stored in memory and will be lost when the process exits") + return Storage{Backend: mock.New()} } return Storage{} }