-
Notifications
You must be signed in to change notification settings - Fork 62
/
example_guestprop_test.go
87 lines (71 loc) · 1.74 KB
/
example_guestprop_test.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package virtualbox_test
import (
"log"
"sync"
"time"
virtualbox "github.com/terra-farm/go-virtualbox"
)
var VM = "MyVM"
func ExampleSetGuestProperty() {
err := virtualbox.SetGuestProperty(VM, "test_name", "test_val")
if err != nil {
panic(err)
}
}
func ExampleGetGuestProperty() {
err := virtualbox.SetGuestProperty(VM, "test_name", "test_val")
if err != nil {
panic(err)
}
val, err := virtualbox.GetGuestProperty(VM, "test_name")
if err != nil {
panic(err)
}
log.Println("val:", val)
}
func ExampleDeleteGuestProperty() {
err := virtualbox.SetGuestProperty(VM, "test_name", "test_val")
if err != nil {
panic(err)
}
err = virtualbox.DeleteGuestProperty(VM, "test_name")
if err != nil {
panic(err)
}
}
func ExampleWaitGuestProperty() {
go func() {
second := time.Second
time.Sleep(1 * second)
_ = virtualbox.SetGuestProperty(VM, "test_name", "test_val")
}()
name, val, err := virtualbox.WaitGuestProperty(VM, "test_*")
if err != nil {
panic(err)
}
log.Println("name:", name, ", value:", val)
}
func ExampleWaitGuestProperties() {
go func() {
second := time.Second
time.Sleep(1 * second)
_ = virtualbox.SetGuestProperty(VM, "test_name", "test_val1")
time.Sleep(1 * second)
_ = virtualbox.SetGuestProperty(VM, "test_name", "test_val2")
time.Sleep(1 * second)
_ = virtualbox.SetGuestProperty(VM, "test_name", "test_val1")
}()
wg := new(sync.WaitGroup)
done := make(chan bool)
propsPattern := "test_*"
props := virtualbox.WaitGuestProperties(VM, propsPattern, done, wg)
ok := true
left := 3
for ; ok && left > 0; left-- {
var prop virtualbox.GuestProperty
prop, ok = <-props
log.Println("name:", prop.Name, ", value:", prop.Value)
}
close(done) // close channel
wg.Wait() // wait for gorouting
}