mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-05-11 20:56:35 +00:00

This is a cherry-pick of 157f5d1412
followed by build/CI changes so that amd64/linux FIPS compliance is
provided by new/separate binaries/artifacts/packages.
The reasoning being that FIPS compliance places excessive requirements
in the encryption algorithms used for regular users that do not care
about that. This can cause cloudflared to reject HTTPS origins that
would otherwise be accepted without FIPS checks.
This way, by having separate binaries, existing ones remain as they
were, and only FIPS-needy users will opt-in to the new FIPS binaries.
58 lines
997 B
Go
58 lines
997 B
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
package watcher
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type mockNotifier struct {
|
|
eventPath string
|
|
}
|
|
|
|
func (n *mockNotifier) WatcherItemDidChange(path string) {
|
|
n.eventPath = path
|
|
}
|
|
|
|
func (n *mockNotifier) WatcherDidError(err error) {
|
|
}
|
|
|
|
func TestFileChanged(t *testing.T) {
|
|
filePath := "test_file"
|
|
f, err := os.Create(filePath)
|
|
assert.NoError(t, err)
|
|
defer func() {
|
|
f.Close()
|
|
os.Remove(filePath)
|
|
}()
|
|
|
|
service, err := NewFile()
|
|
assert.NoError(t, err)
|
|
|
|
err = service.Add(filePath)
|
|
assert.NoError(t, err)
|
|
|
|
n := &mockNotifier{}
|
|
go service.Start(n)
|
|
|
|
f.Sync()
|
|
|
|
w := bufio.NewWriter(f)
|
|
_, err = w.WriteString("hello Austin, do you like my file watcher?\n")
|
|
assert.NoError(t, err)
|
|
err = w.Flush()
|
|
assert.NoError(t, err)
|
|
|
|
// give it time to trigger
|
|
time.Sleep(20 * time.Millisecond)
|
|
service.Shutdown()
|
|
|
|
assert.Equal(t, filePath, n.eventPath, "notifier didn't get an new file write event")
|
|
}
|