summaryrefslogtreecommitdiff
path: root/libvirt/utils_volume_test.go
diff options
context:
space:
mode:
authorThomas Hipp <thipp@suse.de>2017-08-10 12:48:55 +0200
committerFlavio Castelli <flavio@castelli.me>2017-08-11 14:42:24 +0200
commit7fbe405ecb15e4ab22da4a74368aafcc6b0c2ea8 (patch)
tree337160720552859360c190bf890cd0dc96f8297c /libvirt/utils_volume_test.go
parentb76cf35ad27d3f0e49684ea58920230ebd447883 (diff)
downloadterraform-provider-libvirt-7fbe405ecb15e4ab22da4a74368aafcc6b0c2ea8.tar
terraform-provider-libvirt-7fbe405ecb15e4ab22da4a74368aafcc6b0c2ea8.tar.gz
use libvirt-go-xml for volumes
Signed-off-by: Thomas Hipp <thipp@suse.de>
Diffstat (limited to 'libvirt/utils_volume_test.go')
-rw-r--r--libvirt/utils_volume_test.go36
1 files changed, 27 insertions, 9 deletions
diff --git a/libvirt/utils_volume_test.go b/libvirt/utils_volume_test.go
index 5d8188fb..577d6057 100644
--- a/libvirt/utils_volume_test.go
+++ b/libvirt/utils_volume_test.go
@@ -6,6 +6,9 @@ import (
"io/ioutil"
"os"
"testing"
+ "time"
+
+ "github.com/libvirt/libvirt-go-xml"
)
func TestLocalImageDownload(t *testing.T) {
@@ -24,7 +27,6 @@ func TestLocalImageDownload(t *testing.T) {
if err != nil {
t.Fatal(err)
}
-
url := fmt.Sprintf("file://%s", tmpfile.Name())
image, err := newImage(url)
if err != nil {
@@ -33,9 +35,8 @@ func TestLocalImageDownload(t *testing.T) {
t.Logf("Importing %s", url)
vol := newDefVolume()
- modTime := UnixTimestamp{tmpfileStat.ModTime()}
- vol.Target.Timestamps = &defTimestamps{
- Modification: &modTime,
+ vol.Target.Timestamps = &libvirtxml.StorageVolumeTargetTimestamps{
+ Mtime: fmt.Sprintf("%d.%d", tmpfileStat.ModTime().Unix(), tmpfileStat.ModTime().Nanosecond()),
}
copier := func(r io.Reader) error {
@@ -43,7 +44,7 @@ func TestLocalImageDownload(t *testing.T) {
return nil
}
if err = image.Import(copier, vol); err != nil {
- t.Fatal("Could not copy image from %s: %v", url, err)
+ t.Fatalf("Could not copy image from %s: %v", url, err)
}
t.Log("File not copied because modification time was the same")
}
@@ -72,17 +73,34 @@ func TestRemoteImageDownload(t *testing.T) {
t.Logf("Importing %s", url)
vol := newDefVolume()
- modTime := UnixTimestamp{tmpfileStat.ModTime()}
- vol.Target.Timestamps = &defTimestamps{
- Modification: &modTime,
+ vol.Target.Timestamps = &libvirtxml.StorageVolumeTargetTimestamps{
+ Mtime: fmt.Sprintf("%d.%d", tmpfileStat.ModTime().Unix(), tmpfileStat.ModTime().Nanosecond()),
}
copier := func(r io.Reader) error {
t.Fatalf("ERROR: starting copy of %s... but the file is the same!", url)
return nil
}
if err = image.Import(copier, vol); err != nil {
- t.Fatal("Could not copy image from %s: %v", url, err)
+ t.Fatalf("Could not copy image from %s: %v", url, err)
}
t.Log("File not copied because modification time was the same")
}
+
+func TestTimeFromEpoch(t *testing.T) {
+ if ts := timeFromEpoch(""); ts.UnixNano() > 0 {
+ t.Fatalf("expected timestamp '0.0', got %v.%v", ts.Unix(), ts.Nanosecond())
+ }
+
+ if ts := timeFromEpoch("abc"); ts.UnixNano() > 0 {
+ t.Fatalf("expected timestamp '0.0', got %v.%v", ts.Unix(), ts.Nanosecond())
+ }
+
+ if ts := timeFromEpoch("123"); ts.UnixNano() != time.Unix(123, 0).UnixNano() {
+ t.Fatalf("expected timestamp '123.0', got %v.%v", ts.Unix(), ts.Nanosecond())
+ }
+
+ if ts := timeFromEpoch("123.456"); ts.UnixNano() != time.Unix(123, 456).UnixNano() {
+ t.Fatalf("expected timestamp '123.456', got %v.%v", ts.Unix(), ts.Nanosecond())
+ }
+}