// The test verifies the following:
//   registering causes initial notification of the current state
//   notifications delivered to two receivers
//   identical notifications cause no updates
//   different update causes new notification
//   instances are sorted
//   no updates after de-registering
The test verifies the following:
registering causes initial notification of the current state
notifications delivered to two receivers
identical notifications cause no updates
different update causes new notification
instances are sorted
no updates after de-registering
// The test verifies the following : // registering causes initial notification of the current state // notifications delivered to two receivers // identical notifications cause no updates // different update causes new notification // instances are sorted // no updates after de - registering
func TestCache(t *testing.T) {
	e1 := sd.Event{Instances: []string{"y", "x"}} 
	e2 := sd.Event{Instances: []string{"c", "a", "b"}}
	c := NewCache()
	if want, have := 0, len(c.State().Instances); want != have {
		t.Fatalf("want %v instances, have %v", want, have)
	}
	c.Update(e1) 
	if want, have := 2, len(c.State().Instances); want != have {
		t.Fatalf("want %v instances, have %v", want, have)
	}
	r1 := make(chan sd.Event)
	go c.Register(r1)
	expectUpdate(t, r1, []string{"x", "y"})
	r2 := make(chan sd.Event)
	go c.Register(r2)
	expectUpdate(t, r2, []string{"x", "y"})
	c.Update(sd.Event{Instances: []string{"x", "y"}})
	expectNoUpdate(t, r1)
	expectNoUpdate(t, r2)
	go c.Update(e2) 
	expectUpdate(t, r1, []string{"a", "b", "c"})
	expectUpdate(t, r2, []string{"a", "b", "c"})
	c.Deregister(r1)
	c.Deregister(r2)
	close(r1)
	close(r2)
	c.Update(e1)
}
func TestCache ( t * testing . T ) { e1 := sd . Event { Instances : [ ] string { " " , " " } } e2 := sd . Event { Instances : [ ] string { " " , " " , " " } } c := NewCache ( ) if want , have := 0 , len ( c . State ( ) . Instances ) ; want != have { t . Fatalf ( " " , want , have ) } c . Update ( e1 ) if want , have := 2 , len ( c . State ( ) . Instances ) ; want != have { t . Fatalf ( " " , want , have ) } r1 := make ( chan sd . Event ) go c . Register ( r1 ) expectUpdate ( t , r1 , [ ] string { " " , " " } ) r2 := make ( chan sd . Event ) go c . Register ( r2 ) expectUpdate ( t , r2 , [ ] string { " " , " " } ) c . Update ( sd . Event { Instances : [ ] string { " " , " " } } ) expectNoUpdate ( t , r1 ) expectNoUpdate ( t , r2 ) go c . Update ( e2 ) expectUpdate ( t , r1 , [ ] string { " " , " " , " " } ) expectUpdate ( t , r2 , [ ] string { " " , " " , " " } ) c . Deregister ( r1 ) c . Deregister ( r2 ) close ( r1 ) close ( r2 ) c . Update ( e1 ) }
The test verifies the following:
registering causes initial notification of the current state
notifications delivered to two receivers
identical notifications cause no updates
different update causes new notification
instances are sorted
no updates after de-registering
The test verifies the following : registering causes initial notification of the current state notifications delivered to two receivers identical notifications cause no updates different update causes new notification instances are sorted no updates after de - registering
// not sorted // sets initial state // send the same instances but in different order. // because it's a duplicate it should not cause new notification. // if it did, this call would deadlock trying to send to channels with no readers // different set // if deregister didn't work, Update would panic on closed channels