github.com/matrixorigin/matrixone@v1.2.0/pkg/proxy/server_test.go (about) 1 // Copyright 2021 - 2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package proxy 16 17 import ( 18 "context" 19 "fmt" 20 "os" 21 "testing" 22 "time" 23 24 "github.com/lni/goutils/leaktest" 25 "github.com/matrixorigin/matrixone/pkg/common/runtime" 26 "github.com/matrixorigin/matrixone/pkg/logservice" 27 "github.com/stretchr/testify/require" 28 ) 29 30 func WithHAKeeperClient(c logservice.ProxyHAKeeperClient) Option { 31 return func(s *Server) { 32 s.haKeeperClient = c 33 } 34 } 35 36 func TestNewServer(t *testing.T) { 37 defer leaktest.AfterTest(t)() 38 39 ctx, cancel := context.WithCancel(context.Background()) 40 defer cancel() 41 runtime.SetupProcessLevelRuntime(runtime.DefaultRuntime()) 42 temp := os.TempDir() 43 listenAddr := fmt.Sprintf("%s/%d.sock", temp, time.Now().Nanosecond()) 44 require.NoError(t, os.RemoveAll(listenAddr)) 45 cfg := Config{ 46 ListenAddress: "unix://" + listenAddr, 47 } 48 hc := &mockHAKeeperClient{} 49 s, err := NewServer(ctx, cfg, WithRuntime(runtime.DefaultRuntime()), 50 WithHAKeeperClient(hc)) 51 defer func() { 52 err := s.Close() 53 require.NoError(t, err) 54 }() 55 require.NoError(t, err) 56 require.NotNil(t, s) 57 }