mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
fix test
This commit is contained in:
parent
a673a9b5f5
commit
06a1fc77a0
1 changed files with 25 additions and 35 deletions
|
@ -25,18 +25,14 @@ func TestWatcher(t *testing.T) {
|
||||||
w.Watch(context.Background(), []string{filepath.Join(tmpdir, "test1.txt")})
|
w.Watch(context.Background(), []string{filepath.Join(tmpdir, "test1.txt")})
|
||||||
|
|
||||||
ch := w.Bind()
|
ch := w.Bind()
|
||||||
defer w.Unbind(ch)
|
t.Cleanup(func() { w.Unbind(ch) })
|
||||||
|
|
||||||
err = os.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{5, 6, 7, 8}, 0o666)
|
err = os.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{5, 6, 7, 8}, 0o666)
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
expectChange(t, ch)
|
||||||
case <-ch:
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Error("expected change signal when file is modified")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatcherSymlink(t *testing.T) {
|
func TestWatcherSymlink(t *testing.T) {
|
||||||
|
@ -64,20 +60,12 @@ func TestWatcherSymlink(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, os.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{9, 10, 11}, 0o666))
|
assert.NoError(t, os.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{9, 10, 11}, 0o666))
|
||||||
|
|
||||||
select {
|
expectChange(t, ch)
|
||||||
case <-ch:
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Error("expected change signal when underlying file is modified")
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NoError(t, os.Symlink(filepath.Join(tmpdir, "test2.txt"), filepath.Join(tmpdir, "symlink2.txt")))
|
assert.NoError(t, os.Symlink(filepath.Join(tmpdir, "test2.txt"), filepath.Join(tmpdir, "symlink2.txt")))
|
||||||
assert.NoError(t, os.Rename(filepath.Join(tmpdir, "symlink2.txt"), filepath.Join(tmpdir, "symlink1.txt")))
|
assert.NoError(t, os.Rename(filepath.Join(tmpdir, "symlink2.txt"), filepath.Join(tmpdir, "symlink1.txt")))
|
||||||
|
|
||||||
select {
|
expectChange(t, ch)
|
||||||
case <-ch:
|
|
||||||
case <-time.After(10 * time.Second):
|
|
||||||
t.Error("expected change signal when symlink is changed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatcher_FileRemoval(t *testing.T) {
|
func TestWatcher_FileRemoval(t *testing.T) {
|
||||||
|
@ -92,31 +80,33 @@ func TestWatcher_FileRemoval(t *testing.T) {
|
||||||
w.Watch(context.Background(), []string{filepath.Join(tmpdir, "test1.txt")})
|
w.Watch(context.Background(), []string{filepath.Join(tmpdir, "test1.txt")})
|
||||||
|
|
||||||
ch := w.Bind()
|
ch := w.Bind()
|
||||||
defer w.Unbind(ch)
|
t.Cleanup(func() { w.Unbind(ch) })
|
||||||
|
|
||||||
err = os.Remove(filepath.Join(tmpdir, "test1.txt"))
|
err = os.Remove(filepath.Join(tmpdir, "test1.txt"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectChange := func() {
|
expectChange(t, ch)
|
||||||
cnt := 0
|
|
||||||
loop:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
cnt++
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cnt == 0 {
|
|
||||||
t.Error("expected change signal")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expectChange()
|
|
||||||
|
|
||||||
err = os.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{5, 6, 7, 8}, 0o666)
|
err = os.WriteFile(filepath.Join(tmpdir, "test1.txt"), []byte{5, 6, 7, 8}, 0o666)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectChange()
|
expectChange(t, ch)
|
||||||
|
}
|
||||||
|
|
||||||
|
func expectChange(t *testing.T, ch chan context.Context) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
cnt := 0
|
||||||
|
loop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ch:
|
||||||
|
cnt++
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
break loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cnt == 0 {
|
||||||
|
t.Error("expected change signal")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue