packer-cn/builder/vsphere/driver/resource_pool_test.go

72 lines
2.0 KiB
Go
Raw Normal View History

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()
if err != nil {
t.Fatalf("should not fail: %s", err.Error())
}
2020-09-22 10:44:03 -04:00
defer sim.Close()
2020-09-22 10:44:03 -04:00
res, err := sim.driver.FindResourcePool("", "DC0_H0", "")
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)
if err != nil {
t.Fatalf("should not fail: %s", err.Error())
}
2020-09-22 10:44:03 -04:00
defer sim.Close()
2020-09-22 10:44:03 -04:00
res, err := sim.driver.FindResourcePool("", "localhost.localdomain", "")
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")
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())
}
}