-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPECS: Add boilerplate specs for watcher_test.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |