Compare commits

..

2 Commits

Author SHA1 Message Date
3e86864ce7 [v3] remove using global map for default codecs (#224)
Some checks failed
test / test (push) Failing after 15m22s
coverage / build (push) Failing after 15m33s
* remove using global map for default codecs

* fix tests
2025-10-15 21:33:32 +03:00
vtolstov
a68d3b24b8 Apply Code Coverage Badge 2025-09-20 21:10:43 +00:00
6 changed files with 7 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
# Micro
![Coverage](https://img.shields.io/badge/Coverage-33.6%25-yellow)
![Coverage](https://img.shields.io/badge/Coverage-34.1%25-yellow)
[![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Doc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/go.unistack.org/micro/v3?tab=overview)
[![Status](https://git.unistack.org/unistack-org/micro/actions/workflows/job_tests.yml/badge.svg?branch=v3)](https://git.unistack.org/unistack-org/micro/actions?query=workflow%3Abuild+branch%3Av3+event%3Apush)

View File

@@ -17,11 +17,6 @@ import (
"go.unistack.org/micro/v3/tracer"
)
// DefaultCodecs will be used to encode/decode data
var DefaultCodecs = map[string]codec.Codec{
"application/octet-stream": codec.NewCodec(),
}
type noopClient struct {
funcPublish FuncPublish
funcBatchPublish FuncBatchPublish
@@ -178,9 +173,6 @@ func (n *noopClient) newCodec(contentType string) (codec.Codec, error) {
if cf, ok := n.opts.Codecs[contentType]; ok {
return cf, nil
}
if cf, ok := DefaultCodecs[contentType]; ok {
return cf, nil
}
return nil, codec.ErrUnknownContentType
}

View File

@@ -3,6 +3,8 @@ package client
import (
"context"
"testing"
"go.unistack.org/micro/v3/codec"
)
type testHook struct {
@@ -19,7 +21,7 @@ func (t *testHook) Publish(fn FuncPublish) FuncPublish {
func TestNoopHook(t *testing.T) {
h := &testHook{}
c := NewClient(Hooks(HookPublish(h.Publish)))
c := NewClient(Codec("application/octet-stream", codec.NewCodec()), Hooks(HookPublish(h.Publish)))
if err := c.Init(); err != nil {
t.Fatal(err)

View File

@@ -198,7 +198,7 @@ func NewOptions(opts ...Option) Options {
options := Options{
Context: context.Background(),
ContentType: DefaultContentType,
Codecs: DefaultCodecs,
Codecs: make(map[string]codec.Codec),
CallOptions: CallOptions{
Context: context.Background(),
Backoff: DefaultBackoff,

View File

@@ -62,7 +62,7 @@ func TestTime(t *testing.T) {
WithHandlerFunc(slog.NewTextHandler),
logger.WithAddStacktrace(true),
logger.WithTimeFunc(func() time.Time {
return time.Unix(0, 0)
return time.Unix(0, 0).UTC()
}),
)
if err := l.Init(logger.WithFields("key1", "val1")); err != nil {
@@ -71,8 +71,7 @@ func TestTime(t *testing.T) {
l.Error(ctx, "msg1", errors.New("err"))
if !bytes.Contains(buf.Bytes(), []byte(`timestamp=1970-01-01T03:00:00.000000000+03:00`)) &&
!bytes.Contains(buf.Bytes(), []byte(`timestamp=1970-01-01T00:00:00.000000000Z`)) {
if !bytes.Contains(buf.Bytes(), []byte(`timestamp=1970-01-01T00:00:00.000000000Z`)) {
t.Fatalf("logger error not works, buf contains: %s", buf.Bytes())
}
}

View File

@@ -21,11 +21,6 @@ import (
"go.unistack.org/micro/v3/util/rand"
)
// DefaultCodecs will be used to encode/decode
var DefaultCodecs = map[string]codec.Codec{
"application/octet-stream": codec.NewCodec(),
}
const (
defaultContentType = "application/json"
)
@@ -93,9 +88,6 @@ func (n *noopServer) newCodec(contentType string) (codec.Codec, error) {
if cf, ok := n.opts.Codecs[contentType]; ok {
return cf, nil
}
if cf, ok := DefaultCodecs[contentType]; ok {
return cf, nil
}
return nil, codec.ErrUnknownContentType
}