mirror of
https://github.com/go-kratos/kratos.git
synced 2026-05-22 10:15:24 +02:00
fix:move test proto file to internal (#1471)
* fix:move test proto file to internal
This commit is contained in:
@@ -14,6 +14,7 @@ require (
|
||||
go.opentelemetry.io/otel v1.0.0-RC3
|
||||
go.opentelemetry.io/otel/sdk v1.0.0-RC3
|
||||
go.opentelemetry.io/otel/trace v1.0.0-RC3
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67
|
||||
google.golang.org/grpc v1.39.1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1-devel
|
||||
// protoc v3.17.2
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.17.3
|
||||
// source: test.proto
|
||||
|
||||
package binding
|
||||
@@ -3,34 +3,36 @@ package binding
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/go-kratos/kratos/v2/internal/testdata/binding"
|
||||
)
|
||||
|
||||
func TestProtoPath(t *testing.T) {
|
||||
url := EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &HelloRequest{Name: "test", Sub: &Sub{Name: "2233!!!"}}, false)
|
||||
url := EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &binding.HelloRequest{Name: "test", Sub: &binding.Sub{Name: "2233!!!"}}, false)
|
||||
fmt.Println(url)
|
||||
if url != `http://helloworld.Greeter/helloworld/test/sub/2233!!!` {
|
||||
t.Fatalf("proto path not expected!actual: %s ", url)
|
||||
}
|
||||
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.naming}", &HelloRequest{Name: "test", Sub: &Sub{Name: "5566!!!"}}, false)
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.naming}", &binding.HelloRequest{Name: "test", Sub: &binding.Sub{Name: "5566!!!"}}, false)
|
||||
fmt.Println(url)
|
||||
if url != `http://helloworld.Greeter/helloworld/test/sub/5566!!!` {
|
||||
t.Fatalf("proto path not expected!actual: %s ", url)
|
||||
}
|
||||
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/sub", &HelloRequest{Name: "test", Sub: &Sub{Name: "2233!!!"}}, false)
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/sub", &binding.HelloRequest{Name: "test", Sub: &binding.Sub{Name: "2233!!!"}}, false)
|
||||
fmt.Println(url)
|
||||
if url != `http://helloworld.Greeter/helloworld/sub` {
|
||||
t.Fatalf("proto path not expected!actual: %s ", url)
|
||||
}
|
||||
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &HelloRequest{Name: "test"}, false)
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &binding.HelloRequest{Name: "test"}, false)
|
||||
fmt.Println(url)
|
||||
if url != `http://helloworld.Greeter/helloworld/test/sub/` {
|
||||
t.Fatalf("proto path not expected!actual: %s ", url)
|
||||
}
|
||||
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name33}", &HelloRequest{Name: "test"}, false)
|
||||
url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name33}", &binding.HelloRequest{Name: "test"}, false)
|
||||
fmt.Println(url)
|
||||
if url != `http://helloworld.Greeter/helloworld/test/sub/{sub.name33}` {
|
||||
t.Fatalf("proto path not expected!actual: %s ", url)
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/go-kratos/kratos/v2/registry"
|
||||
"github.com/go-kratos/kratos/v2/selector"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -27,3 +31,52 @@ func TestParseTarget(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, &Target{Scheme: "https", Authority: "127.0.0.1:8000"}, target)
|
||||
}
|
||||
|
||||
type mockRebalancer struct{}
|
||||
|
||||
func (m *mockRebalancer) Apply(nodes []selector.Node) {}
|
||||
|
||||
type mockDiscoverys struct{}
|
||||
|
||||
func (*mockDiscoverys) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (*mockDiscoverys) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) {
|
||||
return &mockWatch{}, nil
|
||||
}
|
||||
|
||||
type mockWatch struct {
|
||||
count int
|
||||
}
|
||||
|
||||
func (m *mockWatch) Next() ([]*registry.ServiceInstance, error) {
|
||||
if m.count == 0 {
|
||||
m.count++
|
||||
return nil, errors.New("mock test error")
|
||||
}
|
||||
instance := ®istry.ServiceInstance{
|
||||
ID: "1",
|
||||
Name: "kratos",
|
||||
Version: "v1",
|
||||
Metadata: map[string]string{},
|
||||
Endpoints: []string{},
|
||||
}
|
||||
return []*registry.ServiceInstance{instance}, nil
|
||||
}
|
||||
|
||||
func (m *mockWatch) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestResolver(t *testing.T) {
|
||||
ta := &Target{
|
||||
Scheme: "http",
|
||||
Authority: "",
|
||||
Endpoint: "http://127.0.0.1:9001",
|
||||
}
|
||||
_, err := newResolver(context.Background(), &mockDiscoverys{}, ta, &mockRebalancer{}, false, false)
|
||||
assert.Nil(t, err)
|
||||
_, err = newResolver(context.Background(), &mockDiscoverys{}, ta, &mockRebalancer{}, true, false)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user