forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.bats
executable file
·88 lines (65 loc) · 1.66 KB
/
events.bats
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
88
#!/usr/bin/env bats
load test_helper
@test "events dc" {
vcsim_env
run govc events
assert_success
nevents=${#lines[@]}
# there should be plenty more than 1 event at the top (dc) level
[ $nevents -ge 1 ]
# test -n flag
run govc events -n $((nevents - 1))
assert_success
[ ${#lines[@]} -le $nevents ]
}
@test "events host" {
vcsim_env -esx
run govc events 'host/*'
assert_success
[ ${#lines[@]} -ge 1 ]
}
@test "events vm" {
esx_env
vm=$(new_id)
run govc vm.create -on=false $vm
assert_success
run govc events vm/$vm
assert_success
nevents=${#lines[@]}
[ $nevents -gt 1 ]
# glob should have same # of events
run govc events vm/${vm}*
assert_success
[ ${#lines[@]} -eq $nevents ]
# create a new vm, glob should match more events
run govc vm.create -on=false "${vm}-2"
assert_success
run govc events vm/${vm}*
assert_success
[ ${#lines[@]} -gt $nevents ]
nevents=${#lines[@]}
run govc events vm
assert_success
[ ${#lines[@]} -ge $nevents ]
run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
[ ${#lines[@]} -eq 0 ]
run govc vm.power -on "$vm"
assert_success
run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
[ ${#lines[@]} -eq 1 ]
run govc vm.power -off "$vm"
assert_success
run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
[ ${#lines[@]} -eq 2 ]
}
@test "events json" {
esx_env
# make sure we fmt.Printf properly
govc events | grep -v '%!s(MISSING)'
govc events -json | jq .
# test multiple objects
govc vm.create "$(new_id)"
govc vm.create "$(new_id)"
govc events 'vm/*'
govc events -json 'vm/*' | jq .
}