Skip to content

Commit 87e9b3e

Browse files
committed
vcsim: Add vapi support for CategoryID and TagID fields
Signed-off-by: Doug MacEachern <[email protected]>
1 parent d2b4cc7 commit 87e9b3e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

govc/test/tags.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ load test_helper
5151

5252
run govc tags.category.rm "$update_name"
5353
assert_success
54+
55+
run govc tags.category.create -id "invalid" custom-id-cat
56+
assert_failure
57+
58+
id="urn:vmomi:InventoryServiceCategory:$(new_id):GLOBAL"
59+
run govc tags.category.create -id "$id" custom-id-cat
60+
assert_success
61+
62+
run govc tags.category.info "$id"
63+
assert_success
5464
}
5565

5666
@test "tags" {
@@ -117,6 +127,16 @@ load test_helper
117127

118128
run govc tags.info enoent
119129
assert_failure # does not exist
130+
131+
run govc tags.category.create -c "$category_name" -id "invalid" custom-id-tag
132+
assert_failure
133+
134+
id="urn:vmomi:InventoryServiceTag:$(new_id):GLOBAL"
135+
run govc tags.create -c "$category_name" -id "$id" custom-id-tag
136+
assert_success
137+
138+
run govc tags.info "$id"
139+
assert_success
120140
}
121141

122142
@test "tags.association" {

vapi/simulator/simulator.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,13 @@ func (s *handler) category(w http.ResponseWriter, r *http.Request) {
595595
return
596596
}
597597
}
598-
id := newID("Category")
598+
id := spec.Category.CategoryID
599+
if id == "" {
600+
id = newID("Category")
601+
} else if !strings.HasPrefix(id, "urn:vmomi:InventoryServiceCategory:") {
602+
BadRequest(w, "com.vmware.vapi.std.errors.invalid_argument")
603+
return
604+
}
599605
spec.Category.ID = id
600606
s.Category[id] = &spec.Category
601607
OK(w, id)
@@ -668,7 +674,13 @@ func (s *handler) tag(w http.ResponseWriter, r *http.Request) {
668674
return
669675
}
670676
}
671-
id := newID("Tag")
677+
id := spec.Tag.TagID
678+
if id == "" {
679+
id = newID("Tag")
680+
} else if !strings.HasPrefix(id, "urn:vmomi:InventoryServiceTag:") {
681+
BadRequest(w, "com.vmware.vapi.std.errors.invalid_argument")
682+
return
683+
}
672684
spec.Tag.ID = id
673685
s.Tag[id] = &spec.Tag
674686
s.Association[id] = make(map[internal.AssociatedObject]bool)

0 commit comments

Comments
 (0)