summaryrefslogtreecommitdiff
path: root/libvirt/volume_def_test.go
blob: 44ccf527be0992830480c7acfa799a146caf52eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package libvirt

import (
	"bytes"
	"encoding/xml"
	"testing"

	"github.com/davecgh/go-spew/spew"
)

func init() {
	spew.Config.Indent = "\t"
}

func TestVolumeUnmarshal(t *testing.T) {
	xmlDesc := `
	<volume type='file'>
	  <name>caasp_master.img</name>
	  <key>/home/user/.libvirt/images/image.img</key>
	  <source>
	  </source>
	  <capacity unit='bytes'>42949672960</capacity>
	  <allocation unit='bytes'>900800512</allocation>
	  <target>
	    <path>/home/user/.libvirt/images/image.img</path>
	    <format type='qcow2'/>
	    <permissions>
	      <mode>0644</mode>
	      <owner>480</owner>
	      <group>473</group>
	    </permissions>
	    <timestamps>
	      <atime>1488789260.012293492</atime>
	      <mtime>1488802938.454893390</mtime>
	      <ctime>1488802938.454893390</ctime>
	    </timestamps>
	  </target>
	  <backingStore>
	    <path>/home/user/.libvirt/images/image.img</path>
	    <format type='qcow2'/>
	    <permissions>
	      <mode>0644</mode>
	      <owner>480</owner>
	      <group>473</group>
	    </permissions>
	    <timestamps>
	      <atime>1488541864.606322102</atime>
	      <mtime>1488541858.638308597</mtime>
	      <ctime>1488541864.526321921</ctime>
	    </timestamps>
	  </backingStore>
	</volume>
	`

	_, err := newDefVolumeFromXML(xmlDesc)
	if err != nil {
		t.Fatalf("could not unmarshall volume definition:\n%s", err)
	}
}

func TestDefaultVolumeMarshall(t *testing.T) {
	b := newDefVolume()

	buf := new(bytes.Buffer)
	enc := xml.NewEncoder(buf)
	enc.Indent("  ", "    ")
	if err := enc.Encode(b); err != nil {
		t.Fatalf("could not marshall this:\n%s", spew.Sdump(b))
	}
}