...
1 package poll
2
3 import (
4 "fmt"
5 "os"
6 "testing"
7
8 "gotest.tools/v3/assert"
9 )
10
11 func TestWaitOnFile(t *testing.T) {
12 fakeFilePath := "./fakefile"
13
14 check := FileExists(fakeFilePath)
15
16 t.Run("file does not exist", func(t *testing.T) {
17 r := check(t)
18 assert.Assert(t, !r.Done())
19 assert.Equal(t, r.Message(), fmt.Sprintf("file %s does not exist", fakeFilePath))
20 })
21
22 os.Create(fakeFilePath)
23 defer os.Remove(fakeFilePath)
24
25 t.Run("file exists", func(t *testing.T) {
26 assert.Assert(t, check(t).Done())
27 })
28 }
29
30 func TestWaitOnSocketWithTimeout(t *testing.T) {
31 t.Run("connection to unavailable address", func(t *testing.T) {
32 check := Connection("tcp", "foo.bar:55555")
33 r := check(t)
34 assert.Assert(t, !r.Done())
35 assert.Equal(t, r.Message(), "socket tcp://foo.bar:55555 not available")
36 })
37
38 t.Run("connection to ", func(t *testing.T) {
39 check := Connection("tcp", "google.com:80")
40 assert.Assert(t, check(t).Done())
41 })
42 }
43
View as plain text