trpc.group/trpc-go/trpc-go@v1.0.3/naming/selector/selector_test.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package selector 15 16 import ( 17 "testing" 18 "time" 19 20 "trpc.group/trpc-go/trpc-go/naming/registry" 21 22 "github.com/stretchr/testify/assert" 23 ) 24 25 var testNode *registry.Node = ®istry.Node{ 26 ServiceName: "testservice", 27 Address: "testservice.ip.1:16721", 28 Network: "tcp", 29 } 30 31 type testSelector struct { 32 } 33 34 // Select acquire a node. 35 func (ts *testSelector) Select(serviceName string, opt ...Option) (*registry.Node, error) { 36 return testNode, nil 37 } 38 39 // Report reports data. 40 func (ts *testSelector) Report(node *registry.Node, cost time.Duration, success error) error { 41 return nil 42 } 43 44 func TestSelectorRegister(t *testing.T) { 45 Register("test-selector", &testSelector{}) 46 assert.NotNil(t, Get("test-selector")) 47 unregisterForTesting("test-selector") 48 } 49 50 func TestSelectorGet(t *testing.T) { 51 Register("test-selector", &testSelector{}) 52 s := Get("test-selector") 53 assert.NotNil(t, s) 54 unregisterForTesting("test-selector") 55 assert.Nil(t, Get("not_exist")) 56 }