2017-11-13 16:02:46 -05:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
2019-01-04 16:55:04 -05:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2017-11-13 16:02:46 -05:00
|
|
|
"testing"
|
2019-01-04 16:55:04 -05:00
|
|
|
"time"
|
2017-11-13 16:02:46 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDatastoreAcc(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-11-13 16:02:46 -05:00
|
|
|
d := newTestDriver(t)
|
2018-03-20 19:03:47 -04:00
|
|
|
ds, err := d.FindDatastore("datastore1", "")
|
2017-11-13 16:02:46 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot find the default datastore '%v': %v", "datastore1", err)
|
|
|
|
}
|
|
|
|
info, err := ds.Info("name")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read datastore properties: %v", err)
|
|
|
|
}
|
|
|
|
if info.Name != "datastore1" {
|
|
|
|
t.Errorf("Wrong datastore. expected: 'datastore1', got: '%v'", info.Name)
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 16:55:04 -05:00
|
|
|
|
|
|
|
func TestFileUpload(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2019-01-04 16:55:04 -05:00
|
|
|
dsName := "datastore1"
|
|
|
|
hostName := "esxi-1.vsphere65.test"
|
|
|
|
|
|
|
|
fileName := fmt.Sprintf("test-%v", time.Now().Unix())
|
|
|
|
tmpFile, err := ioutil.TempFile("", fileName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating temp file")
|
|
|
|
}
|
|
|
|
err = tmpFile.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating temp file")
|
|
|
|
}
|
|
|
|
|
|
|
|
d := newTestDriver(t)
|
|
|
|
ds, err := d.FindDatastore(dsName, hostName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot find datastore '%v': %v", dsName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ds.UploadFile(tmpFile.Name(), fileName, hostName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot upload file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ds.FileExists(fileName) != true {
|
|
|
|
t.Fatalf("Cannot find file")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ds.Delete(fileName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot delete file: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFileUploadDRS(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2019-01-04 16:55:04 -05:00
|
|
|
dsName := "datastore3"
|
|
|
|
hostName := ""
|
|
|
|
|
|
|
|
fileName := fmt.Sprintf("test-%v", time.Now().Unix())
|
|
|
|
tmpFile, err := ioutil.TempFile("", fileName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating temp file")
|
|
|
|
}
|
|
|
|
err = tmpFile.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating temp file")
|
|
|
|
}
|
|
|
|
|
|
|
|
d := newTestDriver(t)
|
|
|
|
ds, err := d.FindDatastore(dsName, hostName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot find datastore '%v': %v", dsName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ds.UploadFile(tmpFile.Name(), fileName, hostName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot upload file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ds.FileExists(fileName) != true {
|
|
|
|
t.Fatalf("Cannot find file")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ds.Delete(fileName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot delete file: %v", err)
|
|
|
|
}
|
|
|
|
}
|