From 2b5d211e727562f82a1b4feb6a5eb3dfa245b30c Mon Sep 17 00:00:00 2001 From: number571 Date: Wed, 30 Apr 2025 22:39:03 +0700 Subject: [PATCH] update --- Makefile | 12 +- README.md | 2 +- bin/.gitignore | 3 - bin/Makefile | 6 - build/build.go | 3 - build/build_test.go | 5 - changelog_test.go | 58 ----- cmd/Makefile | 7 - cmd/tools/Makefile | 9 - cmd/tools/keygen/.gitignore | 2 - cmd/tools/keygen/Makefile | 18 -- cmd/tools/keygen/README.md | 15 -- cmd/tools/keygen/main.go | 90 -------- cmd/tools/pmanager/.gitignore | 1 - cmd/tools/pmanager/Makefile | 17 -- cmd/tools/pmanager/README.md | 20 -- cmd/tools/pmanager/main.go | 80 ------- pkg/anonymity/anonymity.go | 2 +- pkg/anonymity/anonymity_test.go | 12 +- pkg/anonymity/examples/echo/main.go | 4 +- pkg/anonymity/examples/ping-pong/main.go | 2 +- pkg/anonymity/head.go | 4 +- pkg/anonymity/logger/log_builder.go | 2 +- pkg/anonymity/queue/queue.go | 6 +- pkg/anonymity/queue/queue_test.go | 8 +- pkg/client/client_test.go | 6 +- pkg/client/examples/file_encrypt/decrypt.go | 12 +- pkg/client/examples/file_encrypt/encrypt.go | 8 +- pkg/client/examples/file_encrypt/filehash.go | 6 +- pkg/crypto/keybuilder/keybuilder.go | 4 +- pkg/crypto/puzzle/puzzle.go | 2 +- pkg/crypto/puzzle/puzzle_bench_test.go | 2 +- pkg/crypto/puzzle/puzzle_test.go | 2 +- pkg/crypto/random/random.go | 2 +- pkg/crypto/symmetric/symmetric.go | 2 +- pkg/logger/logger_test.go | 12 +- pkg/message/layer1/message_bench_test.go | 2 +- pkg/network/conn/conn.go | 4 +- pkg/network/conn/conn_test.go | 10 +- pkg/network/connkeeper/connkeeper_test.go | 8 +- pkg/network/examples/broadcast/main.go | 6 +- pkg/network/examples/ping-pong/main.go | 8 +- pkg/network/network.go | 6 +- pkg/network/network_test.go | 12 +- pkg/payload/joiner/joiner32.go | 4 +- pkg/state/state_test.go | 10 +- pkg/storage/cache/cache_test.go | 6 +- pkg/storage/database/database_test.go | 14 +- test/result/badge_codelines.svg | 2 +- test/result/coverage.svg | 224 +++++++++---------- test/utils/testutils_test.go | 6 +- 51 files changed, 215 insertions(+), 553 deletions(-) delete mode 100644 bin/.gitignore delete mode 100644 bin/Makefile delete mode 100644 build/build.go delete mode 100644 build/build_test.go delete mode 100644 changelog_test.go delete mode 100644 cmd/Makefile delete mode 100644 cmd/tools/Makefile delete mode 100644 cmd/tools/keygen/.gitignore delete mode 100644 cmd/tools/keygen/Makefile delete mode 100644 cmd/tools/keygen/README.md delete mode 100644 cmd/tools/keygen/main.go delete mode 100644 cmd/tools/pmanager/.gitignore delete mode 100644 cmd/tools/pmanager/Makefile delete mode 100644 cmd/tools/pmanager/README.md delete mode 100644 cmd/tools/pmanager/main.go diff --git a/Makefile b/Makefile index 560e7fcb..73a65a8d 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ _GO_TEST_LIST=\ grep -v /examples/ | \ grep -v /vendor/ -.PHONY: default clean go-fmt-vet \ +.PHONY: default go-fmt-vet \ lint-run test-run \ test-coverage test-coverage-view test-coverage-treemap test-coverage-badge \ git-status git-push \ @@ -24,10 +24,6 @@ _GO_TEST_LIST=\ default: lint-run test-run -clean: - make -C ./bin clean - make -C ./cmd clean - go-fmt-vet: go fmt ./... go vet ./... @@ -35,13 +31,13 @@ go-fmt-vet: ### INSTALL install-deps: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.0 + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.2 go install github.com/nikolaydubina/go-cover-treemap@v1.4.2 ### LINT -lint-run: clean go-fmt-vet - golangci-lint run -E "gosec,unconvert,gosimple,goconst,gocyclo,err113,ineffassign,unparam,unused,bodyclose,noctx,perfsprint,prealloc,gocritic,govet,revive,staticcheck,errcheck,errorlint,nestif,maintidx" +lint-run: go-fmt-vet + golangci-lint run -E "gosec,unconvert,goconst,gocyclo,err113,ineffassign,unparam,unused,bodyclose,noctx,perfsprint,prealloc,gocritic,govet,staticcheck,errcheck,errorlint,nestif,maintidx" ### TEST # example run: make test-run N=10 diff --git a/README.md b/README.md index bde2e795..1a1465ea 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ All cmd programs are compiled for {`amd64`, `arm64`} ARCH and {`windows`, `linux There are a number of dependencies that represent separate applications for providing additional information about the quality of the code. These applications are not entered into the project, but are loaded via the `make install-deps` command. The list of applications is as follows: -1. golangci-lint [github.com/golangci/golangci-lint/cmd/golangci-lintv1.60.0](https://github.com/golangci/golangci-lint/tree/v1.60.0) +1. golangci-lint [github.com/golangci/golangci-lint@v2.1.2](https://github.com/golangci/golangci-lint/tree/v2.1.2) 2. go-cover-treemap [github.com/nikolaydubina/go-cover-treemap@v1.4.2](https://github.com/nikolaydubina/go-cover-treemap/tree/v1.4.2) ## Theoretical works diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index a0991ff4..00000000 --- a/bin/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -!.gitignore -!Makefile diff --git a/bin/Makefile b/bin/Makefile deleted file mode 100644 index 667e1b99..00000000 --- a/bin/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -.PHONY: default remove-std clean -default: clean -clean: - ls | grep -xv ".gitignore" | grep -xv "Makefile" | xargs rm | true -remove-std: - ls | grep -xv ".gitignore" | grep -xv "Makefile" | grep -xv -E ".*_.*_.*" | xargs rm diff --git a/build/build.go b/build/build.go deleted file mode 100644 index 5890d08f..00000000 --- a/build/build.go +++ /dev/null @@ -1,3 +0,0 @@ -package build - -const CVersion = "v1.7.11~" diff --git a/build/build_test.go b/build/build_test.go deleted file mode 100644 index 30f6334f..00000000 --- a/build/build_test.go +++ /dev/null @@ -1,5 +0,0 @@ -package build - -import "testing" - -func TestNothing(_ *testing.T) {} diff --git a/changelog_test.go b/changelog_test.go deleted file mode 100644 index 6aa0eea1..00000000 --- a/changelog_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package gopeer - -import ( - _ "embed" - "regexp" - "strings" - "testing" - - "github.com/number571/go-peer/build" -) - -var ( - //go:embed CHANGELOG.md - tgCHANGELOG string -) - -func TestGoPeerVersion(t *testing.T) { - t.Parallel() - - re := regexp.MustCompile(`##\s+(v\d+\.\d+\.\d+~?)\s+`) - match := re.FindAllStringSubmatch(tgCHANGELOG, -1) - if len(match) < 2 { - t.Error("versions not found") - return - } - - if strings.HasSuffix(build.CVersion, "~") { - if match[0][1] != build.CVersion { - t.Error("the versions do not match") - return - } - } else { - // current version is always previous version in the changelog - if match[1][1] != build.CVersion { - t.Error("the versions do not match") - return - } - } - - if match[0][1] == match[1][1] { - t.Error("the same versions inline") - return - } - - for i := 0; i < len(match); i++ { - for j := i + 1; j < len(match)-1; j++ { - if match[i][1] == match[j][1] { - t.Errorf("found the same versions (i=%d, j=%d)", i, j) - return - } - } - } - - if strings.Count(tgCHANGELOG, "*??? ??, ????*") != 1 { - t.Error("is there no new version or more than one new version?") - return - } -} diff --git a/cmd/Makefile b/cmd/Makefile deleted file mode 100644 index 6c5d597f..00000000 --- a/cmd/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -.PHONY: default build clean - -default: build -build: - make -C ./tools build -clean: - make -C ./tools clean diff --git a/cmd/tools/Makefile b/cmd/tools/Makefile deleted file mode 100644 index c5c62c68..00000000 --- a/cmd/tools/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -.PHONY: default build clean - -default: build -build: - make -C ./keygen build - make -C ./pmanager build -clean: - make -C ./keygen clean - make -C ./pmanager clean diff --git a/cmd/tools/keygen/.gitignore b/cmd/tools/keygen/.gitignore deleted file mode 100644 index c3928b63..00000000 --- a/cmd/tools/keygen/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.key -tkeygen diff --git a/cmd/tools/keygen/Makefile b/cmd/tools/keygen/Makefile deleted file mode 100644 index f153e5ff..00000000 --- a/cmd/tools/keygen/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -GC=go build -ROOPATH=../../.. -BINPATH=$(ROOPATH)/bin - -.PHONY: default build clean -default: build -build: - $(GC) -o $(BINPATH)/tkeygen . # main - - for arch in amd64 arm64; \ - do \ - CGO_ENABLED=0 GOOS=linux GOARCH=$${arch} go build -o $(BINPATH)/tkeygen_$${arch}_linux .; \ - CGO_ENABLED=0 GOOS=windows GOARCH=$${arch} go build -o $(BINPATH)/tkeygen_$${arch}_windows.exe .; \ - CGO_ENABLED=0 GOOS=darwin GOARCH=$${arch} go build -o $(BINPATH)/tkeygen_$${arch}_darwin .; \ - done; -clean: - rm -f *.key - rm -f tkeygen $(BINPATH)/tkeygen $(BINPATH)/tkeygen_* diff --git a/cmd/tools/keygen/README.md b/cmd/tools/keygen/README.md deleted file mode 100644 index 567c3219..00000000 --- a/cmd/tools/keygen/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Keygen - -> Asymmetric key generator - -```bash -usage: - go run . [-seed] -``` - -## Example - -```bash -go run . -seed - -``` diff --git a/cmd/tools/keygen/main.go b/cmd/tools/keygen/main.go deleted file mode 100644 index ba0485a8..00000000 --- a/cmd/tools/keygen/main.go +++ /dev/null @@ -1,90 +0,0 @@ -package main - -import ( - "bufio" - "flag" - "fmt" - "os" - "os/exec" - "runtime" - - "github.com/number571/go-peer/pkg/crypto/asymmetric" - "github.com/number571/go-peer/pkg/crypto/random" - "github.com/number571/go-peer/pkg/encoding" -) - -func main() { - seed := flag.Bool("seed", false, "set seed private key") - flag.Parse() - - seedBytes := random.NewRandom().GetBytes(asymmetric.CKeySeedSize) - if *seed { - seedBytes = encoding.HexDecode(readUntilEOL()) - if len(seedBytes) != asymmetric.CKeySeedSize { - panic("len(seedBytes) != asymmetric.CKeySeedSize") - } - } - - priv := asymmetric.NewPrivKeyFromSeed(seedBytes) - if err := os.WriteFile("seed.key", []byte(encoding.HexEncode(seedBytes)), 0o600); err != nil { - panic(err) - } - if err := os.WriteFile("priv.key", []byte(priv.ToString()), 0o600); err != nil { - panic(err) - } - if err := os.WriteFile("pub.key", []byte(priv.GetPubKey().ToString()), 0o600); err != nil { - panic(err) - } -} - -func readUntilEOL() string { - var ( - p = make([]byte, 0, 256) - b = make([]byte, 1) - ) - - if runtime.GOOS == "windows" { - res, _, err := bufio.NewReader(os.Stdin).ReadLine() - if err != nil { - panic(err) - } - return string(res) - } - - if err := exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run(); err != nil { - panic(err) - } - if err := exec.Command("stty", "-F", "/dev/tty", "-echo").Run(); err != nil { - panic(err) - } - defer func() { _ = exec.Command("stty", "-F", "/dev/tty", "echo").Run() }() - - for { - if _, err := os.Stdin.Read(b); err != nil { - panic(err) - } - if b[0] == '\n' { // - fmt.Println() - break - } - if b[0] == 127 { // - if len(p) == 0 { - continue - } - fmt.Print("\r") - for i := 0; i < len(p); i++ { - fmt.Print(" ") - } - fmt.Print("\r") - for i := 0; i < len(p)-1; i++ { - fmt.Print("*") - } - p = p[:len(p)-1] - continue - } - fmt.Print("*") - p = append(p, b[0]) - } - - return string(p) -} diff --git a/cmd/tools/pmanager/.gitignore b/cmd/tools/pmanager/.gitignore deleted file mode 100644 index ebea664e..00000000 --- a/cmd/tools/pmanager/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tpmanager diff --git a/cmd/tools/pmanager/Makefile b/cmd/tools/pmanager/Makefile deleted file mode 100644 index bc899f5a..00000000 --- a/cmd/tools/pmanager/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -GC=go build -ROOPATH=../../.. -BINPATH=$(ROOPATH)/bin - -.PHONY: default build -default: build -build: - $(GC) -o $(BINPATH)/tpmanager . # main - - for arch in amd64 arm64; \ - do \ - CGO_ENABLED=0 GOOS=linux GOARCH=$${arch} go build -o $(BINPATH)/tpmanager_$${arch}_linux .; \ - CGO_ENABLED=0 GOOS=windows GOARCH=$${arch} go build -o $(BINPATH)/tpmanager_$${arch}_windows.exe .; \ - CGO_ENABLED=0 GOOS=darwin GOARCH=$${arch} go build -o $(BINPATH)/tpmanager_$${arch}_darwin .; \ - done; -clean: - rm -f tpmanager $(BINPATH)/tpmanager $(BINPATH)/tpmanager_* diff --git a/cmd/tools/pmanager/README.md b/cmd/tools/pmanager/README.md deleted file mode 100644 index 0ee9ce9f..00000000 --- a/cmd/tools/pmanager/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# PManager - -> Stateless password manager - -```bash -usage: - ./main -salt=[service-name] -work=[diff-size] -stdin: - [master-key]EOL -``` - -EOL - End of Line (Enter) - -## Example - -```bash -$ go run . -salt="service-name" -work=24 -master-key -J64mESAVm2o-8q6nWaywsoQbQvn8pf7U74O-Vr9HwSDu -``` diff --git a/cmd/tools/pmanager/main.go b/cmd/tools/pmanager/main.go deleted file mode 100644 index 1e5badd3..00000000 --- a/cmd/tools/pmanager/main.go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "bufio" - "encoding/base64" - "flag" - "fmt" - "os" - "os/exec" - "runtime" - - "github.com/number571/go-peer/pkg/crypto/keybuilder" -) - -const ( - cKeySize = 33 // bytes -) - -func main() { - saltParam := flag.String("salt", "_salt_", "default salt value") - workParam := flag.Uint("work", 24, "default work value") - flag.Parse() - - keyBuilder := keybuilder.NewKeyBuilder(1<<(*workParam), []byte(*saltParam)) - gotPassword := keyBuilder.Build(readUntilEOL(), cKeySize) - - fmt.Println(base64.URLEncoding.EncodeToString(gotPassword)) -} - -func readUntilEOL() string { - var ( - p = make([]byte, 0, 256) - b = make([]byte, 1) - ) - - if runtime.GOOS == "windows" { - res, _, err := bufio.NewReader(os.Stdin).ReadLine() - if err != nil { - panic(err) - } - return string(res) - } - - if err := exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run(); err != nil { - panic(err) - } - if err := exec.Command("stty", "-F", "/dev/tty", "-echo").Run(); err != nil { - panic(err) - } - defer func() { _ = exec.Command("stty", "-F", "/dev/tty", "echo").Run() }() - - for { - if _, err := os.Stdin.Read(b); err != nil { - panic(err) - } - if b[0] == '\n' { // - fmt.Println() - break - } - if b[0] == 127 { // - if len(p) == 0 { - continue - } - fmt.Print("\r") - for i := 0; i < len(p); i++ { - fmt.Print(" ") - } - fmt.Print("\r") - for i := 0; i < len(p)-1; i++ { - fmt.Print("*") - } - p = p[:len(p)-1] - continue - } - fmt.Print("*") - p = append(p, b[0]) - } - - return string(p) -} diff --git a/pkg/anonymity/anonymity.go b/pkg/anonymity/anonymity.go index 38970846..82b870db 100644 --- a/pkg/anonymity/anonymity.go +++ b/pkg/anonymity/anonymity.go @@ -182,7 +182,7 @@ func (p *sNode) FetchPayload( pRecv asymmetric.IPubKey, pPld payload.IPayload32, ) ([]byte, error) { - headAction := sAction(random.NewRandom().GetUint64()) + headAction := sAction(random.NewRandom().GetUint64()) //nolint:gosec actionKey := newActionKey(pRecv, headAction) p.setAction(actionKey) diff --git a/pkg/anonymity/anonymity_test.go b/pkg/anonymity/anonymity_test.go index 86db95c7..67095a8a 100644 --- a/pkg/anonymity/anonymity_test.go +++ b/pkg/anonymity/anonymity_test.go @@ -1,4 +1,4 @@ -// nolint: goerr113 +// nolint: err113 package anonymity import ( @@ -387,7 +387,7 @@ func TestHandleWrapper(t *testing.T) { node.HandleFunc( 111, func(_ context.Context, _ INode, _ asymmetric.IPubKey, _ []byte) ([]byte, error) { - return nil, errors.New("some error") + return nil, errors.New("some error") //nolint:err113 }, ) @@ -451,7 +451,7 @@ func TestHandleWrapper(t *testing.T) { return } - node.fKVDatavase.Close() + _ = node.fKVDatavase.Close() netMsg41 := node.testNewNetworkMessage(sett, msg4) if err := handler(ctx, netMsg41); err == nil { t.Error("got success code with closed database") @@ -759,14 +759,14 @@ func testRunNode(ctx context.Context, timeWait time.Duration, addr string, typeD func testFreeNodes(nodes []INode, typeDB int) { for _, node := range nodes { - node.GetKVDatabase().Close() + _ = node.GetKVDatabase().Close() } testDeleteDB(typeDB) } func testDeleteDB(typeDB int) { for i := 0; i < 5; i++ { - os.RemoveAll(fmt.Sprintf(tcPathDBTemplate, typeDB, i)) + _ = os.RemoveAll(fmt.Sprintf(tcPathDBTemplate, typeDB, i)) } } @@ -783,6 +783,6 @@ func (p *sNode) testNewNetworkMessage(pSett layer1.IConstructSettings, pMsgBytes type tsDatabase struct{} func (p *tsDatabase) Get([]byte) ([]byte, error) { return nil, database.ErrNotFound } -func (p *tsDatabase) Set([]byte, []byte) error { return errors.New("some error") } +func (p *tsDatabase) Set([]byte, []byte) error { return errors.New("some error") } //nolint:err113 func (p *tsDatabase) Del([]byte) error { return nil } func (p *tsDatabase) Close() error { return nil } diff --git a/pkg/anonymity/examples/echo/main.go b/pkg/anonymity/examples/echo/main.go index 3e67e7f4..de688c0d 100644 --- a/pkg/anonymity/examples/echo/main.go +++ b/pkg/anonymity/examples/echo/main.go @@ -35,7 +35,7 @@ func runClientNode() anonymity.INode { network, node := newNode("cnode", "") go func() { _ = node.Run(ctx) }() - network.AddConnection(ctx, nodeAddress) + _ = network.AddConnection(ctx, nodeAddress) return node } @@ -46,7 +46,7 @@ func runServiceNode() anonymity.INode { node.HandleFunc( nodeRouter, func(_ context.Context, _ anonymity.INode, _ asymmetric.IPubKey, b []byte) ([]byte, error) { - return []byte(fmt.Sprintf("echo: %s", string(b))), nil + return []byte("echo: " + string(b)), nil }, ) diff --git a/pkg/anonymity/examples/ping-pong/main.go b/pkg/anonymity/examples/ping-pong/main.go index e942da26..4a0b3236 100644 --- a/pkg/anonymity/examples/ping-pong/main.go +++ b/pkg/anonymity/examples/ping-pong/main.go @@ -58,7 +58,7 @@ func runClientNode() anonymity.INode { node.HandleFunc(nodeRouter, handler) go func() { _ = node.Run(ctx) }() - network.AddConnection(ctx, nodeAddress) + _ = network.AddConnection(ctx, nodeAddress) return node } diff --git a/pkg/anonymity/head.go b/pkg/anonymity/head.go index 30601529..5116ae15 100644 --- a/pkg/anonymity/head.go +++ b/pkg/anonymity/head.go @@ -24,11 +24,11 @@ func joinHead(pAction iAction, pRoute uint32) iHead { } func (p sHead) getRoute() uint32 { - return uint32(p & 0xFFFFFFFF) + return uint32(p & 0xFFFFFFFF) //nolint:gosec } func (p sHead) getAction() iAction { - return sAction(p >> 32) + return sAction(p >> 32) //nolint:gosec } func (p sHead) uint64() uint64 { diff --git a/pkg/anonymity/logger/log_builder.go b/pkg/anonymity/logger/log_builder.go index a8f6676e..b1eca929 100644 --- a/pkg/anonymity/logger/log_builder.go +++ b/pkg/anonymity/logger/log_builder.go @@ -81,7 +81,7 @@ func (p *sLogger) WithPubKey(pPubKey asymmetric.IPubKey) ILogBuilder { } func (p *sLogger) WithSize(pSize int) ILogBuilder { - p.fSize = uint64(pSize) + p.fSize = uint64(pSize) //nolint:gosec return p } diff --git a/pkg/anonymity/queue/queue.go b/pkg/anonymity/queue/queue.go index a030c4f2..0c2e06a0 100644 --- a/pkg/anonymity/queue/queue.go +++ b/pkg/anonymity/queue/queue.go @@ -123,7 +123,7 @@ func (p *sQBProblemProcessor) runMainPoolFiller(pCtx context.Context, pCancel fu case <-pCtx.Done(): return case <-time.After(p.fSettings.GetQueuePeriod()): - break // next consumer + continue case msg := <-p.fMainPool.fRawQueue[i]: if err := p.pushMessage(pCtx, p.fMainPool.fQueue, msg); err != nil { return @@ -134,7 +134,7 @@ func (p *sQBProblemProcessor) runMainPoolFiller(pCtx context.Context, pCancel fu func (p *sQBProblemProcessor) EnqueueMessage(pPubKey asymmetric.IPubKey, pBytes []byte) error { incCount := atomic.AddInt64(&p.fMainPool.fCount, 1) - if uint64(incCount) > uint64(cap(p.fMainPool.fQueue)) { + if uint64(incCount) > uint64(cap(p.fMainPool.fQueue)) { //nolint:gosec atomic.AddInt64(&p.fMainPool.fCount, -1) return ErrQueueLimit } @@ -188,7 +188,7 @@ func (p *sQBProblemProcessor) DequeueMessage(pCtx context.Context) layer1.IMessa func (p *sQBProblemProcessor) fillRandPool(pCtx context.Context) error { incCount := atomic.AddInt64(&p.fRandPool.fCount, 1) - if uint64(incCount) > uint64(cap(p.fRandPool.fQueue)) { + if uint64(incCount) > uint64(cap(p.fRandPool.fQueue)) { //nolint:gosec atomic.AddInt64(&p.fRandPool.fCount, -1) select { case <-pCtx.Done(): diff --git a/pkg/anonymity/queue/queue_test.go b/pkg/anonymity/queue/queue_test.go index 8c40123c..6d4b3b15 100644 --- a/pkg/anonymity/queue/queue_test.go +++ b/pkg/anonymity/queue/queue_test.go @@ -1,4 +1,4 @@ -// nolint: goerr113 +// nolint: err113 package queue import ( @@ -117,7 +117,7 @@ func TestRunStopQueue(t *testing.T) { if uint64(len(sQueue.fRandPool.fQueue)) == sett.GetQueuePoolCap()[0] { return nil } - return errors.New("len(void queue) != max capacity") + return errors.New("len(void queue) != max capacity") //nolint:err113 }) if err != nil { t.Error(err) @@ -218,7 +218,7 @@ func testQueue(queue IQBProblemProcessor) error { for i := 0; i < len(msgs)-1; i++ { for j := i + 1; j < len(msgs); j++ { if bytes.Equal(msgs[i].GetHash(), msgs[j].GetHash()) { - return fmt.Errorf("hash of messages equals (%d and %d)", i, i) + return fmt.Errorf("hash of messages equals (%d and %d)", i, i) //nolint:err113 } } } @@ -232,7 +232,7 @@ func testQueue(queue IQBProblemProcessor) error { cancel() if <-notClosed { - return errors.New("success dequeue with close") + return errors.New("success dequeue with close") //nolint:err113 } return nil } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 41b41ffe..27c5252f 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -1,4 +1,4 @@ -// nolint: goerr113 +// nolint: err113 package client import ( @@ -226,12 +226,12 @@ func (p *tsPrivKey) GetDSAPrivKey() asymmetric.IDSAPrivKey { return &tsDSAPrivKe func (p *tsKEMPubKey) ToBytes() []byte { return nil } func (p *tsKEMPubKey) Encapsulate() ([]byte, []byte, error) { - return nil, nil, errors.New("some error") + return nil, nil, errors.New("some error") //nolint:err113 } func (p *tsKEMPrivKey) ToBytes() []byte { return nil } func (p *tsKEMPrivKey) GetPubKey() asymmetric.IKEMPubKey { return &tsKEMPubKey{} } -func (p *tsKEMPrivKey) Decapsulate([]byte) ([]byte, error) { return nil, errors.New("some error") } +func (p *tsKEMPrivKey) Decapsulate([]byte) ([]byte, error) { return nil, errors.New("some error") } //nolint:err113 func (p *tsDSAPrivKey) ToBytes() []byte { return nil } func (p *tsDSAPrivKey) GetPubKey() asymmetric.IDSAPubKey { return &tsDSAPubKey{} } diff --git a/pkg/client/examples/file_encrypt/decrypt.go b/pkg/client/examples/file_encrypt/decrypt.go index 8cbd7f14..c95a31a0 100644 --- a/pkg/client/examples/file_encrypt/decrypt.go +++ b/pkg/client/examples/file_encrypt/decrypt.go @@ -12,17 +12,17 @@ import ( func decrypt(client client.IClient, outFilename, inFilename string) error { mapKeys := asymmetric.NewMapPubKeys(client.GetPrivKey().GetPubKey()) - infile, err := os.Open(inFilename) + infile, err := os.Open(inFilename) //nolint:gosec if err != nil { return err } - defer infile.Close() + defer func() { _ = infile.Close() }() - outfile, err := os.Create(outFilename) + outfile, err := os.Create(outFilename) //nolint:gosec if err != nil { return err } - defer infile.Close() + defer func() { _ = infile.Close() }() buf := make([]byte, client.GetMessageSize()) for i := 0; ; i++ { @@ -33,8 +33,8 @@ func decrypt(client client.IClient, outFilename, inFilename string) error { } return err } - if uint64(n) != client.GetMessageSize() { - return errors.New("uint64(n) != msgSize") + if uint64(n) != client.GetMessageSize() { //nolint:gosec + return errors.New("uint64(n) != msgSize") //nolint:err113 } _, chunk, err := client.DecryptMessage(mapKeys, buf[:n]) if err != nil { diff --git a/pkg/client/examples/file_encrypt/encrypt.go b/pkg/client/examples/file_encrypt/encrypt.go index 19cf910a..f4897849 100644 --- a/pkg/client/examples/file_encrypt/encrypt.go +++ b/pkg/client/examples/file_encrypt/encrypt.go @@ -11,17 +11,17 @@ import ( func encrypt(client client.IClient, outFilename, inFilename string) error { pldLimit := client.GetPayloadLimit() - infile, err := os.Open(inFilename) + infile, err := os.Open(inFilename) //nolint:gosec if err != nil { return err } - defer infile.Close() + defer func() { _ = infile.Close() }() - outfile, err := os.Create(outFilename) + outfile, err := os.Create(outFilename) //nolint:gosec if err != nil { return err } - defer infile.Close() + defer func() { _ = infile.Close() }() buf := make([]byte, pldLimit) for i := 0; ; i++ { diff --git a/pkg/client/examples/file_encrypt/filehash.go b/pkg/client/examples/file_encrypt/filehash.go index 8cebcc62..afdcfc73 100644 --- a/pkg/client/examples/file_encrypt/filehash.go +++ b/pkg/client/examples/file_encrypt/filehash.go @@ -8,15 +8,15 @@ import ( ) func fileHash(filename string) []byte { - f, err := os.Open(filename) + f, err := os.Open(filename) //nolint:gosec if err != nil { log.Fatal(err) } - defer f.Close() + defer func() { _ = f.Close() }() h := sha256.New() if _, err := io.Copy(h, f); err != nil { - log.Fatal(err) + log.Fatal(err) //nolint:gocritic } return h.Sum(nil) diff --git a/pkg/crypto/keybuilder/keybuilder.go b/pkg/crypto/keybuilder/keybuilder.go index 63412945..9094956a 100644 --- a/pkg/crypto/keybuilder/keybuilder.go +++ b/pkg/crypto/keybuilder/keybuilder.go @@ -26,8 +26,8 @@ func (p *sKeyBuilder) Build(pPassword string, pKeyLen uint64) []byte { return pbkdf2.Key( []byte(pPassword), p.fSalt, - int(p.fIterN), - int(pKeyLen), + int(p.fIterN), //nolint:gosec + int(pKeyLen), //nolint:gosec sha512.New, ) } diff --git a/pkg/crypto/puzzle/puzzle.go b/pkg/crypto/puzzle/puzzle.go index 3c5439d8..1bd56c78 100644 --- a/pkg/crypto/puzzle/puzzle.go +++ b/pkg/crypto/puzzle/puzzle.go @@ -39,7 +39,7 @@ func (p *sPoWPuzzle) ProofBytes(pPackHash []byte, pParallel uint64) uint64 { target = big.NewInt(1) ) - maxParallel := uint64(runtime.GOMAXPROCS(0)) + maxParallel := uint64(runtime.GOMAXPROCS(0)) //nolint:gosec setParallel := pParallel if pParallel == 0 { setParallel = 1 diff --git a/pkg/crypto/puzzle/puzzle_bench_test.go b/pkg/crypto/puzzle/puzzle_bench_test.go index 44350619..d7b3a4ef 100644 --- a/pkg/crypto/puzzle/puzzle_bench_test.go +++ b/pkg/crypto/puzzle/puzzle_bench_test.go @@ -134,7 +134,7 @@ func BenchmarkPuzzleParallel(b *testing.B) { b.Run(t.name, func(b *testing.B) { b.StopTimer() - parallel := uint64(runtime.GOMAXPROCS(0)) + parallel := uint64(runtime.GOMAXPROCS(0)) //nolint:gosec randomBytes := make([][]byte, 0, b.N) for i := 0; i < b.N; i++ { randomBytes = append(randomBytes, testutils.PseudoRandomBytes(i)) diff --git a/pkg/crypto/puzzle/puzzle_test.go b/pkg/crypto/puzzle/puzzle_test.go index b4b7fe76..a388a432 100644 --- a/pkg/crypto/puzzle/puzzle_test.go +++ b/pkg/crypto/puzzle/puzzle_test.go @@ -56,7 +56,7 @@ func TestPuzzle(t *testing.T) { func TestMultiPuzzle(t *testing.T) { t.Parallel() - parallel := uint64(runtime.GOMAXPROCS(0) + 1) + parallel := uint64(runtime.GOMAXPROCS(0) + 1) //nolint:gosec puzzle := NewPoWPuzzle(4) for i := uint64(0); i < 1_000; i++ { arr := encoding.Uint64ToBytes(i) diff --git a/pkg/crypto/random/random.go b/pkg/crypto/random/random.go index 87965a8e..4a2d7254 100644 --- a/pkg/crypto/random/random.go +++ b/pkg/crypto/random/random.go @@ -49,7 +49,7 @@ func (p *sRandom) GetBytes(n uint64) []byte { */ func (p *sRandom) GetString(n uint64) string { result := strings.Builder{} - result.Grow(int(n)) + result.Grow(int(n)) //nolint:gosec randBytes := p.GetBytes(n) for _, b := range randBytes { diff --git a/pkg/crypto/symmetric/symmetric.go b/pkg/crypto/symmetric/symmetric.go index a917e23a..387e2fc0 100644 --- a/pkg/crypto/symmetric/symmetric.go +++ b/pkg/crypto/symmetric/symmetric.go @@ -32,7 +32,7 @@ func NewCipher(pKey []byte) ICipher { func (p *sAESCipher) EncryptBytes(pMsg []byte) []byte { blockSize := p.fBlock.BlockSize() - iv := random.NewRandom().GetBytes(uint64(blockSize)) + iv := random.NewRandom().GetBytes(uint64(blockSize)) //nolint:gosec stream := cipher.NewCFBEncrypter(p.fBlock, iv) result := make([]byte, len(pMsg)+len(iv)) diff --git a/pkg/logger/logger_test.go b/pkg/logger/logger_test.go index b7a010ac..e09d0c6a 100644 --- a/pkg/logger/logger_test.go +++ b/pkg/logger/logger_test.go @@ -61,24 +61,24 @@ func TestLogger(t *testing.T) { t.Parallel() defer func() { - os.Remove(tcPathInfo) - os.Remove(tcPathWarning) - os.Remove(tcPathError) + _ = os.Remove(tcPathInfo) + _ = os.Remove(tcPathWarning) + _ = os.Remove(tcPathError) }() - fileInfo, err := os.OpenFile(tcPathInfo, os.O_CREATE|os.O_WRONLY, 0644) + fileInfo, err := os.OpenFile(tcPathInfo, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { t.Error(err.Error()) return } - fileWarn, err := os.OpenFile(tcPathWarning, os.O_CREATE|os.O_WRONLY, 0644) + fileWarn, err := os.OpenFile(tcPathWarning, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { t.Error(err.Error()) return } - fileErro, err := os.OpenFile(tcPathError, os.O_CREATE|os.O_WRONLY, 0644) + fileErro, err := os.OpenFile(tcPathError, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { t.Error(err.Error()) return diff --git a/pkg/message/layer1/message_bench_test.go b/pkg/message/layer1/message_bench_test.go index 410c9f1f..51422892 100644 --- a/pkg/message/layer1/message_bench_test.go +++ b/pkg/message/layer1/message_bench_test.go @@ -155,7 +155,7 @@ PASS // go test -bench=BenchmarkMessageParallel -benchtime=100x -timeout 99999s func BenchmarkMessageParallel(b *testing.B) { - gomaxprocs := uint64(runtime.GOMAXPROCS(0)) + gomaxprocs := uint64(runtime.GOMAXPROCS(0)) //nolint:gosec benchTable := []struct { name string diff --git a/pkg/network/conn/conn.go b/pkg/network/conn/conn.go index e00f8c22..670ee87b 100644 --- a/pkg/network/conn/conn.go +++ b/pkg/network/conn/conn.go @@ -100,7 +100,7 @@ func (p *sConn) sendBytes(pCtx context.Context, pBytes []byte) error { return errors.Join(ErrWriteToSocket, err) } - bytesPtr -= uint64(n) + bytesPtr -= uint64(n) //nolint:gosec pBytes = pBytes[:bytesPtr] } } @@ -181,7 +181,7 @@ func (p *sConn) recvDataBytes(pCtx context.Context, pMustLen uint32, pInitTimeou []byte{}, ) - mustLen -= uint32(n) + mustLen -= uint32(n) //nolint:gosec if err := p.fSocket.SetReadDeadline(time.Now().Add(p.fSettings.GetReadTimeout())); err != nil { return nil, errors.Join(ErrSetReadDeadline, err) diff --git a/pkg/network/conn/conn_test.go b/pkg/network/conn/conn_test.go index 1c72ea4c..a2719412 100644 --- a/pkg/network/conn/conn_test.go +++ b/pkg/network/conn/conn_test.go @@ -41,14 +41,14 @@ func (p *tsConn) Read(b []byte) (n int, err error) { return n, nil } if p.cancelBody { - return 0, errors.New("some error1") // nolint: goerr113 + return 0, errors.New("some error1") //nolint:err113 } bodyBytes := random.NewRandom().GetBytes(p.bodySize) n = copy(b, bodyBytes) return n, nil } func (p *tsConn) Write(_ []byte) (n int, err error) { - return 0, errors.New("some error2") // nolint: goerr113 + return 0, errors.New("some error2") //nolint:err113 } func (p *tsConn) Close() error { return nil } func (p *tsConn) LocalAddr() net.Addr { return &net.TCPAddr{} } @@ -56,7 +56,7 @@ func (p *tsConn) RemoteAddr() net.Addr { return &net.TCPAddr{} } func (p *tsConn) SetDeadline(_ time.Time) error { return nil } func (p *tsConn) SetReadDeadline(_ time.Time) error { if p.bodyPart && p.readDlError { - return errors.New("some error3") // nolint: goerr113 + return errors.New("some error3") //nolint:err113 } return nil } @@ -502,7 +502,7 @@ func testNewService(t *testing.T, pAddr, pNetworkKey string) net.Listener { } ok := func() bool { - defer conn.Close() + defer func() { _ = conn.Close() }() return conn.WriteMessage(ctx, msg) == nil }() @@ -519,5 +519,5 @@ func testFreeService(listener net.Listener) { if listener == nil { return } - listener.Close() + _ = listener.Close() } diff --git a/pkg/network/connkeeper/connkeeper_test.go b/pkg/network/connkeeper/connkeeper_test.go index 96aa5709..26ca4513 100644 --- a/pkg/network/connkeeper/connkeeper_test.go +++ b/pkg/network/connkeeper/connkeeper_test.go @@ -1,4 +1,4 @@ -// nolint: goerr113 +// nolint: err113 package connkeeper import ( @@ -98,7 +98,7 @@ func TestConnKeeper(t *testing.T) { go func() { err1 := testutils.TryN(50, 20*time.Millisecond, func() error { if err := connKeeper.Run(ctx2); err == nil { - return errors.New("error is nil with already running connKeeper") + return errors.New("error is nil with already running connKeeper") //nolint:err113 } return nil }) @@ -110,7 +110,7 @@ func TestConnKeeper(t *testing.T) { err1 := testutils.TryN(50, 20*time.Millisecond, func() error { if len(connKeeper.GetNetworkNode().GetConnections()) != 1 { - return errors.New("length of connections != 1") + return errors.New("length of connections != 1") //nolint:err113 } return nil }) @@ -170,5 +170,5 @@ func testFreeService(listener net.Listener) { if listener == nil { return } - listener.Close() + _ = listener.Close() } diff --git a/pkg/network/examples/broadcast/main.go b/pkg/network/examples/broadcast/main.go index 47babf66..a1487e40 100644 --- a/pkg/network/examples/broadcast/main.go +++ b/pkg/network/examples/broadcast/main.go @@ -21,7 +21,7 @@ const ( var handler = func(serviceName string) network.IHandlerF { return func(ctx context.Context, node network.INode, _ conn.IConn, msg layer1.IMessage) error { - defer node.BroadcastMessage(ctx, msg) // send this message to other connections + defer func() { _ = node.BroadcastMessage(ctx, msg) }() // send this message to other connections fmt.Printf("'%s' got '%s'\n", serviceName, string(msg.GetPayload().GetBody())) return nil } @@ -38,7 +38,7 @@ func main() { node4 = runClientNode("node4") ) - node4.BroadcastMessage( + _ = node4.BroadcastMessage( context.Background(), layer1.NewMessage( layer1.NewConstructSettings(&layer1.SConstructSettings{ @@ -58,7 +58,7 @@ func runClientNode(id string) network.INode { ctx := context.Background() node := newNode("").HandleFunc(serviceHeader, handler(id)) - node.AddConnection(ctx, serviceAddress) + _ = node.AddConnection(ctx, serviceAddress) return node } diff --git a/pkg/network/examples/ping-pong/main.go b/pkg/network/examples/ping-pong/main.go index 3655fd7f..0895bacc 100644 --- a/pkg/network/examples/ping-pong/main.go +++ b/pkg/network/examples/ping-pong/main.go @@ -32,13 +32,13 @@ var handler = func(id string) network.IHandlerF { } fmt.Printf("'%s' got '%s#%d'\n", id, val, num) - n.BroadcastMessage( + _ = n.BroadcastMessage( ctx, layer1.NewMessage( layer1.NewConstructSettings(&layer1.SConstructSettings{ FSettings: n.GetSettings().GetConnSettings().GetMessageSettings(), }), - payload.NewPayload32(serviceHeader, []byte(fmt.Sprintf("%d", num+1))), + payload.NewPayload32(serviceHeader, []byte(strconv.Itoa(num+1))), ), ) @@ -61,7 +61,7 @@ func main() { }), payload.NewPayload32(serviceHeader, []byte("0")), ) - node1.BroadcastMessage(ctx, msg) + _ = node1.BroadcastMessage(ctx, msg) select {} } @@ -70,7 +70,7 @@ func runClientNode(id string) network.INode { ctx := context.Background() node := newNode("").HandleFunc(serviceHeader, handler(id)) - node.AddConnection(ctx, serviceAddress) + _ = node.AddConnection(ctx, serviceAddress) return node } diff --git a/pkg/network/network.go b/pkg/network/network.go index dae978ce..9a8ec1d0 100644 --- a/pkg/network/network.go +++ b/pkg/network/network.go @@ -117,11 +117,11 @@ func (p *sNode) Run(pCtx context.Context) error { if err != nil { return errors.Join(ErrCreateListener, err) } - defer listener.Close() + defer func() { _ = listener.Close() }() go func() { <-pCtx.Done() - listener.Close() + _ = listener.Close() }() p.setListener(listener) @@ -136,7 +136,7 @@ func (p *sNode) Run(pCtx context.Context) error { } if p.hasMaxConnSize() { - tconn.Close() + _ = tconn.Close() continue } diff --git a/pkg/network/network_test.go b/pkg/network/network_test.go index e91c4e91..ba711cc8 100644 --- a/pkg/network/network_test.go +++ b/pkg/network/network_test.go @@ -1,4 +1,4 @@ -// nolint: goerr113 +// nolint: err113 package network import ( @@ -132,13 +132,13 @@ func TestBroadcast(t *testing.T) { val := string(pMsg.GetPayload().GetBody()) flag, ok := mapp[node][val] if !ok { - err := fmt.Errorf("incoming value '%s' undefined", val) + err := fmt.Errorf("incoming value '%s' undefined", val) //nolint:err113 t.Error(err) return err } if flag { - err := fmt.Errorf("incoming value '%s' already exists", val) + err := fmt.Errorf("incoming value '%s' already exists", val) //nolint:err113 t.Error(err) return err } @@ -234,7 +234,7 @@ func TestNodeConnection(t *testing.T) { err1 := testutils.TryN(50, 10*time.Millisecond, func() error { if err := node1.AddConnection(ctx, "unknown_connection_address"); err == nil { - return errors.New("success add incorrect connection address") + return errors.New("success add incorrect connection address") //nolint:err113 } return nil }) @@ -270,7 +270,7 @@ func TestNodeConnection(t *testing.T) { err2 := testutils.TryN(50, 10*time.Millisecond, func() error { if len(node3.GetConnections()) != 1 { - return errors.New("has more than 1 connections (node2 should be auto disconnects by max conns param)") + return errors.New("has more than 1 connections (node2 should be auto disconnects by max conns param)") //nolint:err113 } return nil }) @@ -298,7 +298,7 @@ func TestHandleMessage(t *testing.T) { } node.HandleFunc(1, func(_ context.Context, _ INode, _ conn.IConn, _ layer1.IMessage) error { - return errors.New("some error") + return errors.New("some error") //nolint:err113 }) msg2 := layer1.NewMessage(sett, payload.NewPayload32(1, []byte{2})) if ok := node.handleMessage(ctx, nil, msg2); ok { diff --git a/pkg/payload/joiner/joiner32.go b/pkg/payload/joiner/joiner32.go index 4c66f60d..c2baff21 100644 --- a/pkg/payload/joiner/joiner32.go +++ b/pkg/payload/joiner/joiner32.go @@ -14,7 +14,7 @@ func NewBytesJoiner32(pBytesSlice [][]byte) []byte { p = append( p, payload.NewPayload32( - uint32(len(b)), + uint32(len(b)), //nolint:gosec b, ).ToBytes()..., ) @@ -34,7 +34,7 @@ func LoadBytesJoiner32(pJoinerBytes []byte) ([][]byte, error) { pLen := pld.GetHead() pBytes := pld.GetBody() - if pLen > uint32(len(pBytes)) { + if pLen > uint32(len(pBytes)) { //nolint:gosec return nil, ErrInvalidLength } diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index bc6fa775..cab3f6db 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -1,4 +1,4 @@ -// nolint: goerr113 +// nolint: err113 package state import ( @@ -73,7 +73,7 @@ func Test_sState_Enable(t *testing.T) { fields: fields{ fEnabled: true, }, - args: args{f: func() error { return errors.New("some error") }}, + args: args{f: func() error { return errors.New("some error") }}, //nolint:err113 wantErr: true, }, { @@ -97,7 +97,7 @@ func Test_sState_Enable(t *testing.T) { fields: fields{ fEnabled: false, }, - args: args{f: func() error { return errors.New("some error") }}, + args: args{f: func() error { return errors.New("some error") }}, //nolint:err113 wantErr: true, }, } @@ -149,7 +149,7 @@ func Test_sState_Disable(t *testing.T) { fields: fields{ fEnabled: true, }, - args: args{f: func() error { return errors.New("some error") }}, + args: args{f: func() error { return errors.New("some error") }}, //nolint:err113 wantErr: true, }, { @@ -173,7 +173,7 @@ func Test_sState_Disable(t *testing.T) { fields: fields{ fEnabled: false, }, - args: args{f: func() error { return errors.New("some error") }}, + args: args{f: func() error { return errors.New("some error") }}, //nolint:err113 wantErr: true, }, } diff --git a/pkg/storage/cache/cache_test.go b/pkg/storage/cache/cache_test.go index 5643cc67..75f125b2 100644 --- a/pkg/storage/cache/cache_test.go +++ b/pkg/storage/cache/cache_test.go @@ -19,19 +19,19 @@ func TestLRUCache(t *testing.T) { } for i := 0; i < 3; i++ { - key := encoding.Uint64ToBytes(uint64(i)) + key := encoding.Uint64ToBytes(uint64(i)) //nolint:gosec if ok := lruCache.Set(key[:], []byte(fmt.Sprintf("_%d_", i))); !ok { t.Errorf("failed push %d", i) return } - if lruCache.GetIndex() != uint64((i+1)%3) { + if lruCache.GetIndex() != uint64((i+1)%3) { //nolint:gosec t.Error("got invalid index") return } } for i := 0; i < 3; i++ { - key := encoding.Uint64ToBytes(uint64(i)) + key := encoding.Uint64ToBytes(uint64(i)) //nolint:gosec val, ok := lruCache.Get( key[:], ) diff --git a/pkg/storage/database/database_test.go b/pkg/storage/database/database_test.go index d787ebd4..0dbd33de 100644 --- a/pkg/storage/database/database_test.go +++ b/pkg/storage/database/database_test.go @@ -26,7 +26,7 @@ func TestInvalidCreateDB(t *testing.T) { t.Parallel() path := "./not_exist/path/to/database/57199u140291724y121291d1/database.db" - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() _, err := NewKVDatabase(path) if err == nil { @@ -39,14 +39,14 @@ func TestClosedDB(t *testing.T) { t.Parallel() dbPath := fmt.Sprintf(tcPathDBTemplate, 2) - defer os.RemoveAll(dbPath) + defer func() { _ = os.RemoveAll(dbPath) }() db, err := NewKVDatabase(dbPath) if err != nil { t.Error(err) return } - defer db.Close() + defer func() { _ = db.Close() }() if err := db.Close(); err != nil { t.Error(err) @@ -68,14 +68,14 @@ func TestCreateDB(t *testing.T) { t.Parallel() dbPath := fmt.Sprintf(tcPathDBTemplate, 3) - defer os.RemoveAll(dbPath) + defer func() { _ = os.RemoveAll(dbPath) }() store, err := NewKVDatabase(dbPath) if err != nil { t.Error(err) return } - defer store.Close() + defer func() { _ = store.Close() }() if err := store.Set([]byte("KEY"), []byte("VALUE")); err != nil { t.Error(err) @@ -97,14 +97,14 @@ func TestBasicDB(t *testing.T) { t.Parallel() dbPath := fmt.Sprintf(tcPathDBTemplate, 1) - defer os.RemoveAll(dbPath) + defer func() { _ = os.RemoveAll(dbPath) }() store, err := NewKVDatabase(dbPath) if err != nil { t.Error("[testBasic]", err) return } - defer store.Close() + defer func() { _ = store.Close() }() if _, err := store.Get([]byte("KEY")); err == nil { t.Error("[testBasic] success get with bucket=nil") diff --git a/test/result/badge_codelines.svg b/test/result/badge_codelines.svg index 22f9c31b..10598dcb 100644 --- a/test/result/badge_codelines.svg +++ b/test/result/badge_codelines.svg @@ -1 +1 @@ -code lines: 12558code lines12558 \ No newline at end of file +code lines: 12322code lines12322 \ No newline at end of file diff --git a/test/result/coverage.svg b/test/result/coverage.svg index 6e5ae3c9..2bf027e5 100644 --- a/test/result/coverage.svg +++ b/test/result/coverage.svg @@ -20,7 +20,7 @@ - + - + - + - + client @@ -65,12 +65,12 @@ - + crypto @@ -78,12 +78,12 @@ - + encoding @@ -91,12 +91,12 @@ - + logger @@ -104,12 +104,12 @@ - + message @@ -117,12 +117,12 @@ - + network @@ -130,12 +130,12 @@ - + payload @@ -143,12 +143,12 @@ - + state @@ -156,12 +156,12 @@ - + storage @@ -169,12 +169,12 @@ - + action.go @@ -182,13 +182,13 @@ - + - + - + - + head.go @@ -220,12 +220,12 @@ - + logger/log_builder.go @@ -233,12 +233,12 @@ - + queue @@ -246,12 +246,12 @@ - + settings.go @@ -259,12 +259,12 @@ - + client.go @@ -272,12 +272,12 @@ - + asymmetric @@ -285,12 +285,12 @@ - + hashing @@ -298,18 +298,18 @@ - + - + puzzle/puzzle.go @@ -317,12 +317,12 @@ - + random/random.go @@ -330,12 +330,12 @@ - + symmetric/symmetric.go @@ -343,12 +343,12 @@ - + bytes.go @@ -356,30 +356,30 @@ - + - + - + - + serialize_yaml.go @@ -387,12 +387,12 @@ - + logger.go @@ -400,18 +400,18 @@ - + - + layer1 @@ -419,12 +419,12 @@ - + layer2 @@ -432,12 +432,12 @@ - + conn @@ -445,12 +445,12 @@ - + connkeeper @@ -458,12 +458,12 @@ - + network.go @@ -471,12 +471,12 @@ - + settings.go @@ -484,12 +484,12 @@ - + joiner @@ -497,12 +497,12 @@ - + payload32.go @@ -510,12 +510,12 @@ - + payload64.go @@ -523,18 +523,18 @@ - + - + cache/lru.go @@ -542,12 +542,12 @@ - + database @@ -555,18 +555,18 @@ - + - + queue.go @@ -574,12 +574,12 @@ - + settings.go @@ -587,12 +587,12 @@ - + dsa.go @@ -600,12 +600,12 @@ - + kem.go @@ -613,12 +613,12 @@ - + key.go @@ -626,36 +626,36 @@ - + - + - + - + - + message.go @@ -663,12 +663,12 @@ - + settings.go @@ -676,12 +676,12 @@ - + message.go @@ -689,12 +689,12 @@ - + conn.go @@ -702,12 +702,12 @@ - + settings.go @@ -715,12 +715,12 @@ - + connkeeper.go @@ -728,30 +728,30 @@ - + - + - + - + database.go diff --git a/test/utils/testutils_test.go b/test/utils/testutils_test.go index c3fa0c66..23f2db75 100644 --- a/test/utils/testutils_test.go +++ b/test/utils/testutils_test.go @@ -1,4 +1,4 @@ -// nolint: goerr113 +// nolint: err113 package testutils import ( @@ -32,7 +32,7 @@ func TestPseudoRandomBytes(t *testing.T) { func TestTryN(t *testing.T) { t.Parallel() - if err := TryN(3, 10*time.Millisecond, func() error { return errors.New("some error") }); err != nil && err.Error() != "some error" { + if err := TryN(3, 10*time.Millisecond, func() error { return errors.New("some error") }); err != nil && err.Error() != "some error" { //nolint:err113 t.Error("success tryN with error") return } @@ -45,7 +45,7 @@ func TestTryN(t *testing.T) { 10*time.Millisecond, func() error { if random.NewRandom().GetBool() { - return errors.New("some error") + return errors.New("some error") //nolint:err113 } return nil },