Allow the test client parameters to be set via environment variables
This commit is contained in:
parent
84e0ad321f
commit
0b9457e2a7
|
@ -1,15 +1,45 @@
|
||||||
package rapi
|
package rapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClientInitialization(t *testing.T) {
|
func getTestClient(t *testing.T) *Client {
|
||||||
NewClient("test", "test123", "ganeti.test", 5080, 2)
|
username := os.Getenv("RAPI_USERNAME")
|
||||||
|
if len(username) == 0 {
|
||||||
|
username = "test"
|
||||||
|
}
|
||||||
|
password := os.Getenv("RAPI_PASSWORD")
|
||||||
|
if len(password) == 0 {
|
||||||
|
password = "test"
|
||||||
|
}
|
||||||
|
host := os.Getenv("RAPI_HOST")
|
||||||
|
if len(host) == 0 {
|
||||||
|
host = "ganeti.burntworld.test"
|
||||||
|
}
|
||||||
|
port := os.Getenv("RAPI_PORT")
|
||||||
|
if len(port) == 0 {
|
||||||
|
port = "5080"
|
||||||
|
}
|
||||||
|
version := os.Getenv("RAPI_VERSION")
|
||||||
|
if len(version) == 0 {
|
||||||
|
version = "2"
|
||||||
|
}
|
||||||
|
_port, port_error := strconv.Atoi(port)
|
||||||
|
if port_error != nil {
|
||||||
|
t.Errorf("Failed to convert client port '%v' to integer: %v", port, port_error)
|
||||||
|
}
|
||||||
|
_version, version_error := strconv.Atoi(version)
|
||||||
|
if version_error != nil {
|
||||||
|
t.Errorf("Failed to convert '%v' to integer: %v", version, version_error)
|
||||||
|
}
|
||||||
|
return NewClient(username, password, host, _port, _version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClusterInfo(t *testing.T) {
|
func TestClusterInfo(t *testing.T) {
|
||||||
c := NewClient("test", "test123", "ganeti.test", 5080, 2)
|
c := getTestClient(t)
|
||||||
_, err := c.GetClusterInformation()
|
_, err := c.GetClusterInformation()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error requesting cluster info %s", err)
|
t.Errorf("Got error requesting cluster info %s", err)
|
||||||
|
@ -17,7 +47,7 @@ func TestClusterInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetNetworks(t *testing.T) {
|
func TestGetNetworks(t *testing.T) {
|
||||||
c := NewClient("test", "test123", "ganeti.test", 5080, 2)
|
c := getTestClient(t)
|
||||||
_, err := c.GetNetworks()
|
_, err := c.GetNetworks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error requesting network list %s", err)
|
t.Errorf("Got error requesting network list %s", err)
|
||||||
|
@ -25,7 +55,7 @@ func TestGetNetworks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetNetworksBulk(t *testing.T) {
|
func TestGetNetworksBulk(t *testing.T) {
|
||||||
c := NewClient("test", "test123", "ganeti.test", 5080, 2)
|
c := getTestClient(t)
|
||||||
_, err := c.GetNetworksBulk()
|
_, err := c.GetNetworksBulk()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error requesting network list %s", err)
|
t.Errorf("Got error requesting network list %s", err)
|
||||||
|
@ -33,7 +63,7 @@ func TestGetNetworksBulk(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetNetworkInformation(t *testing.T) {
|
func TestGetNetworkInformation(t *testing.T) {
|
||||||
c := NewClient("test", "test123", "ganeti.test", 5080, 2)
|
c := getTestClient(t)
|
||||||
n, err := c.GetNetworks()
|
n, err := c.GetNetworks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error requesting network list %s", err)
|
t.Errorf("Got error requesting network list %s", err)
|
||||||
|
|
Loading…
Reference in New Issue