Commit 029dc401 authored by Yann KAISER's avatar Yann KAISER

Added tests for when host id or name is not specified or empty

parent 09354d66
......@@ -50,6 +50,10 @@ func dataSourceHostRead(d *schema.ResourceData, m interface{}) error {
request.SpecificName = &name
}
if *request.SpecificName == "" {
return fmt.Errorf("No host name was specified")
}
host, err = session.FetchHostByNameOrId(request)
if err != nil {
......
......@@ -281,16 +281,16 @@ func resourceVMCreate(d *schema.ResourceData, m interface{}) error {
datastoreID, hasDID := d.GetOk("datastore_id")
hostID, hasHID := d.GetOk("host_id")
if hasDID && hasHID {
if hasDID && hasHID && hostID != "" {
vmData.HostID = hostID.(int)
vmData.DatastoreID = datastoreID.(int)
} else {
if !hasDID {
return fmt.Errorf("You need to set a datastore_id")
}
hostList, err := session.FetchHostList()
if err != nil {
return err
hostList, herr := session.FetchHostList()
if herr != nil {
return herr
}
host := vm.BestHostSelection(hostList)
vmData.HostID = host.ID
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment