Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error notification when using host mode (no device) #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fsevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ func (es *EventStream) Start() {
// in C callback
cbInfo := registry.Add(es)
es.registryID = cbInfo
es.uuid = GetDeviceUUID(es.Device)
if es.Device != 0 {
Copy link
Contributor

@nathany nathany Jan 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will need to be revised in light of the changes in #41.

We need to rebase this against master and test it with multiple versions of Go.

es.uuid = GetDeviceUUID(es.Device)
}
es.start(es.Paths, cbInfo)
}

Expand Down
67 changes: 50 additions & 17 deletions fsevents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,73 @@ import (
"time"
)

func newEventStream(t *testing.T, path string, useDev bool) *EventStream {
es := &EventStream{
Paths: []string{path},
Latency: 500 * time.Millisecond,
Flags: FileEvents,
}

if useDev {
dev, err := DeviceForPath(path)
if err != nil {
t.Fatal(err)
}

es.Device = dev
}

return es
}

func processEvents(t *testing.T, es *EventStream, wait chan Event) {
for msg := range es.Events {
for _, event := range msg {
t.Logf("Event: %#v", event)
wait <- event
es.Stop()
return
}
}
}

func TestBasicExample(t *testing.T) {
path, err := ioutil.TempDir("", "fsexample")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(path)

dev, err := DeviceForPath(path)
es := newEventStream(t, path, true)

es.Start()

wait := make(chan Event)
go processEvents(t, es, wait)

err = ioutil.WriteFile(filepath.Join(path, "example.txt"), []byte("example"), 0600)
if err != nil {
t.Fatal(err)
}

es := &EventStream{
Paths: []string{path},
Latency: 500 * time.Millisecond,
Device: dev,
Flags: FileEvents,
<-wait
}

func TestNoDevice(t *testing.T) {
path, err := ioutil.TempDir("", "fsexample")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(path)

es := newEventStream(t, path, false)

es.Start()

wait := make(chan Event)
go func() {
for msg := range es.Events {
for _, event := range msg {
t.Logf("Event: %#v", event)
wait <- event
es.Stop()
return
}
}
}()
go processEvents(t, es, wait)

err = ioutil.WriteFile(filepath.Join(path, "example.txt"), []byte("example"), 0700)
err = ioutil.WriteFile(filepath.Join(path, "example.txt"), []byte("example"), 0600)
if err != nil {
t.Fatal(err)
}
Expand Down