You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2021/03/19 01:03:56 UTC
[servicecomb-service-center] branch v1.x updated: SCB-2176 Fix:
Allow erase tags (#904)
This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch v1.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/v1.x by this push:
new 758587b SCB-2176 Fix: Allow erase tags (#904)
758587b is described below
commit 758587b97c45510b7a5ca20a014b570d8a2e65c8
Author: little-cui <su...@qq.com>
AuthorDate: Fri Mar 19 09:03:51 2021 +0800
SCB-2176 Fix: Allow erase tags (#904)
---
integration/tags_test.go | 24 ++++++++++++++++++------
server/service/tag_test.go | 16 +++++++++-------
server/service/tag_validator.go | 2 +-
3 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/integration/tags_test.go b/integration/tags_test.go
index d0d98ab..1d93dea 100644
--- a/integration/tags_test.go
+++ b/integration/tags_test.go
@@ -100,11 +100,8 @@ var _ = Describe("MicroService Api Test", func() {
Expect(resp.StatusCode).To(Equal(http.StatusOK))
})
- It("Create MicroService tags with invalid params", func() {
- tags := map[string]interface{}{}
- bodyParams := map[string]interface{}{
- "tags": tags,
- }
+ It("Create MicroService tags with empty collections, should be pass", func() {
+ bodyParams := map[string]interface{}{}
url := strings.Replace(ADDTAGE, ":serviceId", serviceId, 1)
body, _ := json.Marshal(bodyParams)
bodyBuf := bytes.NewReader(body)
@@ -114,7 +111,22 @@ var _ = Describe("MicroService Api Test", func() {
Expect(err).To(BeNil())
defer resp.Body.Close()
- Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))
+ Expect(resp.StatusCode).To(Equal(http.StatusOK))
+
+ tags := map[string]interface{}{}
+ bodyParams = map[string]interface{}{
+ "tags": tags,
+ }
+ url = strings.Replace(ADDTAGE, ":serviceId", serviceId, 1)
+ body, _ = json.Marshal(bodyParams)
+ bodyBuf = bytes.NewReader(body)
+ req, _ = http.NewRequest(POST, SCURL+url, bodyBuf)
+ req.Header.Set("X-Domain-Name", "default")
+ resp, err = scclient.Do(req)
+ Expect(err).To(BeNil())
+ defer resp.Body.Close()
+
+ Expect(resp.StatusCode).To(Equal(http.StatusOK))
})
It("Create MicroService tags with invalid serviceID", func() {
diff --git a/server/service/tag_test.go b/server/service/tag_test.go
index 72a6e4f..6206e6c 100644
--- a/server/service/tag_test.go
+++ b/server/service/tag_test.go
@@ -87,13 +87,6 @@ var _ = Describe("'Tag' service", func() {
})
Expect(respAddTags.Response.GetCode()).ToNot(Equal(proto.Response_SUCCESS))
- By("tag is empty")
- respAddTags, _ = serviceResource.AddTags(getContext(), &pb.AddServiceTagsRequest{
- ServiceId: serviceId1,
- Tags: map[string]string{},
- })
- Expect(respAddTags.Response.GetCode()).ToNot(Equal(proto.Response_SUCCESS))
-
By("tag key is empty")
respAddTags, _ = serviceResource.AddTags(getContext(), &pb.AddServiceTagsRequest{
ServiceId: serviceId1,
@@ -120,6 +113,15 @@ var _ = Describe("'Tag' service", func() {
})
Expect(err).To(BeNil())
Expect(respAddTags.Response.GetCode()).To(Equal(proto.Response_SUCCESS))
+
+ By("tag is empty")
+ respAddTags, _ = serviceResource.AddTags(getContext(), &pb.AddServiceTagsRequest{
+ ServiceId: serviceId1,
+ Tags: map[string]string{},
+ })
+ Expect(respAddTags.Response.GetCode()).To(Equal(proto.Response_SUCCESS))
+ getServiceTagsResponse, _ := serviceResource.GetTags(getContext(), &pb.GetServiceTagsRequest{ServiceId: serviceId1})
+ Expect(getServiceTagsResponse.Tags).To(BeEmpty())
})
})
diff --git a/server/service/tag_validator.go b/server/service/tag_validator.go
index 2ed45ef..fdcda74 100644
--- a/server/service/tag_validator.go
+++ b/server/service/tag_validator.go
@@ -43,7 +43,7 @@ func GetTagsReqValidator() *validate.Validator {
func AddTagsReqValidator() *validate.Validator {
return addTagsReqValidator.Init(func(v *validate.Validator) {
v.AddRule("ServiceId", GetServiceReqValidator().GetRule("ServiceId"))
- v.AddRule("Tags", &validate.Rule{Min: 1, Max: quota.DefaultTagQuota, Regexp: tagRegex})
+ v.AddRule("Tags", &validate.Rule{Max: quota.DefaultTagQuota, Regexp: tagRegex})
})
}