Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
38a4b0ca
Commit
38a4b0ca
authored
5 years ago
by
高辛格
Browse files
Options
Downloads
Patches
Plain Diff
consul test
parent
114b0c99
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.travis.yml
+0
-8
0 additions, 8 deletions
.travis.yml
registry/consul/consul_test.go
+40
-25
40 additions, 25 deletions
registry/consul/consul_test.go
with
40 additions
and
33 deletions
.travis.yml
+
0
−
8
View file @
38a4b0ca
...
...
@@ -6,14 +6,6 @@ go:
env
:
-
GO111MODULE=on CONSUL_VERSION=0.9.2
before_install
:
-
curl -sLo consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip
-
unzip consul.zip
-
rm consul.zip
-
mkdir -p ~/bin
-
mv consul ~/bin
-
export PATH="~/bin:$PATH"
install
:
true
script
:
...
...
This diff is collapsed.
Click to expand it.
registry/consul/consul_test.go
+
40
−
25
View file @
38a4b0ca
...
...
@@ -19,15 +19,20 @@ package consul
import
(
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"strconv"
"sync"
"testing"
)
import
(
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/hashicorp/consul/agent"
"github.com/stretchr/testify/assert"
)
var
(
...
...
@@ -125,28 +130,38 @@ func (server *Server) close() {
server
.
wg
.
Wait
()
}
//func TestSomething(t *testing.T) {
// providerRegistryUrl := newProviderRegistryUrl(registryHost, registryPort)
// consumerRegistryUrl := newConsumerRegistryUrl(registryHost, registryPort)
// providerUrl := newProviderUrl(providerHost, providerPort, service, protocol)
// consumerUrl := newConsumerUrl(consumerHost, consumerPort, service, protocol)
//
// cb := func(c *testutil.TestServerConfig) { c.Ports.HTTP = registryPort }
// consulServer, _ := testutil.NewTestServerConfig(cb)
// defer consulServer.Stop()
// providerRegistry, err := newConsulRegistry(providerRegistryUrl)
// assert.NoError(t, err)
// consumerRegistry, err := newConsulRegistry(consumerRegistryUrl)
// assert.NoError(t, err)
//
// server := newServer(providerHost, providerPort)
// defer server.close()
// err = providerRegistry.Register(providerUrl)
// assert.NoError(t, err)
//
// listener, err := consumerRegistry.Subscribe(consumerUrl)
// assert.NoError(t, err)
// event, err := listener.Next()
// assert.NoError(t, err)
// assert.True(t, providerUrl.URLEqual(event.Service))
//}
func
TestSomething
(
t
*
testing
.
T
)
{
providerRegistryUrl
:=
newProviderRegistryUrl
(
registryHost
,
registryPort
)
consumerRegistryUrl
:=
newConsumerRegistryUrl
(
registryHost
,
registryPort
)
providerUrl
:=
newProviderUrl
(
providerHost
,
providerPort
,
service
,
protocol
)
consumerUrl
:=
newConsumerUrl
(
consumerHost
,
consumerPort
,
service
,
protocol
)
dataDir
,
_
:=
ioutil
.
TempDir
(
"./"
,
"agent"
)
defer
os
.
RemoveAll
(
dataDir
)
hcl
:=
`
ports {
http = `
+
strconv
.
Itoa
(
registryPort
)
+
`
}
data_dir = "`
+
dataDir
+
`"
`
consulServer
:=
&
agent
.
TestAgent
{
Name
:
t
.
Name
(),
DataDir
:
dataDir
,
HCL
:
hcl
}
consulServer
.
Start
(
t
)
defer
consulServer
.
Shutdown
()
providerRegistry
,
err
:=
newConsulRegistry
(
providerRegistryUrl
)
assert
.
NoError
(
t
,
err
)
consumerRegistry
,
err
:=
newConsulRegistry
(
consumerRegistryUrl
)
assert
.
NoError
(
t
,
err
)
server
:=
newServer
(
providerHost
,
providerPort
)
defer
server
.
close
()
err
=
providerRegistry
.
Register
(
providerUrl
)
assert
.
NoError
(
t
,
err
)
listener
,
err
:=
consumerRegistry
.
Subscribe
(
consumerUrl
)
assert
.
NoError
(
t
,
err
)
event
,
err
:=
listener
.
Next
()
assert
.
NoError
(
t
,
err
)
assert
.
True
(
t
,
providerUrl
.
URLEqual
(
event
.
Service
))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment