mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-21 21:17:13 +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
50
config/config_source_test.go
Normal file
50
config/config_source_test.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFileWatcherSource(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, "example.txt"), []byte{1, 2, 3, 4}, 0o600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
src := NewFileWatcherSource(NewStaticSource(&Config{
|
||||
Options: &Options{
|
||||
CAFile: filepath.Join(tmpdir, "example.txt"),
|
||||
},
|
||||
}))
|
||||
var closeOnce sync.Once
|
||||
ch := make(chan struct{})
|
||||
src.OnConfigChange(func(cfg *Config) {
|
||||
closeOnce.Do(func() {
|
||||
close(ch)
|
||||
})
|
||||
})
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(tmpdir, "example.txt"), []byte{5, 6, 7, 8}, 0o600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ch:
|
||||
case <-time.After(time.Second):
|
||||
t.Error("expected OnConfigChange to be fired after modifying a file")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue