From 346c59e5eea3b9e856b824b5eac4462f13ae9454 Mon Sep 17 00:00:00 2001
From: Marc Di Luzio <marc.diluzio@gmail.com>
Date: Sat, 30 May 2020 22:53:28 +0100
Subject: [PATCH] Implement the integration test to check the status

---
 pkg/rove/rove.go | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/pkg/rove/rove.go b/pkg/rove/rove.go
index dae5c9c..5bdc42d 100644
--- a/pkg/rove/rove.go
+++ b/pkg/rove/rove.go
@@ -1,12 +1,19 @@
 package rove
 
+import (
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"net/url"
+)
+
 type Connection struct {
-	address string
+	host string
 }
 
-func NewConnection(address string) *Connection {
+func NewConnection(host string) *Connection {
 	return &Connection{
-		address: address,
+		host: host,
 	}
 }
 
@@ -15,6 +22,20 @@ type ServerStatus struct {
 	Ready bool `json:"ready"`
 }
 
-func (c *Connection) Status() ServerStatus {
-	return ServerStatus{}
+func (c *Connection) Status() (status ServerStatus, err error) {
+	url := url.URL{
+		Scheme: "http",
+		Host:   c.host,
+		Path:   "status",
+	}
+
+	if resp, err := http.Get(url.String()); err != nil {
+		return ServerStatus{}, err
+	} else if resp.StatusCode != http.StatusOK {
+		return ServerStatus{}, fmt.Errorf("Status request returned %d", resp.StatusCode)
+	} else {
+		err = json.NewDecoder(resp.Body).Decode(&status)
+	}
+
+	return
 }