mirror of
https://github.com/datarhei/core.git
synced 2025-11-03 10:30:53 +08:00
Use abstract filesystem for stores
This commit is contained in:
@@ -10,14 +10,19 @@ import (
|
||||
"github.com/datarhei/core/v16/config/store"
|
||||
v1 "github.com/datarhei/core/v16/config/v1"
|
||||
"github.com/datarhei/core/v16/http/mock"
|
||||
"github.com/datarhei/core/v16/io/fs"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func getDummyConfigRouter() (*echo.Echo, store.Store) {
|
||||
func getDummyConfigRouter(t *testing.T) (*echo.Echo, store.Store) {
|
||||
router := mock.DummyEcho()
|
||||
|
||||
config := store.NewDummy()
|
||||
memfs, err := fs.NewMemFilesystem(fs.MemConfig{})
|
||||
require.NoError(t, err)
|
||||
|
||||
config, err := store.NewJSON(memfs, "/config.json", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
handler := NewConfig(config)
|
||||
|
||||
@@ -28,7 +33,7 @@ func getDummyConfigRouter() (*echo.Echo, store.Store) {
|
||||
}
|
||||
|
||||
func TestConfigGet(t *testing.T) {
|
||||
router, _ := getDummyConfigRouter()
|
||||
router, _ := getDummyConfigRouter(t)
|
||||
|
||||
mock.Request(t, http.StatusOK, router, "GET", "/", nil)
|
||||
|
||||
@@ -36,18 +41,18 @@ func TestConfigGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigSetConflict(t *testing.T) {
|
||||
router, _ := getDummyConfigRouter()
|
||||
router, _ := getDummyConfigRouter(t)
|
||||
|
||||
var data bytes.Buffer
|
||||
|
||||
encoder := json.NewEncoder(&data)
|
||||
encoder.Encode(config.New())
|
||||
encoder.Encode(config.New(nil))
|
||||
|
||||
mock.Request(t, http.StatusConflict, router, "PUT", "/", &data)
|
||||
}
|
||||
|
||||
func TestConfigSet(t *testing.T) {
|
||||
router, store := getDummyConfigRouter()
|
||||
router, store := getDummyConfigRouter(t)
|
||||
|
||||
storedcfg := store.Get()
|
||||
|
||||
@@ -57,7 +62,7 @@ func TestConfigSet(t *testing.T) {
|
||||
encoder := json.NewEncoder(&data)
|
||||
|
||||
// Setting a new v3 config
|
||||
cfg := config.New()
|
||||
cfg := config.New(nil)
|
||||
cfg.FFmpeg.Binary = "true"
|
||||
cfg.DB.Dir = "."
|
||||
cfg.Storage.Disk.Dir = "."
|
||||
@@ -78,7 +83,7 @@ func TestConfigSet(t *testing.T) {
|
||||
require.Equal(t, "cert@datarhei.com", cfg.TLS.Email)
|
||||
|
||||
// Setting a complete v1 config
|
||||
cfgv1 := v1.New()
|
||||
cfgv1 := v1.New(nil)
|
||||
cfgv1.FFmpeg.Binary = "true"
|
||||
cfgv1.DB.Dir = "."
|
||||
cfgv1.Storage.Disk.Dir = "."
|
||||
|
||||
Reference in New Issue
Block a user