Skip to content

Commit

Permalink
fix format & bug
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-Morgan committed Oct 22, 2024
1 parent b991252 commit 24b1986
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
2 changes: 1 addition & 1 deletion nacos/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ replace github.com/cloudwego-contrib/cwgo-pkg/registry/nacos/nacoshertz/v2 => gi

replace github.com/cloudwego-contrib/cwgo-pkg/registry/nacos/options => github.com/smx-Morgan/cwgo-pkg/registry/nacos/options v0.0.0-20241016000926-d56ef7e0f578

replace github.com/nacos-group/nacos-sdk-go/v2 => github.com/nacos-group/nacos-sdk-go/v2 v2.2.0
replace github.com/nacos-group/nacos-sdk-go/v2 v2.2.7 => github.com/nacos-group/nacos-sdk-go/v2 v2.2.0
46 changes: 0 additions & 46 deletions nacos/v2/nacos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,49 +426,3 @@ func TestCompareMaps(t *testing.T) {
}
}
}

// TestHertzAppWithNacosRegistry test a client call a hertz app with NacosRegistry
func TestHertzAppWithNacosRegistry(t *testing.T) {
namingClient = getNamingClient()
register := NewNacosRegistry(namingClient)
address := "127.0.0.1:4576"
srvName := "d.h.t"
var opts []config.Option
opts = append(opts, server.WithHostPorts(address), server.WithExitWaitTime(2*time.Second))
opts = append(opts, server.WithRegistry(register, &registry.Info{
ServiceName: srvName,
Addr: utils.NewNetAddr("tcp", address),
Weight: 10,
Tags: nil,
}))
// run a hertz app,registry src info into NacosRegistry
srv := server.New(opts...)
srv.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
ctx.String(200, "pong")
})
go srv.Spin()
// Because delayed registration, we need sleep more time.
time.Sleep(2 * time.Second)

// client call an url, with NacosResolver
newClient, _ := client.NewClient()
resolver := NewNacosResolver(namingClient)
newClient.Use(sd.Discovery(resolver))

status, body, err := newClient.Get(context.TODO(), nil, "http://d.h.t/ping",
config.WithSD(true))
assert.Nil(t, err)
assert.Equal(t, 200, status)
assert.Equal(t, "pong", string(body))

ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFunc()
srv.Shutdown(ctx) //nolint:errcheck // ignore error

time.Sleep(5 * time.Second)
status, body, err = newClient.Get(context.Background(), nil, "http://d.h.t/ping",
config.WithSD(true))
assert.NotNil(t, err)
assert.Equal(t, 0, status)
assert.Equal(t, "", string(body))
}

0 comments on commit 24b1986

Please sign in to comment.