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

     1  #!/usr/bin/env bats
     2  
     3  load test_helper
     4  
     5  @test "events dc" {
     6    vcsim_env
     7  
     8    run govc events
     9    assert_success
    10    nevents=${#lines[@]}
    11    # there should be plenty more than 1 event at the top (dc) level
    12    [ $nevents -ge 1 ]
    13  
    14    # test -n flag
    15    run govc events -n $((nevents - 1))
    16    assert_success
    17    [ ${#lines[@]} -le $nevents ]
    18  
    19    # test keys in json
    20    [ "$(govc events -l -n 1 -json | jq -r 'has("createdTime")')" = "true" ]
    21    [ "$(govc events -l -n 1 -json | jq -r 'has("category")')" = "true" ]
    22    [ "$(govc events -l -n 1 -json | jq -r 'has("message")')" = "true" ]
    23    [ "$(govc events -l -n 1 -json | jq -r 'has("type")')" = "true" ]
    24    [ "$(govc events -l -n 1 -json | jq -r 'has("key")')" = "true" ]
    25  }
    26  
    27  @test "events host" {
    28    vcsim_env -esx
    29  
    30    run govc events 'host/*'
    31    assert_success
    32    [ ${#lines[@]} -ge 1 ]
    33  }
    34  
    35  @test "events vm" {
    36    vcsim_env
    37  
    38    vm=$(new_id)
    39  
    40    run govc vm.create -on=false $vm
    41    assert_success
    42  
    43    run govc events vm/$vm
    44    assert_success
    45    nevents=${#lines[@]}
    46    [ $nevents -gt 1 ]
    47  
    48    # glob should have same # of events
    49    run govc events vm/${vm}*
    50    assert_success
    51    [ ${#lines[@]} -eq $nevents ]
    52  
    53    # create a new vm, glob should match more events
    54    run govc vm.create -on=false "${vm}-2"
    55    assert_success
    56    run govc events vm/${vm}*
    57    assert_success
    58    [ ${#lines[@]} -gt $nevents ]
    59    nevents=${#lines[@]}
    60  
    61    run govc events vm/*
    62    assert_success
    63    [ ${#lines[@]} -ge $nevents ]
    64  
    65    run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
    66    [ ${#lines[@]} -eq 0 ]
    67  
    68    run govc vm.power -on "$vm"
    69    assert_success
    70  
    71    run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
    72    [ ${#lines[@]} -eq 1 ]
    73  
    74    run govc vm.power -off "$vm"
    75    assert_success
    76  
    77    run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
    78    [ ${#lines[@]} -eq 2 ]
    79  }
    80  
    81  @test "events json" {
    82    vcsim_env
    83  
    84    # make sure we fmt.Printf properly
    85    govc events | grep -v '%!s(MISSING)'
    86  
    87    govc events -json | jq .
    88  
    89    # test multiple objects
    90    govc vm.create "$(new_id)"
    91    govc vm.create "$(new_id)"
    92  
    93    govc events 'vm/*'
    94    govc events -json 'vm/*' | jq .
    95  }