2017-04-17 10:50:02 +00:00
|
|
|
package kv
|
2015-11-13 10:50:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2016-03-04 22:52:08 +00:00
|
|
|
"time"
|
2015-11-13 10:50:32 +00:00
|
|
|
|
2018-01-24 16:52:03 +00:00
|
|
|
"github.com/abronan/valkeyrie/store"
|
2018-08-06 18:00:03 +00:00
|
|
|
"github.com/containous/traefik/log"
|
2016-12-30 08:21:13 +00:00
|
|
|
"github.com/containous/traefik/types"
|
2015-11-13 10:50:32 +00:00
|
|
|
)
|
|
|
|
|
2016-03-04 22:52:08 +00:00
|
|
|
func TestKvWatchTree(t *testing.T) {
|
|
|
|
returnedChans := make(chan chan []*store.KVPair)
|
2017-12-23 16:45:25 +00:00
|
|
|
provider := Provider{
|
|
|
|
kvClient: &Mock{
|
|
|
|
WatchTreeMethod: func() <-chan []*store.KVPair {
|
|
|
|
c := make(chan []*store.KVPair, 10)
|
|
|
|
returnedChans <- c
|
|
|
|
return c
|
2016-03-04 22:52:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
configChan := make(chan types.ConfigMessage)
|
2016-04-19 17:23:08 +00:00
|
|
|
go func() {
|
2018-08-06 18:00:03 +00:00
|
|
|
if err := provider.watchKv(configChan, "prefix", make(chan bool, 1)); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
2016-04-19 17:23:08 +00:00
|
|
|
}()
|
2016-03-04 22:52:08 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case c1 := <-returnedChans:
|
|
|
|
c1 <- []*store.KVPair{}
|
|
|
|
<-configChan
|
|
|
|
close(c1) // WatchTree chans can close due to error
|
|
|
|
case <-time.After(1 * time.Second):
|
2016-03-05 20:43:44 +00:00
|
|
|
t.Fatalf("Failed to create a new WatchTree chan")
|
2016-03-04 22:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case c2 := <-returnedChans:
|
|
|
|
c2 <- []*store.KVPair{}
|
|
|
|
<-configChan
|
|
|
|
case <-time.After(1 * time.Second):
|
2016-03-05 20:43:44 +00:00
|
|
|
t.Fatalf("Failed to create a new WatchTree chan")
|
2016-03-04 22:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
2017-08-18 00:18:02 +00:00
|
|
|
case <-configChan:
|
2016-03-04 22:52:08 +00:00
|
|
|
t.Fatalf("configChan should be empty")
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|