Skip to content

Commit

Permalink
fix nacos test
Browse files Browse the repository at this point in the history
  • Loading branch information
cvictory committed Sep 16, 2020
1 parent c3aac14 commit 2a6c0a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
11 changes: 10 additions & 1 deletion metadata/report/nacos/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"strconv"
"testing"
"time"
)

import (
Expand All @@ -37,7 +38,7 @@ import (
)

func TestNacosMetadataReport_CRUD(t *testing.T) {
if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil {
if !checkNacosServerAlive() {
return
}
rpt := newTestReport()
Expand Down Expand Up @@ -118,3 +119,11 @@ func newTestReport() report.MetadataReport {
res := extension.GetMetadataReportFactory("nacos").CreateMetadataReport(&regurl)
return res
}

func checkNacosServerAlive() bool {
c := http.Client{Timeout: time.Second}
if _, err := c.Get("http://console.nacos.io/nacos/"); err != nil {
return false
}
return true
}
15 changes: 12 additions & 3 deletions registry/nacos/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/url"
"strconv"
"testing"
"time"
)

import (
Expand All @@ -36,7 +37,7 @@ import (
)

func TestNacosRegistry_Register(t *testing.T) {
if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil {
if !checkNacosServerAlive() {
return
}
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestNacosRegistry_Register(t *testing.T) {
}

func TestNacosRegistry_Subscribe(t *testing.T) {
if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil {
if !checkNacosServerAlive() {
return
}
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestNacosRegistry_Subscribe(t *testing.T) {
}

func TestNacosRegistry_Subscribe_del(t *testing.T) {
if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil {
if !checkNacosServerAlive() {
return
}
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
Expand Down Expand Up @@ -198,3 +199,11 @@ func TestNacosListener_Close(t *testing.T) {
_, err = listener.Next()
assert.NotNil(t, err)
}

func checkNacosServerAlive() bool {
c := http.Client{Timeout: time.Second}
if _, err := c.Get("http://console.nacos.io/nacos/"); err != nil {
return false
}
return true
}
3 changes: 1 addition & 2 deletions registry/nacos/service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package nacos

import (
"math/rand"
"net/http"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -82,7 +81,7 @@ func TestNacosServiceDiscovery_Destroy(t *testing.T) {
}

func TestNacosServiceDiscovery_CRUD(t *testing.T) {
if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil {
if !checkNacosServerAlive() {
return
}
prepareData()
Expand Down

0 comments on commit 2a6c0a1

Please sign in to comment.