Implement the integration test to check the status

This commit is contained in:
Marc Di Luzio 2020-05-30 22:53:28 +01:00
parent 5f358fa9fd
commit 346c59e5ee

View file

@ -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
}