github.com/pawelgaczynski/gain@v0.4.0-alpha.0.20230821120126-41f1e60a18da/config_test.go (about) 1 // Copyright (c) 2023 Paweł Gaczyński 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 gain 16 17 import ( 18 "testing" 19 "time" 20 21 "github.com/rs/zerolog" 22 . "github.com/stretchr/testify/require" 23 ) 24 25 func TestConfig(t *testing.T) { 26 opts := []ConfigOption{ 27 WithArchitecture(SocketSharding), 28 WithAsyncHandler(true), 29 WithGoroutinePool(true), 30 WithCPUAffinity(true), 31 WithProcessPriority(true), 32 WithWorkers(128), 33 WithCBPF(true), 34 WithLoadBalancing(LeastConnections), 35 WithSocketRecvBufferSize(4096), 36 WithSocketSendBufferSize(4096), 37 WithTCPKeepAlive(time.Second), 38 WithLoggerLevel(zerolog.DebugLevel), 39 WithPrettyLogger(true), 40 WithMaxSQEntries(4096), 41 WithMaxCQEvents(4096), 42 } 43 44 config := NewConfig(opts...) 45 46 Equal(t, SocketSharding, config.Architecture) 47 Equal(t, true, config.AsyncHandler) 48 Equal(t, true, config.GoroutinePool) 49 Equal(t, true, config.CPUAffinity) 50 Equal(t, true, config.ProcessPriority) 51 Equal(t, 128, config.Workers) 52 Equal(t, true, config.CBPFilter) 53 Equal(t, LeastConnections, config.LoadBalancing) 54 Equal(t, 4096, config.SocketRecvBufferSize) 55 Equal(t, 4096, config.SocketSendBufferSize) 56 Equal(t, time.Second, config.TCPKeepAlive) 57 Equal(t, zerolog.DebugLevel, config.LoggerLevel) 58 Equal(t, true, config.PrettyLogger) 59 Equal(t, uint(4096), config.MaxSQEntries) 60 Equal(t, uint(4096), config.MaxCQEvents) 61 }