-
Notifications
You must be signed in to change notification settings - Fork 908
/
ls.bats
executable file
·198 lines (148 loc) · 3.53 KB
/
ls.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env bats
load test_helper
@test "ls" {
vcsim_env
run govc ls
assert_success
# /dc/{vm,network,host,datastore}
n=${#lines[@]}
[ $n -ge 4 ]
run govc ls -json
assert_success
run govc ls -xml
assert_success
# list entire inventory
run govc ls '/**'
assert_success
[ ${#lines[@]} -ge $n ]
run govc ls ./...
assert_success
[ ${#lines[@]} -ge $n ]
run govc ls -t HostSystem '*'
assert_success
[ ${#lines[@]} -eq 0 ]
run govc ls host
assert_success
[ ${#lines[@]} -ge 1 ]
run govc ls enoent
assert_success
[ ${#lines[@]} -eq 0 ]
}
@test "ls -R" {
vcsim_env -esx
# search entire inventory
run govc ls ./...
assert_success
# should have at least 1 dc + folders, 1 host, 1 network, 1 datastore
[ ${#lines[@]} -ge 9 ]
run govc ls -t HostSystem ./...
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls -t Datacenter /...
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls -t ResourcePool host/...
assert_success
[ ${#lines[@]} -ge 1 ]
run govc ls -t ResourcePool vm/...
assert_success
[ ${#lines[@]} -eq 0 ]
c=$(govc ls -t ComputeResource ./... | head -1)
run govc ls -t ResourcePool "$c/..."
assert_success
[ ${#lines[@]} -ge 1 ]
}
@test "ls vm" {
vcsim_env -esx
vm=$(new_empty_vm)
run govc ls vm
assert_success
[ ${#lines[@]} -ge 1 ]
run govc ls vm/$vm
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls /*/vm/$vm
assert_success
[ ${#lines[@]} -eq 1 ]
}
@test "ls network" {
vcsim_env -esx
run govc ls network
assert_success
[ ${#lines[@]} -ge 1 ]
local path=${lines[0]}
run govc ls "$path"
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls "network/$(basename "$path")"
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls "/*/network/$(basename "$path")"
assert_success
[ ${#lines[@]} -eq 1 ]
}
@test "ls multi ds" {
vcsim_env -dc 2
run govc ls
assert_success
# /DC0/{vm,network,host,datastore}
[ ${#lines[@]} -eq 4 ]
run govc ls /DC*
assert_success
# /DC[0,1]/{vm,network,host,datastore}
[ ${#lines[@]} -eq 8 ]
# here 'vm' is relative to /DC0
run govc ls vm
assert_success
[ ${#lines[@]} -gt 0 ]
unset GOVC_DATACENTER
run govc ls
assert_success
# /DC[0,1]
[ ${#lines[@]} -eq 2 ]
run govc ls -dc enoent
assert_failure
[ ${#lines[@]} -gt 0 ]
# here 'vm' is relative to '/' - so there are no matches
run govc ls vm
assert_success
[ ${#lines[@]} -eq 0 ]
# ls all vms in all datacenters
run govc ls */vm
assert_success
[ ${#lines[@]} -gt 0 ]
}
@test "ls moref" {
vcsim_env -esx
# ensure the vm folder isn't empty
run govc vm.create -on=false "$(new_id)"
assert_success
# list dc folder paths
folders1=$(govc ls)
# list dc folder refs | govc ls -L ; should output the same paths
folders2=$(govc ls -i | xargs govc ls -L)
assert_equal "$folders1" "$folders2"
for folder in $folders1
do
# list paths in $folder
items1=$(govc ls "$folder")
# list refs in $folder | govc ls -L ; should output the same paths
items2=$(govc ls -i "$folder" | $xargs -d '\n' govc ls -L)
assert_equal "$items1" "$items2"
done
ref=ViewManager:ViewManager
path=$(govc ls -L $ref)
assert_equal "$ref" "$path"
path=$(govc ls -L Folder:ha-folder-root)
assert_equal "/" "$path"
}
@test "ls substr" {
# Test fix for issue #815, introduced by b35abbc
vcsim_env
id=$(new_id)
run govc vm.create -on=false "${id}"
assert_success
run govc vm.create -on=false "bar${id}"
assert_success
assert [ "$(govc ls "vm/$id" | wc -l)" -eq 1 ]
}