File: datacenter.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 (70 lines) | stat: -rwxr-xr-x 1,534 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
#!/usr/bin/env bats

load test_helper

@test "datacenter.info" {
  vcsim_env -esx

  dc=$(govc ls -t Datacenter / | head -n1)
  run govc datacenter.info "$dc"
  assert_success

  run govc datacenter.info -json "$dc"
  assert_success

  run govc datacenter.info /enoent
  assert_failure
}

@test "datacenter.info with folders" {
  vcsim_start -cluster 3 -folder 1

  info=$(govc datacenter.info DC0)

  hosts=$(govc find -type h | wc -l)
  clusters=$(govc find -type c | wc -l)
  vms=$(govc find -type m | wc -l)
  datastores=$(govc find -type s | wc -l)


  assert_equal "$hosts" "$(grep Hosts: <<<"$info" | awk '{print $2}')"
  assert_equal "$clusters" "$(grep Clusters: <<<"$info" | awk '{print $2}')"
  assert_equal "$vms" "$(grep "Virtual Machines": <<<"$info" | awk '{print $3}')"
  assert_equal "$datastores" "$(grep Datastores: <<<"$info" | awk '{print $2}')"
}

@test "datacenter.create" {
  vcsim_env
  unset GOVC_DATACENTER

  # name not specified
  run govc datacenter.create
  assert_failure

  dcs=($(new_id) $(new_id))
  run govc datacenter.create "${dcs[@]}"
  assert_success

  for dc in ${dcs[*]}; do
    run govc ls "/$dc"
    assert_success
    # /<datacenter>/{vm,network,host,datastore}
    [ ${#lines[@]} -eq 4 ]

    run govc datacenter.info "/$dc"
    assert_success
  done

  run govc object.destroy "/$dc"
  assert_success
}

@test "datacenter commands fail against ESX" {
  vcsim_env -esx

  run govc datacenter.create something
  assert_failure

  run govc object.destroy /ha-datacenter
  assert_failure
}