Added tests for draining. run go test with a aurora vagrant image running to test.

This commit is contained in:
Renan DelValle 2017-09-28 17:49:15 -07:00
parent 7db2395df1
commit 430764f025
2 changed files with 49 additions and 7 deletions

View file

@ -187,7 +187,6 @@ func (m *Monitor) HostMaintenance(hosts []string, modes []aurora.MaintenanceMode
}
if len(hostMode) == 0 {
fmt.Println("Provided hosts have all entered desired state(s)")
return true, nil
} else {
fmt.Printf("%d host(s) not in desired state\n", len(hostMode))

View file

@ -16,8 +16,8 @@ package realis_test
import (
"fmt"
"github.com/rdelval/gorealis/gen-go/apache/aurora"
"github.com/rdelval/gorealis"
"github.com/rdelval/gorealis/gen-go/apache/aurora"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
@ -26,6 +26,7 @@ import (
)
var r realis.Realis
var monitor *realis.Monitor
var thermosPayload []byte
func TestMain(m *testing.M) {
@ -42,6 +43,9 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
// Create monitor
monitor = &realis.Monitor{r}
thermosPayload, err = ioutil.ReadFile("examples/thermos_payload.json")
if err != nil {
fmt.Println("Error reading thermos payload file: ", err)
@ -148,3 +152,42 @@ func TestRealisClient_ScheduleCronJob_Thermos(t *testing.T) {
fmt.Printf("Deschedule cron call took %d ns\n", (end.UnixNano() - start.UnixNano()))
})
}
func TestRealisClient_DrainHosts(t *testing.T) {
hosts := []string{"192.168.33.7"}
_, _ , err := r.DrainHosts(hosts...)
if err != nil {
fmt.Printf("error: %+v\n", err.Error())
os.Exit(1)
}
// Monitor change to DRAINING and DRAINED mode
_, err = monitor.HostMaintenance(
hosts,
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED, aurora.MaintenanceMode_DRAINING},
5,
10)
if err != nil {
fmt.Printf("error: %+v\n", err.Error())
os.Exit(1)
}
t.Run("TestRealisClient_EndMaintenance", func(t *testing.T) {
_, _ , err := r.EndMaintenance(hosts...)
if err != nil {
fmt.Printf("error: %+v\n", err.Error())
os.Exit(1)
}
// Monitor change to DRAINING and DRAINED mode
_, err = monitor.HostMaintenance(
hosts,
[]aurora.MaintenanceMode{aurora.MaintenanceMode_NONE},
5,
10)
if err != nil {
fmt.Printf("error: %+v\n", err.Error())
os.Exit(1)
}
})
}