Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
d0f9d44fe4 | |||
725ed992cc | |||
b8928d3da9 | |||
76090f7569 | |||
f8c68a81f7 |
@ -31,6 +31,9 @@ func (c *cfg) Validate() error {
|
||||
if c.IntValue != 10 {
|
||||
return fmt.Errorf("invalid IntValue %d != %d", 10, c.IntValue)
|
||||
}
|
||||
if c.MapValue["key1"] != true {
|
||||
return fmt.Errorf("invalid MapValue %t != %t", true, c.MapValue["key1"])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -105,3 +108,19 @@ func TestValidate(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
cfg := config.NewConfig()
|
||||
res := cfg.String()
|
||||
if res != "default" {
|
||||
t.Fatalf("string value invalid: %s", res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
cfg := config.NewConfig()
|
||||
res := cfg.Name()
|
||||
if res != "" {
|
||||
t.Fatal("name value not empty")
|
||||
}
|
||||
}
|
||||
|
36
flow/flow_test.go
Normal file
36
flow/flow_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package flow
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func FuzzMarshall(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, ref []byte) {
|
||||
rm := RawMessage(ref)
|
||||
|
||||
b, err := rm.MarshalJSON()
|
||||
if err != nil {
|
||||
t.Errorf("Error MarshalJSON: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(ref, b) {
|
||||
t.Errorf("Error. Expected '%s', was '%s'", ref, b)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzUnmarshall(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, ref string) {
|
||||
b := []byte(ref)
|
||||
rm := RawMessage(b)
|
||||
|
||||
if err := rm.UnmarshalJSON(b); err != nil {
|
||||
t.Errorf("Error UnmarshalJSON: %s", err)
|
||||
}
|
||||
|
||||
if ref != string(rm) {
|
||||
t.Errorf("Error. Expected '%s', was '%s'", ref, rm)
|
||||
}
|
||||
})
|
||||
}
|
@ -214,6 +214,20 @@ func WithMicroKeys() options.Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithAddCallerSkipCount add skip count for copy logger
|
||||
func WithAddCallerSkipCount(n int) options.Option {
|
||||
return func(src interface{}) error {
|
||||
c, err := options.Get(src, ".CallerSkipCount")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = options.Set(src, c.(int)+n, ".CallerSkipCount"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithAddStacktrace controls writing stacktrace on error
|
||||
func WithAddStacktrace(v bool) options.Option {
|
||||
return func(src interface{}) error {
|
||||
|
@ -17,4 +17,6 @@ var (
|
||||
SubscribeMessageTotal = "subscribe_message_total"
|
||||
// SubscribeMessageInflight specifies meter metric name
|
||||
SubscribeMessageInflight = "subscribe_message_inflight"
|
||||
// BrokerGroupLag specifies broker lag
|
||||
BrokerGroupLag = "broker_lag"
|
||||
)
|
||||
|
12
semconv/cache.go
Normal file
12
semconv/cache.go
Normal file
@ -0,0 +1,12 @@
|
||||
package semconv
|
||||
|
||||
var (
|
||||
// CacheRequestDurationSeconds specifies meter metric name
|
||||
CacheRequestDurationSeconds = "cache_request_duration_seconds"
|
||||
// ClientRequestLatencyMicroseconds specifies meter metric name
|
||||
CacheRequestLatencyMicroseconds = "cache_request_latency_microseconds"
|
||||
// CacheRequestTotal specifies meter metric name
|
||||
CacheRequestTotal = "cache_request_total"
|
||||
// CacheRequestInflight specifies meter metric name
|
||||
CacheRequestInflight = "cache_request_inflight"
|
||||
)
|
25
util/xpool/pool.go
Normal file
25
util/xpool/pool.go
Normal file
@ -0,0 +1,25 @@
|
||||
package pool
|
||||
|
||||
import "sync"
|
||||
|
||||
type Pool[T any] struct {
|
||||
p *sync.Pool
|
||||
}
|
||||
|
||||
func NewPool[T any](fn func() T) Pool[T] {
|
||||
return Pool[T]{
|
||||
p: &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return fn()
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (p Pool[T]) Get() T {
|
||||
return p.p.Get().(T)
|
||||
}
|
||||
|
||||
func (p Pool[T]) Put(t T) {
|
||||
p.p.Put(t)
|
||||
}
|
27
util/xpool/pool_test.go
Normal file
27
util/xpool/pool_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package pool
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBytes(t *testing.T) {
|
||||
p := NewPool(func() *bytes.Buffer { return bytes.NewBuffer(nil) })
|
||||
b := p.Get()
|
||||
b.Write([]byte(`test`))
|
||||
if b.String() != "test" {
|
||||
t.Fatal("pool not works")
|
||||
}
|
||||
p.Put(b)
|
||||
}
|
||||
|
||||
func TestStrings(t *testing.T) {
|
||||
p := NewPool(func() *strings.Builder { return &strings.Builder{} })
|
||||
b := p.Get()
|
||||
b.Write([]byte(`test`))
|
||||
if b.String() != "test" {
|
||||
t.Fatal("pool not works")
|
||||
}
|
||||
p.Put(b)
|
||||
}
|
Loading…
Reference in New Issue
Block a user