little-cui closed pull request #488: SCB-1015 Support the forth microservice 
version number registration
URL: https://github.com/apache/servicecomb-service-center/pull/488
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/plugin/pkg/registry/etcd/etcd_test.go 
b/server/plugin/pkg/registry/etcd/etcd_test.go
index 79aed508..aa4e69f6 100644
--- a/server/plugin/pkg/registry/etcd/etcd_test.go
+++ b/server/plugin/pkg/registry/etcd/etcd_test.go
@@ -120,7 +120,7 @@ func TestEtcdClient(t *testing.T) {
 
        // base test
        inst := NewRegistry()
-       if inst == nil || firstEndpoint != endpoint {
+       if inst == nil || strings.Index(endpoint, firstEndpoint) < 0 {
                t.Fatalf("TestEtcdClient failed, %s != %s", firstEndpoint, 
endpoint)
        }
        old1 := registry.Configuration().ClusterAddresses
diff --git a/server/service/microservice_test.go 
b/server/service/microservice_test.go
index 4b7792a6..420c25c7 100644
--- a/server/service/microservice_test.go
+++ b/server/service/microservice_test.go
@@ -64,7 +64,7 @@ var _ = Describe("'Micro-service' service", func() {
                                        Service: &pb.MicroService{
                                                AppId:       
TOO_LONG_APPID[:len(TOO_LONG_APPID)-1],
                                                ServiceName: 
TOO_LONG_SERVICENAME[:len(TOO_LONG_SERVICENAME)-1],
-                                               Version:     
"32767.32767.32767",
+                                               Version:     
"32767.32767.32767.32767",
                                                Alias:       
TOO_LONG_ALIAS[:len(TOO_LONG_ALIAS)-1],
                                                Level:       "BACK",
                                                Status:      "UP",
@@ -495,6 +495,20 @@ var _ = Describe("'Micro-service' service", func() {
                                Expect(err).To(BeNil())
                                
Expect(resp.Response.Code).To(Equal(scerr.ErrInvalidParams))
 
+                               By("invalid version 4")
+                               r = &pb.CreateServiceRequest{
+                                       Service: &pb.MicroService{
+                                               AppId:       "default",
+                                               ServiceName: "service-validate",
+                                               Version:     "1.1.0.0.0",
+                                               Level:       "BACK",
+                                               Status:      "UP",
+                                       },
+                               }
+                               resp, err = 
serviceResource.Create(getContext(), r)
+                               Expect(err).To(BeNil())
+                               
Expect(resp.Response.Code).To(Equal(scerr.ErrInvalidParams))
+
                                By("invalid level")
                                r = &pb.CreateServiceRequest{
                                        Service: &pb.MicroService{
@@ -840,6 +854,14 @@ var _ = Describe("'Micro-service' service", func() {
                                })
                                Expect(err).To(BeNil())
                                
Expect(resp.Response.Code).To(Equal(scerr.ErrInvalidParams))
+                               resp, err = serviceResource.Exist(getContext(), 
&pb.GetExistenceRequest{
+                                       Type:        "microservice",
+                                       AppId:       "default",
+                                       ServiceName: "exist-invalid-version",
+                                       Version:     "3.0.0.0.0",
+                               })
+                               Expect(err).To(BeNil())
+                               
Expect(resp.Response.Code).To(Equal(scerr.ErrInvalidParams))
 
                                By("version is empty")
                                resp, err = serviceResource.Exist(getContext(), 
&pb.GetExistenceRequest{
diff --git a/server/service/util/versionrule.go 
b/server/service/util/versionrule.go
index 78feb9a9..ed7f3600 100644
--- a/server/service/util/versionrule.go
+++ b/server/service/util/versionrule.go
@@ -254,9 +254,9 @@ func (vr *VersionRegexp) validateVersionRule(versionRule 
string) (err error) {
 func NewVersionRegexp(fuzzy bool) (vr *VersionRegexp) {
        vr = &VersionRegexp{Fuzzy: fuzzy}
        if fuzzy {
-               vr.Regex, _ = 
regexp.Compile(`^\d+(\.\d+){0,2}\+?$|^\d+(\.\d+){0,2}-\d+(\.\d+){0,2}$|^latest$`)
+               vr.Regex, _ = 
regexp.Compile(`^\d+(\.\d+){0,3}\+?$|^\d+(\.\d+){0,3}-\d+(\.\d+){0,3}$|^latest$`)
                return
        }
-       vr.Regex, _ = regexp.Compile(`^\d+(\.\d+){0,2}$`)
+       vr.Regex, _ = regexp.Compile(`^\d+(\.\d+){0,3}$`)
        return
 }
diff --git a/server/service/util/versionrule_test.go 
b/server/service/util/versionrule_test.go
index 71bbc7f1..8d1f105b 100644
--- a/server/service/util/versionrule_test.go
+++ b/server/service/util/versionrule_test.go
@@ -330,6 +330,9 @@ var _ = Describe("Version Rule sorter", func() {
                                Expect(vr.MatchString("1.-.2")).To(BeFalse())
                                Expect(vr.MatchString("60000-1")).To(BeFalse())
                                Expect(vr.MatchString("1.1-2.2")).To(BeTrue())
+                               
Expect(vr.MatchString("1.1.1.1-2.2.2.2")).To(BeTrue())
+                               
Expect(vr.MatchString("1.1.1.1.1-2.2.2.2")).To(BeFalse())
+                               
Expect(vr.MatchString("1.1.1.1-2.2.2.2.2")).To(BeFalse())
                        })
                        It("AtLess", func() {
                                vr := NewVersionRegexp(false)
@@ -343,6 +346,8 @@ var _ = Describe("Version Rule sorter", func() {
                                Expect(vr.MatchString(".+")).To(BeFalse())
                                Expect(vr.MatchString("60000+")).To(BeFalse())
                                Expect(vr.MatchString("1.0+")).To(BeTrue())
+                               Expect(vr.MatchString("1.0.0.0+")).To(BeTrue())
+                               
Expect(vr.MatchString("1.0.0.0.0+")).To(BeFalse())
                        })
                        It("Explicit", func() {
                                vr := NewVersionRegexp(false)
@@ -361,6 +366,8 @@ var _ = Describe("Version Rule sorter", func() {
                                Expect(vr.MatchString("1.")).To(BeFalse())
                                Expect(vr.MatchString(".1")).To(BeFalse())
                                Expect(vr.MatchString("1.4")).To(BeTrue())
+                               Expect(vr.MatchString("1.4.0.0")).To(BeTrue())
+                               
Expect(vr.MatchString("1.4.0.0.0")).To(BeFalse())
                        })
                })
                Context("Exception", func() {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to