Skip to content

Commit

Permalink
SPECS: Add boilerplate specs for watcher_test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cian911 committed Dec 11, 2021
1 parent 249b48a commit ce85df1
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions watcher/watcher_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
package watcher

import "testing"

const (
path = "/tmp"
destination = "/test"
)

func TestWatcher(t *testing.T) {
t.Run("It registers a consumer", func(t *testing.T) {
pw, pc := setup()

pw.Register(&pc)

if len(pw.(*PathWatcher).Consumers) != 1 {
t.Fatalf("Consumer was not registered when it should have been. want=%d, got=%d", 1, len(pw.(*PathWatcher).Consumers))
}
})

t.Run("It unregisters a consumer", func(t *testing.T) {
pw, pc := setup()

pw.Register(&pc)
pw.Unregister(&pc)

if len(pw.(*PathWatcher).Consumers) != 0 {
t.Fatalf("Consumer was not unregistered when it should have been. want=%d, got=%d", 0, len(pw.(*PathWatcher).Consumers))
}
})
}

func setup() (Producer, Consumer) {
var pw Producer = &PathWatcher{
Path: path,
}

var pc Consumer = &PathConsumer{
Path: path,
Destination: destination,
}

return pw, pc
}

0 comments on commit ce85df1

Please sign in to comment.