Added tests for draining. run go test with a aurora vagrant image running to test.
This commit is contained in:
parent
7db2395df1
commit
430764f025
2 changed files with 49 additions and 7 deletions
|
@ -187,7 +187,6 @@ func (m *Monitor) HostMaintenance(hosts []string, modes []aurora.MaintenanceMode
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(hostMode) == 0 {
|
if len(hostMode) == 0 {
|
||||||
fmt.Println("Provided hosts have all entered desired state(s)")
|
|
||||||
return true, nil
|
return true, nil
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%d host(s) not in desired state\n", len(hostMode))
|
fmt.Printf("%d host(s) not in desired state\n", len(hostMode))
|
||||||
|
|
|
@ -16,8 +16,8 @@ package realis_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
|
||||||
"github.com/rdelval/gorealis"
|
"github.com/rdelval/gorealis"
|
||||||
|
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -26,6 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var r realis.Realis
|
var r realis.Realis
|
||||||
|
var monitor *realis.Monitor
|
||||||
var thermosPayload []byte
|
var thermosPayload []byte
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -42,6 +43,9 @@ func TestMain(m *testing.M) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create monitor
|
||||||
|
monitor = &realis.Monitor{r}
|
||||||
|
|
||||||
thermosPayload, err = ioutil.ReadFile("examples/thermos_payload.json")
|
thermosPayload, err = ioutil.ReadFile("examples/thermos_payload.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error reading thermos payload file: ", err)
|
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()))
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue