File: cli.bats

package info (click to toggle)
golang-github-vmware-govmomi 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,848 kB
  • sloc: sh: 2,285; lisp: 1,560; ruby: 948; xml: 139; makefile: 54
file content (215 lines) | stat: -rwxr-xr-x 4,613 bytes parent folder | download | duplicates (2)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env bats

load test_helper

@test "about" {
  vcsim_env -api-version uE53DA

  run govc about
  assert_success
  assert_line "Vendor: VMware, Inc."

  run env GOVC_TLS_HANDSHAKE_TIMEOUT=10s govc about
  assert_success
  assert_line "Vendor: VMware, Inc."

  run env GOVC_TLS_HANDSHAKE_TIMEOUT=NOT_A_DURATION govc about
  assert_failure

  run govc about -json
  assert_success

  run govc about -json -l
  assert_success

  run govc about -dump
  assert_success

  run govc about -dump -l
  assert_success

  version=$(govc about -json -c | jq -r .Client.Version)
  assert_equal 7.0 "$version" # govc's default version

  version=$(govc about -json -c -vim-version "" | jq -r .Client.Version)
  assert_equal uE53DA "$version" # vcsim's service version

  version=$(govc about -json -c -vim-version 6.8.2 | jq -r .Client.Version)
  assert_equal 6.8.2 "$version" # client specified version
}

@test "about.cert" {
  vcsim_env -esx

  run govc about.cert
  assert_success

  run govc about.cert -json
  assert_success

  run govc about.cert -show
  assert_success

  # with -k=true we get thumbprint output and exit 0
  thumbprint=$(govc about.cert -k=true -thumbprint)

  # with -k=true we get thumbprint output and exit 60
  run govc about.cert -k=false -thumbprint
  if [ "$status" -ne 60 ]; then
    flunk $(printf "expected failed exit status=60, got status=%d" $status)
  fi
  assert_output "$thumbprint"

  run govc about -k=false
  assert_failure

  run govc about -k=false -tls-known-hosts <(echo "$thumbprint")
  assert_success

  run govc about -k=false -tls-known-hosts <(echo "nope nope")
  assert_failure
}

@test "version" {
  vcsim_env -esx

  run govc version
  assert_success

  v=$(govc version | awk '{print $NF}')
  run govc version -require "$v"
  assert_success

  run govc version -require "not-a-version-string"
  assert_failure

  run govc version -require 100.0.0
  assert_failure
}

@test "login attempt without credentials" {
  vcsim_env -esx

  host=$(govc env -x GOVC_URL_HOST)
  port=$(govc env -x GOVC_URL_PORT)
  run govc about -u "enoent@$host:$port"
  assert_failure "govc: ServerFaultCode: Login failure"
}

@test "login attempt with GOVC_URL, GOVC_USERNAME, and GOVC_PASSWORD" {
  vcsim_env -esx

  govc_url_to_vars
  run govc about
  assert_success
}

@test "API version check" {
  vcsim_env -esx

  run env GOVC_MIN_API_VERSION=24.4 govc about
  assert grep -q "^govc: require API version \"24.4\"," <<<"${output}"

  run env GOVC_MIN_API_VERSION=no.no govc about
  assert_failure

  run env GOVC_MIN_API_VERSION=- govc about
  assert_success

  run env GOVC_MIN_API_VERSION=5.0 govc about
  assert_success

  run govc about -vim-namespace urn:vim25 -vim-version 6.0
  assert_success
}

@test "govc env" {
  output="$(govc env -x -u 'user:pass@enoent:99999?key=val#anchor')"
  assert grep -q GOVC_URL=enoent:99999 <<<${output}
  assert grep -q GOVC_USERNAME=user <<<${output}
  assert grep -q GOVC_PASSWORD=pass <<<${output}

  assert grep -q GOVC_URL_SCHEME=https <<<${output}
  assert grep -q GOVC_URL_HOST=enoent <<<${output}
  assert grep -q GOVC_URL_PORT=99999 <<<${output}
  assert grep -q GOVC_URL_PATH=/sdk <<<${output}
  assert grep -q GOVC_URL_QUERY=key=val <<<${output}
  assert grep -q GOVC_URL_FRAGMENT=anchor <<<${output}

  password="pa\$sword!ok"
  run govc env -u "user:${password}@enoent:99999" GOVC_PASSWORD
  assert_output "$password"
}

@test "govc help" {
  run govc
  assert_failure

  run govc -h
  assert_success
  assert_matches "Usage of govc:"

  run govc -enoent
  assert_failure

  run govc vm.create
  assert_failure

  run govc vm.create -h
  assert_success

  run govc vm.create -enoent
  assert_failure

  run govc nope
  assert_failure
  assert_matches "Usage of govc:"

  run govc power
  assert_failure
  assert_matches "did you mean:"
}

@test "govc format error" {
  vcsim_env

  vm=DC0_H0_VM0

  run govc vm.power -json -on $vm
  assert_failure
  jq . <<<"$output"

  run govc vm.power -xml -on $vm
  assert_failure
  if type xmlstarlet ; then
    xmlstarlet fo <<<"$output"
  fi

  run govc vm.power -dump -on $vm
  assert_failure
  gofmt <<<"$output"
}

@test "insecure cookies" {
  vcsim_start -tls=false

  run govc ls
  assert_success

  vcsim_stop

  VCSIM_SECURE_COOKIES=true vcsim_start -tls=false

  run govc ls
  assert_failure
  assert_matches NotAuthenticated # Go's cookiejar won't send Secure cookies if scheme != https

  vcsim_stop

  VCSIM_SECURE_COOKIES=true vcsim_start -tls=false

  run env GOVMOMI_INSECURE_COOKIES=true govc ls
  assert_success # soap.Client will set Cookie.Secure=false

  vcsim_stop
}