File: extension.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 (73 lines) | stat: -rwxr-xr-x 1,776 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env bats

load test_helper

@test "extension" {
  vcsim_env_todo

  govc extension.info | grep Name: | grep govc-test | awk '{print $2}' | $xargs -r govc extension.unregister

  run govc extension.info enoent
  assert_failure

  id=$(new_id)

  result=$(govc extension.info | grep $id | wc -l)
  [ $result -eq 0 ]

  # register extension
  run govc extension.register $id <<EOS
  {
    "Description": {
      "Label": "govc",
      "Summary": "Go interface to vCenter"
    },
    "Key": "${id}",
    "Company": "VMware, Inc.",
    "Version": "0.2.0"
  }
EOS
  assert_success

  # check info output is legit
  run govc extension.info $id
  assert_line "Name: $id"

  json=$(govc extension.info -json $id)
  label=$(jq -r .Extensions[].Description.Label <<<"$json")
  assert_equal "govc" "$label"

  # change label and update extension
  json=$(jq -r '.Extensions[] | .Description.Label = "novc"' <<<"$json")
  run govc extension.register -update $id <<<"$json"
  assert_success

  # check label changed in info output
  json=$(govc extension.info -json $id)
  label=$(jq -r .Extensions[].Description.Label <<<"$json")
  assert_equal "novc" "$label"

  # set extension certificate to generated certificate
  run govc extension.setcert -cert-pem '+' $id
  assert_success

  # test client certificate authentication
  (
    # remove password from env, set user to extension id and turn of session cache
    govc_url_to_vars
    unset GOVC_PASSWORD
    GOVC_USERNAME=$id
    export GOVC_PERSIST_SESSION=false
    run govc about -cert "${id}.crt" -key "${id}.key"
    assert_success
  )

  # remove generated cert and key
  rm ${id}.{crt,key}

  run govc extension.unregister $id
  assert_success

  result=$(govc extension.info | grep $id | wc -l)
  [ $result -eq 0 ]
}