Merge remote-tracking branch 'origin/260201-readonly' into beta
# Conflicts: # README.md # www/index.html
This commit is contained in:
@@ -20,11 +20,15 @@ func LoadConfig(v any) {
|
||||
}
|
||||
|
||||
var configMu sync.Mutex
|
||||
var ConfigReadOnly bool
|
||||
|
||||
func PatchConfig(path []string, value any) error {
|
||||
if ConfigPath == "" {
|
||||
return errors.New("config file disabled")
|
||||
}
|
||||
if ConfigReadOnly {
|
||||
return errors.New("config is read-only")
|
||||
}
|
||||
|
||||
configMu.Lock()
|
||||
defer configMu.Unlock()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPatchConfigReadOnly(t *testing.T) {
|
||||
prevPath := ConfigPath
|
||||
prevReadOnly := ConfigReadOnly
|
||||
t.Cleanup(func() {
|
||||
ConfigPath = prevPath
|
||||
ConfigReadOnly = prevReadOnly
|
||||
})
|
||||
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "config.yaml")
|
||||
require.NoError(t, os.WriteFile(path, []byte(""), 0644))
|
||||
|
||||
ConfigPath = path
|
||||
ConfigReadOnly = true
|
||||
|
||||
err := PatchConfig([]string{"streams", "cam"}, "rtsp://example.com")
|
||||
require.Error(t, err)
|
||||
require.EqualError(t, err, "config is read-only")
|
||||
}
|
||||
Reference in New Issue
Block a user