aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/mbf/internal/ci/ci_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/mbf/internal/ci/ci_test.go')
-rw-r--r--cmd/mbf/internal/ci/ci_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/cmd/mbf/internal/ci/ci_test.go b/cmd/mbf/internal/ci/ci_test.go
new file mode 100644
index 00000000..b5ed134e
--- /dev/null
+++ b/cmd/mbf/internal/ci/ci_test.go
@@ -0,0 +1,55 @@
+package ci_test
+
+import (
+ "bytes"
+ "context"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "hakurei.app/cmd/mbf/internal/ci"
+)
+
+func TestFollow(t *testing.T) {
+ t.Parallel()
+
+ pathname := filepath.Join(t.TempDir(), "f")
+ w, err := os.Create(pathname)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var buf bytes.Buffer
+ ctx, cancel := context.WithCancel(t.Context())
+
+ var want string
+ go func() {
+ defer cancel()
+ for _, s := range []string{
+ "\xde\xad\xbe\xef",
+ "\xff\xff\xff\xff",
+ "\x00\x00",
+ } {
+ want += s
+ if _, _err := w.WriteString(s); _err != nil {
+ panic(_err)
+ }
+ }
+ }()
+
+retry:
+ if err = ci.Follow(ctx, pathname, &buf); err != nil {
+ t.Fatal(err)
+ }
+ <-ctx.Done()
+
+ // the inotify event takes time to arrive, and there is no way to
+ // synchronise for this cleanly
+ if buf.Len() != len(want) {
+ goto retry
+ }
+
+ if got := buf.String(); got != want {
+ t.Fatalf("follow: %q, want %q", got, want)
+ }
+}