Implement the integration test to check the status
This commit is contained in:
parent
5f358fa9fd
commit
346c59e5ee
1 changed files with 26 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue