2020-08-31 10:26:48 -04:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/vmware/govmomi/simulator"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestVCenterDriver_FindResourcePool(t *testing.T) {
|
2020-09-22 10:44:03 -04:00
|
|
|
sim, err := NewVCenterSimulator()
|
2020-08-31 10:26:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not fail: %s", err.Error())
|
|
|
|
}
|
2020-09-22 10:44:03 -04:00
|
|
|
defer sim.Close()
|
2020-08-31 10:26:48 -04:00
|
|
|
|
2020-09-22 10:44:03 -04:00
|
|
|
res, err := sim.driver.FindResourcePool("", "DC0_H0", "")
|
2020-08-31 10:26:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not fail: %s", err.Error())
|
|
|
|
}
|
|
|
|
if res == nil {
|
|
|
|
t.Fatalf("resource pool should not be nil")
|
|
|
|
}
|
|
|
|
expectedResourcePool := "Resources"
|
|
|
|
if res.pool.Name() != expectedResourcePool {
|
|
|
|
t.Fatalf("resource name expected %s but was %s", expectedResourcePool, res.pool.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVCenterDriver_FindResourcePoolStandaloneESX(t *testing.T) {
|
|
|
|
// standalone ESX host without any vCenter
|
|
|
|
model := simulator.ESX()
|
|
|
|
defer model.Remove()
|
|
|
|
|
|
|
|
opts := simulator.VPX()
|
|
|
|
model.Datastore = opts.Datastore
|
|
|
|
model.Machine = opts.Machine
|
|
|
|
model.Autostart = opts.Autostart
|
|
|
|
model.DelayConfig.Delay = opts.DelayConfig.Delay
|
|
|
|
model.DelayConfig.MethodDelay = opts.DelayConfig.MethodDelay
|
|
|
|
model.DelayConfig.DelayJitter = opts.DelayConfig.DelayJitter
|
|
|
|
|
2020-09-22 10:44:03 -04:00
|
|
|
sim, err := NewCustomVCenterSimulator(model)
|
2020-08-31 10:26:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not fail: %s", err.Error())
|
|
|
|
}
|
2020-09-22 10:44:03 -04:00
|
|
|
defer sim.Close()
|
2020-08-31 10:26:48 -04:00
|
|
|
|
2020-09-22 10:44:03 -04:00
|
|
|
res, err := sim.driver.FindResourcePool("", "localhost.localdomain", "")
|
2020-08-31 10:26:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not fail: %s", err.Error())
|
|
|
|
}
|
|
|
|
if res == nil {
|
|
|
|
t.Fatalf("resource pool should not be nil")
|
|
|
|
}
|
|
|
|
expectedResourcePool := "Resources"
|
|
|
|
if res.pool.Name() != expectedResourcePool {
|
|
|
|
t.Fatalf("resource name expected %s but was %s", expectedResourcePool, res.pool.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid resource name should look for default resource pool
|
2020-09-22 10:44:03 -04:00
|
|
|
res, err = sim.driver.FindResourcePool("", "localhost.localdomain", "invalid")
|
2020-08-31 10:26:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not fail: %s", err.Error())
|
|
|
|
}
|
|
|
|
if res == nil {
|
|
|
|
t.Fatalf("resource pool should not be nil")
|
|
|
|
}
|
|
|
|
if res.pool.Name() != expectedResourcePool {
|
|
|
|
t.Fatalf("resource name expected %s but was %s", expectedResourcePool, res.pool.Name())
|
|
|
|
}
|
|
|
|
}
|