package etcd_tools

import (
	"fmt"
	"testing"
	"time"
)

func TestLocalIPs(t *testing.T) {
	cli, err := NewLocalClient()
	if err != nil {
		t.Fatal(err)
	}
	defer cli.Close()
	hosts, err := Discover(cli, "snafu")
	if err != nil {
		t.Fatal(err)
	}
	if len(hosts) != 0 {
		fmt.Printf("Discover returned %v", hosts)
		t.Fatal("Expected empty discovery")
	}
	d := NewDiscovery(cli, "snafu", s5)
	err = d.Announce("en0", 8080, 5)
	if err != nil {
		t.Fatal(err)
	}
	time.Sleep(17 * time.Second)
	hosts, err = Discover(cli, "snafu")
	if err != nil {
		t.Fatal(err)
	}
	fmt.Printf("Discover returned %v\n", hosts)
	if len(hosts) != 1 {
		t.Fatal("Expected 1 discovery result")
	}
}
