Exemple #1
0
func TestRoundRobinStrategy(t *testing.T) {
	lib, err := dns.NewDefaultLookupLib()
	assert.Nil(t, err)

	//given
	c := lb.NewGeneric(&lb.Config{
		Dns:      lib,
		Strategy: lb.RoundRobinStrategy,
	})

	// when
	srvName := "foo.service.fligl.io"
	add1, err1 := c.Next(srvName)
	add2, err2 := c.Next(srvName)

	// then
	assert.Nil(t, err1)
	assert.Nil(t, err2)

	adds := []dns.Address{add1, add2}
	sort.Sort(ByConnectionString(adds))

	expected := []dns.Address{dns.Address{Address: "0.1.2.3", Port: 8001}, dns.Address{Address: "4.5.6.7", Port: 8002}}
	assert.Equal(t, expected, adds, "unexpected results")
}
Exemple #2
0
func TestRandomStrategy(t *testing.T) {
	lib, err := dns.NewDefaultLookupLib()
	assert.Nil(t, err)

	//given
	c := lb.NewGeneric(&lb.Config{
		Dns:      lib,
		Strategy: random.RandomStrategy,
	})

	// when
	srvName := "foo.service.fligl.io"
	_, err = c.Next(srvName)

	// then
	assert.Nil(t, err)
}