mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-24 12:08:19 +02:00
config: detect underlying file changes (#1775)
* wip * cleanup * add test * use uuid for temp dir, derive root CA path from filemgr for tests * fix comment * fix double close * use latest notify
This commit is contained in:
parent
c99994bed8
commit
10912add67
16 changed files with 500 additions and 99 deletions
42
internal/fileutil/watcher_test.go
Normal file
42
internal/fileutil/watcher_test.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package fileutil
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWatcher(t *testing.T) {
|
||||
tmpdir := filepath.Join(os.TempDir(), uuid.New().String())
|
||||
err := os.MkdirAll(tmpdir, 0o755)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{1, 2, 3, 4}, 0o666)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
w := NewWatcher()
|
||||
w.Add(filepath.Join(tmpdir, "test1.txt"))
|
||||
|
||||
ch := w.Bind()
|
||||
defer w.Unbind(ch)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{5, 6, 7, 8}, 0o666)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ch:
|
||||
case <-time.After(time.Second):
|
||||
t.Error("expected change signal when file is modified")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue