func TestPingBogusHostnameEndpointFailure(t *testing.T) {

	// given
	client := client.LatencyClient{Host: "http://localhost:7801", RemoteHost: "somehostname.that.does.not.exist.com"}

	// when
	_, err := client.PingHost()

	//then
	if err == nil {
		t.Error("No error encountered")
	}
}
func TestPingBogusIPEndpointFailure(t *testing.T) {

	// given
	client := client.LatencyClient{Host: "http://localhost:7801", RemoteHost: "8.8.-1.-1"}

	// when
	_, err := client.PingHost()

	//then
	if err == nil {
		t.Error("No error encountered")
	}

}
func TestPingHostnameEndpointSuccess(t *testing.T) {

	// given
	client := client.LatencyClient{Host: "http://localhost:7801", RemoteHost: "google.com"}

	// when
	latencyResponse, err := client.PingHost()

	//then
	if err != nil {
		t.Error(err)
	} else {
		if latencyResponse.STATUS != "ok" {
			fmt.Printf("%+v\n", latencyResponse)
			t.Error("Status not ok.")
		}
	}
}
func main() {

	app := cli.NewApp()
	app.Name = "latency cli"
	app.Usage = "cli to work with the latency service"
	app.Version = "0.2.0"

	app.Flags = []cli.Flag{
		cli.StringFlag{"host", "http://localhost:8080", "Hostname for latency API", "APP_HOST"},
		cli.StringFlag{"remotehost", "8.8.8.8", "Host to check latency to", "APP_REMOTE_HOST"},
	}

	app.Commands = []cli.Command{
		{
			Name:  "latency",
			Usage: "(title description) check latency to a remote ip",
			Action: func(c *cli.Context) {

				host := c.GlobalString("host")
				remotehost := c.GlobalString("remotehost")

				client := client.LatencyClient{Host: host, RemoteHost: remotehost}

				latencyData, err := client.PingHost()

				if err != nil {
					log.Fatal(err)
					return
				}
				fmt.Printf("%+v\n", latencyData)
			},
		},
	}

	app.Run(os.Args)
}