Files
Igor Sirotin f3e4363808 refactor: move protocol to internal/protocol
Part of the Go project layout migration, item 27.

Pure move plus import-path rewrite across 502 files. No API or behaviour
change. `internal/` keeps the messaging application logic unimportable
from outside the module, which is what the issue asks for -- status-go is
consumed through the C-bindings in mobile/, not as a Go library.

Things that had to follow the move, beyond the Go imports:

- tools/generate-handlers/template.txt. messenger_handlers.go is
  generated, and the template hard-codes the imports it emits, so the
  generated file kept importing protocol/common and failed typecheck.
- .gitignore. The ignore rule for that generated file was pinned to the
  old path; without moving it, a 1486-line generated file starts being
  tracked.
- Makefile: the logosstorage and torrent test targets (both the archive
  packages and ./protocol itself), the archive README, migration-protocol.
- scripts/run_unit_tests.sh, which names the protocol package explicitly
  to shard its tests.
- scripts/cleanup_generated_files.sh and .golangci.yml.

scripts/migration_check.sh also needed a fix that is not specific to this
move: it validated every file the branch touched under a migration dir
against the timestamp naming rule, and a directory rename makes every
migration in it look newly added. It now excludes renames, so moving a
migration is not mistaken for adding one.

refs #7067
2026-08-21 10:11:05 +02:00

82 lines
2.1 KiB
Go

package zaputil
import (
"io/ioutil"
"testing"
"time"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func TestJSONHexEncoder(t *testing.T) {
encoder := NewJSONHexEncoder(zap.NewDevelopmentEncoderConfig())
encoder.AddBinary("test-key", []byte{0x01, 0x02, 0x03})
buf, err := encoder.EncodeEntry(zapcore.Entry{
LoggerName: "",
Time: time.Now(),
Level: zapcore.DebugLevel,
Message: "",
}, nil)
require.NoError(t, err)
require.Contains(t, buf.String(), `"test-key":"0x010203"`)
}
func TestLoggerWithJSONHexEncoder(t *testing.T) {
err := RegisterJSONHexEncoder()
require.NoError(t, err)
tmpFile, err := ioutil.TempFile("", "")
require.NoError(t, err)
cfg := zap.NewDevelopmentConfig()
cfg.OutputPaths = []string{tmpFile.Name()}
cfg.Encoding = "json-hex"
l, err := cfg.Build()
require.NoError(t, err)
l.With(zap.Binary("some-field", []byte{0x01, 0x02, 0x03})).Debug("test message")
err = l.Sync()
require.NoError(t, err)
data, err := ioutil.ReadFile(tmpFile.Name())
require.NoError(t, err)
require.Contains(t, string(data), "0x010203")
}
func TestConsoleHexEncoder(t *testing.T) {
encoder := NewConsoleHexEncoder(zap.NewDevelopmentEncoderConfig())
encoder.AddBinary("test-key", []byte{0x01, 0x02, 0x03})
buf, err := encoder.EncodeEntry(zapcore.Entry{
LoggerName: "",
Time: time.Now(),
Level: zapcore.DebugLevel,
Message: "",
}, nil)
require.NoError(t, err)
require.Contains(t, buf.String(), `{"test-key": "0x010203"}`)
}
func TestLoggerWithConsoleHexEncoder(t *testing.T) {
err := RegisterConsoleHexEncoder()
require.NoError(t, err)
tmpFile, err := ioutil.TempFile("", "")
require.NoError(t, err)
cfg := zap.NewDevelopmentConfig()
cfg.OutputPaths = []string{tmpFile.Name()}
cfg.Encoding = "console-hex"
l, err := cfg.Build()
require.NoError(t, err)
l.With(zap.Binary("some-field", []byte{0x01, 0x02, 0x03})).Debug("test message")
err = l.Sync()
require.NoError(t, err)
data, err := ioutil.ReadFile(tmpFile.Name())
require.NoError(t, err)
require.Contains(t, string(data), "0x010203")
}