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

     1  #!/usr/bin/env bats
     2  
     3  load test_helper
     4  
     5  @test "tags.category" {
     6    vcsim_env
     7    local output
     8  
     9    run govc tags.category.ls
    10    assert_success # no categories defined yet
    11  
    12    run govc tags.category.info
    13    assert_success # no categories defined yet
    14  
    15    run govc tags.category.info enoent
    16    assert_failure # category does not exist
    17  
    18    category_name=$(new_id)
    19  
    20    run govc tags.category.create -d "Cat in the hat" -m "$category_name"
    21    assert_success
    22  
    23    category_id="$output"
    24    run govc tags.category.ls
    25    assert_success
    26  
    27    run govc tags.category.create -m "$category_name"
    28    assert_failure # already exists
    29  
    30    run govc tags.category.ls
    31    assert_line "$category_name"
    32  
    33    id=$(govc tags.category.ls -json | jq -r '.[].id')
    34    assert_matches "$id" "$category_id"
    35  
    36    run govc tags.category.info "$category_name"
    37    assert_success
    38  
    39    update_name="${category_name}-update"
    40  
    41    run govc tags.category.update -n "$update_name" -d "Green eggs and ham" "$category_id"
    42    assert_success
    43  
    44    govc tags.category.info "$update_name" | grep -c eggs
    45  
    46    run govc tags.category.info "$category_name"
    47    assert_failure # does not exist
    48  
    49    run govc tags.category.rm "$category_name"
    50    assert_failure # should fail with old name
    51  
    52    run govc tags.category.rm "$update_name"
    53    assert_success
    54  }
    55  
    56  @test "tags" {
    57    vcsim_env
    58    local output
    59  
    60    run govc tags.ls
    61    assert_success # no tags defined yet
    62  
    63    run govc tags.ls -k=false
    64    assert_failure
    65  
    66    run govc tags.ls -k=false -tls-ca-certs <(govc about.cert -show)
    67    assert_success
    68  
    69    run govc tags.info
    70    assert_success # no tags defined yet
    71  
    72    run govc tags.info enoent
    73    assert_failure # specific tag does not exist
    74  
    75    category_name=$(new_id)
    76    run govc tags.category.create -m "$category_name"
    77    assert_success
    78  
    79    category="$output"
    80    test_name="test_name"
    81  
    82    run govc tags.create -c "$category" $test_name
    83    assert_success
    84    tag_id="$output"
    85  
    86    count=$(govc tags.ls | grep -c $test_name)
    87    [ "$count" = "1" ]
    88  
    89    run govc tags.create -c "$category_name" $test_name
    90    assert_failure # already_exists
    91  
    92    run govc tags.category.create -m "$category_name-2"
    93    assert_success
    94  
    95    run govc tags.create -c "$category_name-2" $test_name
    96    assert_success # same name but different category
    97  
    98    count=$(govc tags.ls | grep -c $test_name)
    99    [ "$count" = "2" ]
   100  
   101    id=$(govc tags.ls -json | jq -r '.[].id')
   102    assert_matches "$id" "$tag_id"
   103  
   104    update_name="${test_name}-update"
   105    run govc tags.update -d "Updated tag" -n "$update_name" "$tag_id"
   106    assert_success
   107  
   108    govc tags.info
   109    govc tags.info -C=false
   110    govc tags.info "$update_name" | grep Updated
   111  
   112    run govc tags.create -c "$category_name" "$(new_id)"
   113    assert_success
   114  
   115    run govc tags.create -c enoent "$(new_id)"
   116    assert_failure # category name does not exist
   117  
   118    run govc tags.info enoent
   119    assert_failure # does not exist
   120  }
   121  
   122  @test "tags.association" {
   123    vcsim_env
   124    local lines
   125  
   126    category_name=$(new_id)
   127    run govc tags.category.create -m "$category_name"
   128    assert_success
   129    category="$output"
   130  
   131    run govc tags.create -c "$category" "$(new_id)"
   132    assert_success
   133    tag=$output
   134  
   135    tag_name=$(govc tags.ls -json | jq -r ".[] | select(.id == \"$tag\") | .name")
   136    run govc find . -type h
   137    object=${lines[0]}
   138  
   139    run govc tags.attach "$tag" "$object"
   140    assert_success
   141  
   142    run govc tags.attached.ls "$tag_name"
   143    assert_success
   144    [ ${#lines[@]} -eq 1 ]
   145  
   146    result=$(govc tags.attached.ls -r "$object")
   147    assert_matches "$result" "$tag_name"
   148  
   149    result=$(govc tags.attached.ls -r -json "$object")
   150    assert_matches "$tag_name" "$result"
   151  
   152    run govc tags.rm "$tag"
   153    assert_failure # tags still attached
   154  
   155    run govc tags.detach "$tag" "$object"
   156    assert_success
   157  
   158    run govc tags.attach "$tag_name" "$object"
   159    assert_success # attach using name instead of ID
   160  
   161    run govc tags.rm "$tag"
   162    assert_failure # tags still attached
   163  
   164    run govc tags.detach -c enoent "$tag_name" "$object"
   165    assert_failure # category does not exist
   166  
   167    run govc tags.detach -c "$category_name" "$tag_name" "$object"
   168    assert_success # detach using name instead of ID
   169  
   170    run govc tags.rm -c "$category_name" "$tag"
   171    assert_success
   172  
   173    run govc tags.category.rm "$category"
   174    assert_success
   175  }
   176  
   177  @test "tags.example" {
   178    vcsim_env -dc 2 -cluster 2
   179  
   180    govc tags.category.create -d "Kubernetes region" k8s-region
   181  
   182    for region in EMEA US ; do
   183      govc tags.create -d "Kubernetes region $region" -c k8s-region k8s-region-$region
   184    done
   185  
   186    govc tags.attach k8s-region-EMEA /DC0
   187    govc tags.attach k8s-region-US /DC1
   188  
   189    govc tags.category.create -d "Kubernetes zone" k8s-zone
   190  
   191    for zone in DE CA WA ; do
   192      govc tags.create -d "Kubernetes zone $zone" -c k8s-zone k8s-zone-$zone
   193    done
   194  
   195    govc tags.attach k8s-zone-DE /DC0/host/DC0_C0
   196    govc tags.attach k8s-zone-DE /DC0/host/DC0_C1
   197  
   198    govc tags.attach k8s-zone-CA /DC1/host/DC1_C0
   199    govc tags.attach k8s-zone-WA /DC1/host/DC1_C1
   200  
   201    govc tags.category.ls
   202    govc tags.category.info
   203  
   204    govc tags.ls
   205    govc tags.ls -c k8s-region
   206    govc tags.ls -c k8s-zone
   207    govc tags.info
   208  
   209    govc tags.attached.ls k8s-region-US
   210    govc tags.attached.ls k8s-zone-CA
   211    govc tags.attached.ls -r /DC1
   212    govc tags.attached.ls -r /DC1/host/DC1_C0
   213  }