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

     1  #!/usr/bin/env bats
     2  
     3  load test_helper
     4  
     5  # These tests should only run against a server running an evaluation license.
     6  verify_evaluation() {
     7    if [ "$(govc license.ls -json | jq -r .[0].editionKey)" != "eval" ]; then
     8      skip "requires evaluation license"
     9    fi
    10  }
    11  
    12  get_key() {
    13    jq ".[] | select(.licenseKey == \"$1\")"
    14  }
    15  
    16  get_property() {
    17    jq -r ".properties[] | select(.key == \"$1\") | .value"
    18  }
    19  
    20  get_label() {
    21    govc license.ls -json | jq -r ".[] | select(.licenseKey == \"$1\") | .labels[] | select(.key == \"$2\") | .value"
    22  }
    23  
    24  get_nlabel() {
    25    govc license.ls -json | jq ".[] | select(.licenseKey == \"$1\") | .labels[].key" | wc -l
    26  }
    27  
    28  @test "license.add" {
    29    esx_env
    30  
    31    verify_evaluation
    32  
    33    run govc license.add -json 00000-00000-00000-00000-00001 00000-00000-00000-00000-00002
    34    assert_success
    35  
    36    # Expect to see an entry for both the first and the second key
    37    assert_equal "License is not valid for this product" "$(get_key 00000-00000-00000-00000-00001 <<<${output} | get_property diagnostic)"
    38    assert_equal "License is not valid for this product" "$(get_key 00000-00000-00000-00000-00002 <<<${output} | get_property diagnostic)"
    39  }
    40  
    41  @test "license.remove" {
    42    esx_env
    43  
    44    verify_evaluation
    45  
    46    run govc license.remove -json 00000-00000-00000-00000-00001
    47    assert_success
    48  }
    49  
    50  @test "license.ls" {
    51    vcsim_env
    52  
    53    verify_evaluation
    54  
    55    run govc license.ls -json
    56    assert_success
    57  
    58    # Expect the test instance to run in evaluation mode
    59    assert_equal "Evaluation Mode" "$(get_key 00000-00000-00000-00000-00000 <<<$output | jq -r ".name")"
    60  }
    61  
    62  @test "license.decode" {
    63    esx_env
    64  
    65    verify_evaluation
    66  
    67    key=00000-00000-00000-00000-00000
    68    assert_equal "eval" $(govc license.decode $key | grep $key | awk '{print $2}')
    69  }
    70  
    71  @test "license.label.set" {
    72    vcsim_env
    73  
    74    key=00000-00000-00000-00000-00000
    75  
    76    assert_equal 0 "$(get_nlabel $key)"
    77    assert_equal "" "$(get_label $key foo)"
    78  
    79    run govc license.label.set $key foo bar
    80    assert_success
    81  
    82    assert_equal 1 "$(get_nlabel $key)"
    83    assert_equal bar "$(get_label $key foo)"
    84  
    85    run govc license.label.set $key biz baz
    86    assert_success
    87    run govc license.label.set $key foo bar2
    88    assert_success
    89  
    90    assert_equal 2 "$(get_nlabel $key)"
    91    assert_equal bar2 "$(get_label $key foo)"
    92  
    93    run govc license.label.set $key foo ""
    94    assert_success
    95  
    96    assert_equal 1 "$(get_nlabel $key)"
    97    assert_equal "" "$(get_label $key foo)"
    98  }