gitee.com/h79/goutils@v1.22.10/loader/loader_test.go (about)

     1  package loader
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestLoader_Watch(t *testing.T) {
     9  
    10  	item := map[string]interface{}{}
    11  	ll := NewFiler("./load.json", "json", &item)
    12  
    13  	if err, _ := ll.Read(); err != nil {
    14  		t.Error(err)
    15  		return
    16  	}
    17  	jn, _ := ll.JSON()
    18  	t.Logf("JSON: %+v", jn)
    19  
    20  	ch := ll.WatchChan()
    21  
    22  	//ch := make(bus.EventChan)
    23  	//bs.Subscribe("load.data", ch)
    24  
    25  	go func() {
    26  		for {
    27  			select {
    28  			case <-ch:
    29  				t.Logf("file changed, %+v", ll.Data().(*map[string]interface{}))
    30  
    31  			default:
    32  			}
    33  		}
    34  	}()
    35  
    36  	//ll.WithLoadFunc(func(data Data) (error, bool) {
    37  	//	return nil, false
    38  	//})
    39  	time.Sleep(time.Second * 50)
    40  }