summaryrefslogtreecommitdiff
path: root/xenstoreclient/xenstore_test.go
diff options
context:
space:
mode:
authorzheng <Zheng.chai@citrix.com>2015-05-19 08:49:57 +0100
committerzheng <Zheng.chai@citrix.com>2015-05-19 08:49:57 +0100
commit2fb5afbd442e35a6e0ba3bd57a04e0bd58c7c213 (patch)
tree158e65bf08b638bff6375baeb2d13fda16667196 /xenstoreclient/xenstore_test.go
parent2c85890a25bff9f327ea95018c541c1190267492 (diff)
parent75bc98ab536804963551416a4206ec8c43ebcc34 (diff)
downloadvyos-xe-guest-utilities-2fb5afbd442e35a6e0ba3bd57a04e0bd58c7c213.tar.gz
vyos-xe-guest-utilities-2fb5afbd442e35a6e0ba3bd57a04e0bd58c7c213.zip
Merge pull request #1 from xs-nanjing/master
CP-11399: Go Linux guest agent for XenServer
Diffstat (limited to 'xenstoreclient/xenstore_test.go')
-rw-r--r--xenstoreclient/xenstore_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/xenstoreclient/xenstore_test.go b/xenstoreclient/xenstore_test.go
new file mode 100644
index 0000000..1259447
--- /dev/null
+++ b/xenstoreclient/xenstore_test.go
@@ -0,0 +1,60 @@
+package xenstoreclient
+
+import (
+ "bytes"
+ "testing"
+)
+
+type mockFile struct {
+ t *testing.T
+}
+
+func (f *mockFile) Read(b []byte) (n int, err error) {
+ value := "i am value"
+ p := &Packet{
+ OpCode: XS_READ,
+ Req: 0,
+ TxID: 0,
+ Length: uint32(len(value)),
+ Value: []byte(value),
+ }
+ var buf bytes.Buffer
+ if err = p.Write(&buf); err != nil {
+ return 0, err
+ }
+ copy(b, buf.Bytes())
+ n = buf.Len()
+ f.t.Logf("Read %d bytes", n)
+ return n, nil
+}
+
+func (f *mockFile) Write(b []byte) (n int, err error) {
+ buf := bytes.NewBuffer(b)
+ if _, err := ReadPacket(buf); err != nil {
+ return 0, err
+ }
+ n = len(b)
+ f.t.Logf("Write %d bytes", n)
+ return n, nil
+}
+
+func (f *mockFile) Close() error {
+ f.t.Logf("Close()")
+ return nil
+}
+
+func TestXenStore(t *testing.T) {
+ xs, err := newXenstore(0, &mockFile{t})
+ if err != nil {
+ t.Errorf("newXenstore error: %#v\n", err)
+ }
+ defer xs.Close()
+
+ if _, err := xs.Read("foo"); err != nil {
+ t.Errorf("xs.Read error: %#v\n", err)
+ }
+
+ if err := xs.Write("foo", "bar"); err != nil {
+ t.Errorf("xs.Read error: %#v\n", err)
+ }
+}