summaryrefslogtreecommitdiff
path: root/guestmetric/guestmetric_test.go
diff options
context:
space:
mode:
authorPhus Lu <phuslu@hotmail.com>2015-04-24 16:37:17 +0800
committerZheng Chai <zheng.chai@citrix.com>2015-05-14 17:30:24 +0800
commit75bc98ab536804963551416a4206ec8c43ebcc34 (patch)
tree158e65bf08b638bff6375baeb2d13fda16667196 /guestmetric/guestmetric_test.go
parent2c85890a25bff9f327ea95018c541c1190267492 (diff)
downloadvyos-xe-guest-utilities-75bc98ab536804963551416a4206ec8c43ebcc34.tar.gz
vyos-xe-guest-utilities-75bc98ab536804963551416a4206ec8c43ebcc34.zip
CP-11399: Go Linux guest agent for XenServer
This is the reviewed and tested Go guest agent for XenServer Linux guests. Go guest agent is a static linked binary without any dependency (e.g. Bash or Python execution environment) with below benefits: 1. Cross platform, Go version works well with all kinds Linux distributions (i386 and x86_64) with the porting ability to arm, FreeBSD, Darwin OS etc. 2. Standalone binary, works well with some restricted environment for example, CoreOS and Boot2Docker Linux 3. Easy to maintain and structured design, with Golang's nature Change history: 1: Refined Rob Robert's comments. 2: Add unit test for xenstoreclient and refact folder structure. 3: Refined codes according to Robert's comments 4: To run 32bit xe-guest-agent in Linux 64bit OS(eg, CoreOS): we need 4.1 - Switch to ip/ifconfig CLI tool instead of net package 4.2 - Switch to log package instead of syslog package Signed-off-by: phus lu <phus.lu@citrix.com>
Diffstat (limited to 'guestmetric/guestmetric_test.go')
-rw-r--r--guestmetric/guestmetric_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/guestmetric/guestmetric_test.go b/guestmetric/guestmetric_test.go
new file mode 100644
index 0000000..dcc5384
--- /dev/null
+++ b/guestmetric/guestmetric_test.go
@@ -0,0 +1,63 @@
+package guestmetric
+
+import (
+ "testing"
+)
+
+func TestCollector(t *testing.T) {
+ c := Collector{
+ Client: nil,
+ }
+
+ funcs := []CollectFunc{
+ c.CollectDisk,
+ c.CollectMemory,
+ c.CollectMisc,
+ c.CollectNetworkAddr,
+ }
+
+ for _, f := range funcs {
+ metric, err := f()
+ if err != nil {
+ t.Errorf("%#v error: %#v\n", f, err)
+ }
+ t.Logf("%#v return %#v", f, metric)
+ }
+}
+
+func doBenchmark(b *testing.B, f CollectFunc) {
+ b.Logf("doBenchmark 1000 for %#v", f)
+ for i := 0; i < 1000; i++ {
+ if _, err := f(); err != nil {
+ b.Errorf("%#v error: %#v\n", f, err)
+ }
+ }
+}
+
+func BenchmarkCollectorDisk(b *testing.B) {
+ c := Collector{
+ Client: nil,
+ }
+ doBenchmark(b, c.CollectDisk)
+}
+
+func BenchmarkCollectMemory(b *testing.B) {
+ c := Collector{
+ Client: nil,
+ }
+ doBenchmark(b, c.CollectMemory)
+}
+
+func BenchmarkCollectMisc(b *testing.B) {
+ c := Collector{
+ Client: nil,
+ }
+ doBenchmark(b, c.CollectMisc)
+}
+
+func BenchmarkCollectNetwork(b *testing.B) {
+ c := Collector{
+ Client: nil,
+ }
+ doBenchmark(b, c.CollectNetworkAddr)
+}