github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/watch_test.go (about)

     1  package alfred
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestWatchComponent(t *testing.T) {
     9  	task := Task{
    10  		Watch: ".*?go$",
    11  	}
    12  	context := InitialContext([]string{})
    13  	tasks := make(map[string]Task)
    14  	changes := make(chan bool)
    15  	go func(changes chan bool) {
    16  		evaluate("touch watch_test.go", ".")
    17  		watch(task, context, tasks)
    18  		changes <- true
    19  	}(changes)
    20  
    21  	select {
    22  	case <-changes:
    23  	case <-time.After(2 * time.Second):
    24  		// timeout ... boo!
    25  		t.Fatalf("Watch failed ...")
    26  	}
    27  
    28  	<-time.After(time.Second * 3)
    29  }