github.com/vmware/govmomi@v0.37.2/govc/test/datacenter.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load test_helper
     4  
     5  @test "datacenter.info" {
     6    vcsim_env -esx
     7  
     8    dc=$(govc ls -t Datacenter / | head -n1)
     9    run govc datacenter.info "$dc"
    10    assert_success
    11  
    12    run govc datacenter.info -json "$dc"
    13    assert_success
    14  
    15    run govc datacenter.info /enoent
    16    assert_failure
    17  }
    18  
    19  @test "datacenter.info with folders" {
    20    vcsim_start -cluster 3 -folder 1
    21  
    22    info=$(govc datacenter.info DC0)
    23  
    24    hosts=$(govc find -type h | wc -l)
    25    clusters=$(govc find -type c | wc -l)
    26    vms=$(govc find -type m | wc -l)
    27    datastores=$(govc find -type s | wc -l)
    28  
    29  
    30    assert_equal "$hosts" "$(grep Hosts: <<<"$info" | awk '{print $2}')"
    31    assert_equal "$clusters" "$(grep Clusters: <<<"$info" | awk '{print $2}')"
    32    assert_equal "$vms" "$(grep "Virtual Machines": <<<"$info" | awk '{print $3}')"
    33    assert_equal "$datastores" "$(grep Datastores: <<<"$info" | awk '{print $2}')"
    34  }
    35  
    36  @test "datacenter.create" {
    37    vcsim_env
    38    unset GOVC_DATACENTER
    39  
    40    # name not specified
    41    run govc datacenter.create
    42    assert_failure
    43  
    44    dcs=($(new_id) $(new_id))
    45    run govc datacenter.create "${dcs[@]}"
    46    assert_success
    47  
    48    for dc in ${dcs[*]}; do
    49      run govc ls "/$dc"
    50      assert_success
    51      # /<datacenter>/{vm,network,host,datastore}
    52      [ ${#lines[@]} -eq 4 ]
    53  
    54      run govc datacenter.info "/$dc"
    55      assert_success
    56    done
    57  
    58    run govc object.destroy "/$dc"
    59    assert_success
    60  }
    61  
    62  @test "datacenter commands fail against ESX" {
    63    vcsim_env -esx
    64  
    65    run govc datacenter.create something
    66    assert_failure
    67  
    68    run govc object.destroy /ha-datacenter
    69    assert_failure
    70  }