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

     1  #!/usr/bin/env bats
     2  
     3  load test_helper
     4  
     5  @test "about" {
     6    vcsim_env -api-version uE53DA
     7  
     8    run govc about
     9    assert_success
    10    assert_line "Vendor: VMware, Inc."
    11  
    12    run env GOVC_TLS_HANDSHAKE_TIMEOUT=10s govc about
    13    assert_success
    14    assert_line "Vendor: VMware, Inc."
    15  
    16    run env GOVC_TLS_HANDSHAKE_TIMEOUT=NOT_A_DURATION govc about
    17    assert_failure
    18  
    19    run govc about -json
    20    assert_success
    21  
    22    run govc about -json -l
    23    assert_success
    24  
    25    run govc about -dump
    26    assert_success
    27  
    28    run govc about -dump -l
    29    assert_success
    30  
    31    version=$(govc about -json -c | jq -r .client.version)
    32    assert_equal 8.0.2.0 "$version" # govc's default version
    33  
    34    version=$(govc about -json -c -vim-version "" | jq -r .client.version)
    35    assert_equal uE53DA "$version" # vcsim's service version
    36  
    37    version=$(govc about -json -c -vim-version 6.8.2 | jq -r .client.version)
    38    assert_equal 6.8.2 "$version" # client specified version
    39  
    40    run govc about -trace
    41    assert_success
    42  
    43    run env GOVC_DEBUG_FORMAT=false govc about -trace
    44    assert_success
    45  
    46    run env GOVC_DEBUG_XML=enoent GOVC_DEBUG_JSON=enoent govc library.ls -trace
    47    assert_success
    48  }
    49  
    50  @test "about.cert" {
    51    vcsim_env -esx
    52  
    53    run govc about.cert
    54    assert_success
    55  
    56    run govc about.cert -json
    57    assert_success
    58  
    59    run govc about.cert -show
    60    assert_success
    61  
    62    # with -k=true we get sha256 thumbprint output and exit 0
    63    thumbprint=$(govc about.cert -k=true -thumbprint)
    64  
    65    # with -k=true we get thumbprint output and exit 60
    66    run govc about.cert -k=false -thumbprint
    67    if [ "$status" -ne 60 ]; then
    68      flunk $(printf "expected failed exit status=60, got status=%d" $status)
    69    fi
    70    assert_output "$thumbprint"
    71  
    72    run govc about -k=false
    73    assert_failure
    74  
    75    run govc about -k=false -tls-known-hosts <(echo "$thumbprint")
    76    assert_success
    77  
    78    run govc about -k=false -tls-known-hosts <(echo "nope nope")
    79    assert_failure
    80  
    81    # sha1 backwards compatibility
    82    host=$(awk '{print $1}'<<<"$thumbprint")
    83    sha1=$(govc about.cert -k=true -json | jq -r .thumbprintSHA1)
    84    run govc about -k=false -tls-known-hosts <(echo "$host $sha1")
    85    assert_success
    86  }
    87  
    88  @test "version" {
    89    vcsim_env -esx
    90  
    91    run govc version
    92    assert_success
    93  
    94    v=$(govc version | awk '{print $NF}')
    95    run govc version -require "$v"
    96    assert_success
    97  
    98    run govc version -require "not-a-version-string"
    99    assert_failure
   100  
   101    run govc version -require 100.0.0
   102    assert_failure
   103  }
   104  
   105  @test "login attempt without credentials" {
   106    vcsim_env -esx
   107  
   108    host=$(govc env -x GOVC_URL_HOST)
   109    port=$(govc env -x GOVC_URL_PORT)
   110    run govc about -u "enoent@$host:$port"
   111    assert_failure "govc: ServerFaultCode: Login failure"
   112  }
   113  
   114  @test "login attempt with GOVC_URL, GOVC_USERNAME, and GOVC_PASSWORD" {
   115    vcsim_env -esx
   116  
   117    govc_url_to_vars
   118    run govc about
   119    assert_success
   120  }
   121  
   122  @test "API version check" {
   123    vcsim_env -esx
   124  
   125    run env GOVC_MIN_API_VERSION=24.4 govc about
   126    assert grep -q "^govc: require API version \"24.4\"," <<<"${output}"
   127  
   128    run env GOVC_MIN_API_VERSION=no.no govc about
   129    assert_failure
   130  
   131    run env GOVC_MIN_API_VERSION=- govc about
   132    assert_success
   133  
   134    run env GOVC_MIN_API_VERSION=5.0 govc about
   135    assert_success
   136  
   137    run govc about -vim-namespace urn:vim25 -vim-version 6.0
   138    assert_success
   139  }
   140  
   141  @test "govc env" {
   142    output="$(govc env -x -u 'user:pass@enoent:99999?key=val#anchor')"
   143    assert grep -q GOVC_URL=enoent:99999 <<<${output}
   144    assert grep -q GOVC_USERNAME=user <<<${output}
   145    assert grep -q GOVC_PASSWORD=pass <<<${output}
   146  
   147    assert grep -q GOVC_URL_SCHEME=https <<<${output}
   148    assert grep -q GOVC_URL_HOST=enoent <<<${output}
   149    assert grep -q GOVC_URL_PORT=99999 <<<${output}
   150    assert grep -q GOVC_URL_PATH=/sdk <<<${output}
   151    assert grep -q GOVC_URL_QUERY=key=val <<<${output}
   152    assert grep -q GOVC_URL_FRAGMENT=anchor <<<${output}
   153  
   154    password="pa\$sword!ok"
   155    run govc env -u "user:${password}@enoent:99999" GOVC_PASSWORD
   156    assert_output "$password"
   157  }
   158  
   159  @test "govc help" {
   160    run govc
   161    assert_failure
   162  
   163    run govc -h
   164    assert_success
   165    assert_matches "Usage: govc <COMMAND> \[COMMON OPTIONS\] \[PATH\]..."
   166  
   167    run govc --help
   168    assert_success
   169    assert_matches "Usage: govc <COMMAND> \[COMMON OPTIONS\] \[PATH\]..."
   170  
   171    run govc -enoent
   172    assert_failure
   173  
   174    run govc vm.create
   175    assert_failure
   176  
   177    run govc vm.create -h
   178    assert_success
   179  
   180    run govc vm.create -enoent
   181    assert_failure
   182  
   183    run govc nope
   184    assert_failure
   185    assert_matches "Usage: govc <COMMAND> \[COMMON OPTIONS\] \[PATH\]..."
   186  
   187    run govc power
   188    assert_failure
   189    assert_matches "did you mean:"
   190  }
   191  
   192  @test "govc format error" {
   193    vcsim_env
   194  
   195    vm=DC0_H0_VM0
   196  
   197    run govc vm.power -json -on $vm
   198    assert_failure
   199    jq . <<<"$output"
   200  
   201    run govc vm.power -xml -on $vm
   202    assert_failure
   203    if type xmlstarlet ; then
   204      xmlstarlet fo <<<"$output"
   205    fi
   206  
   207    run govc vm.power -dump -on $vm
   208    assert_failure
   209    gofmt <<<"$output"
   210  
   211    run govc datastore.create -type local -name vsanDatastore -path "$BATS_TMPDIR" DC0_C0_H0
   212    assert_success
   213  
   214    run govc vm.create -ds vsanDatastore "$(new_id)"
   215    assert_failure
   216    assert_matches "requires 2 more usable fault domains"
   217  }
   218  
   219  @test "insecure cookies" {
   220    vcsim_start -tls=false
   221  
   222    run govc ls
   223    assert_success
   224  
   225    vcsim_stop
   226  
   227    VCSIM_SECURE_COOKIES=true vcsim_start -tls=false
   228  
   229    run govc ls
   230    assert_failure
   231    assert_matches NotAuthenticated # Go's cookiejar won't send Secure cookies if scheme != https
   232  
   233    vcsim_stop
   234  
   235    VCSIM_SECURE_COOKIES=true vcsim_start -tls=false
   236  
   237    run env GOVMOMI_INSECURE_COOKIES=true govc ls
   238    assert_success # soap.Client will set Cookie.Secure=false
   239  
   240    vcsim_stop
   241  }
   242  
   243  @test "govc verbose" {
   244    vcsim_env
   245  
   246    vm=DC0_H0_VM0
   247  
   248    run govc vm.power -verbose -off $vm
   249    assert_success
   250  
   251    run govc vm.power -verbose -off $vm
   252    assert_failure
   253  
   254    run govc vm.power -verbose -on $vm
   255    assert_success
   256  
   257    run govc vm.power -verbose -on $vm
   258    assert_failure
   259  
   260    run govc vm.info -verbose '*'
   261    assert_success
   262  
   263    run govc device.ls -vm DC0_H0_VM0 -verbose
   264    assert_success
   265  
   266    run govc device.info -vm DC0_H0_VM0 -verbose
   267    assert_success
   268  
   269    run govc vm.destroy -verbose $vm
   270    assert_success
   271  
   272    run govc host.info -verbose '*'
   273    assert_success
   274  
   275    run govc cluster.group.create -verbose -cluster DC0_C0 -name cgroup -vm DC0_C0_RP0_VM{0,1}
   276    assert_success
   277  
   278    run govc cluster.group.ls -cluster DC0_C0
   279    assert_success
   280  
   281    run govc cluster.create -verbose ClusterA
   282    assert_success
   283  
   284    run govc metric.ls -verbose /DC0/host/DC0_C0
   285    assert_success
   286  
   287    run govc metric.info -verbose /DC0/host/DC0_C0
   288    assert_success
   289  
   290    run govc metric.sample -verbose /DC0/host/DC0_C0 cpu.usage.average
   291    assert_success
   292  
   293    run govc session.login -verbose -issue # sts.Client
   294    assert_success
   295  
   296    run govc sso.service.ls -verbose # lookup.Client
   297    assert_success
   298  
   299    run govc storage.policy.ls -verbose # pbm.Client
   300    assert_success
   301  
   302    run govc volume.ls -verbose # cns.Client
   303    assert_success
   304  }