diff --git a/pkg/api/accounting_test.go b/pkg/api/accounting_test.go index 6664e48108d..7a807aa811e 100644 --- a/pkg/api/accounting_test.go +++ b/pkg/api/accounting_test.go @@ -101,6 +101,7 @@ func TestAccountingInfo(t *testing.T) { if !reflect.DeepEqual(got, expected) { t.Errorf("got accounting: %v, expected: %v", got, expected) } + } func TestAccountingInfoError(t *testing.T) { diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index e7f2f92b9c4..2c93a20353b 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -190,7 +190,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket. erc20 := erc20mock.New(o.Erc20Opts...) backend := backendmock.New(o.BackendOpts...) - extraOpts := api.ExtraOptions{ + var extraOpts = api.ExtraOptions{ TopologyDriver: topologyDriver, Accounting: acc, Pseudosettle: recipient, @@ -344,7 +344,7 @@ func TestParseName(t *testing.T) { const bzzHash = "89c17d0d8018a19057314aa035e61c9d23c47581a61dd3a79a7839692c617e4d" log := log.Noop - errInvalidNameOrAddress := errors.New("invalid name or bzz address") + var errInvalidNameOrAddress = errors.New("invalid name or bzz address") testCases := []struct { desc string @@ -531,7 +531,9 @@ func TestPostageHeaderError(t *testing.T) { func TestOptions(t *testing.T) { t.Parallel() - client, _, _, _ := newTestServer(t, testServerOptions{}) + var ( + client, _, _, _ = newTestServer(t, testServerOptions{}) + ) for _, tc := range []struct { endpoint string expectedMethods string // expectedMethods contains HTTP methods like GET, POST, HEAD, PATCH, DELETE, OPTIONS. These are in alphabetical sorted order diff --git a/pkg/api/balances_test.go b/pkg/api/balances_test.go index da3ea24cb73..174196d253a 100644 --- a/pkg/api/balances_test.go +++ b/pkg/api/balances_test.go @@ -216,6 +216,7 @@ func TestConsumedBalances(t *testing.T) { if !equalBalances(got, expected) { t.Errorf("got balances: %v, expected: %v", got, expected) } + } func TestConsumedError(t *testing.T) { diff --git a/pkg/api/bytes_test.go b/pkg/api/bytes_test.go index 88ed06d2f5b..e2acc99a9d6 100644 --- a/pkg/api/bytes_test.go +++ b/pkg/api/bytes_test.go @@ -271,6 +271,7 @@ func TestBytesInvalidStamp(t *testing.T) { jsonhttptest.WithRequestBody(bytes.NewReader(content)), ) }) + } func TestBytesUploadHandlerInvalidInputs(t *testing.T) { diff --git a/pkg/api/bzz.go b/pkg/api/bzz.go index 3d85b81973a..b49bc89baea 100644 --- a/pkg/api/bzz.go +++ b/pkg/api/bzz.go @@ -16,6 +16,10 @@ import ( "strings" "time" + "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/ext" + olog "github.com/opentracing/opentracing-go/log" + "github.com/ethereum/go-ethereum/common" "github.com/ethersphere/bee/v2/pkg/feeds" "github.com/ethersphere/bee/v2/pkg/file/joiner" @@ -33,9 +37,6 @@ import ( "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/ethersphere/langos" "github.com/gorilla/mux" - "github.com/opentracing/opentracing-go" - "github.com/opentracing/opentracing-go/ext" - olog "github.com/opentracing/opentracing-go/log" ) // The size of buffer used for prefetching content with Langos when not using erasure coding @@ -393,7 +394,7 @@ FETCH: // go on normally. if !feedDereferenced { if l, err := s.manifestFeed(ctx, m); err == nil { - // we have a feed manifest here + //we have a feed manifest here ch, cur, _, err := l.At(ctx, time.Now().Unix(), 0) if err != nil { logger.Debug("bzz download: feed lookup failed", "error", err) diff --git a/pkg/api/bzz_test.go b/pkg/api/bzz_test.go index 236768a2bf6..7d1e1b27bfe 100644 --- a/pkg/api/bzz_test.go +++ b/pkg/api/bzz_test.go @@ -934,6 +934,7 @@ func TestInvalidBzzParams(t *testing.T) { jsonhttptest.WithRequestBody(tr), jsonhttptest.WithRequestHeader(api.ContentTypeHeader, api.ContentTypeTar), ) + }) t.Run("batch exists", func(t *testing.T) { @@ -961,6 +962,7 @@ func TestInvalidBzzParams(t *testing.T) { jsonhttptest.WithRequestBody(tr), jsonhttptest.WithRequestHeader(api.ContentTypeHeader, api.ContentTypeTar), ) + }) t.Run("batch not found", func(t *testing.T) { @@ -1055,6 +1057,7 @@ func TestInvalidBzzParams(t *testing.T) { address := "f30c0aa7e9e2a0ef4c9b1b750ebfeaeb7c7c24da700bb089da19a46e3677824b" jsonhttptest.Request(t, client, http.MethodGet, fmt.Sprintf("/bzz/%s/", address), http.StatusNotFound) }) + } // TestDirectUploadBzz tests that the direct upload endpoint give correct error message in dev mode diff --git a/pkg/api/chequebook.go b/pkg/api/chequebook.go index b2b30e2443e..33cd75d9767 100644 --- a/pkg/api/chequebook.go +++ b/pkg/api/chequebook.go @@ -15,6 +15,7 @@ import ( "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" "github.com/ethersphere/bee/v2/pkg/settlement/swap" "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/chequebook_test.go b/pkg/api/chequebook_test.go index d1415b994fc..b9b9cbdef32 100644 --- a/pkg/api/chequebook_test.go +++ b/pkg/api/chequebook_test.go @@ -21,6 +21,7 @@ import ( "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook/mock" swapmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) @@ -426,6 +427,7 @@ func TestChequebookLastCheques(t *testing.T) { if !LastChequesEqual(got, expected) { t.Fatalf("Got: \n %+v \n\n Expected: \n %+v \n\n", got, expected) } + } func TestChequebookLastChequesPeer(t *testing.T) { @@ -440,6 +442,7 @@ func TestChequebookLastChequesPeer(t *testing.T) { sig := make([]byte, 65) lastSentChequeFunc := func(swarm.Address) (*chequebook.SignedCheque, error) { + sig := make([]byte, 65) lastSentCheque := &chequebook.SignedCheque{ @@ -455,6 +458,7 @@ func TestChequebookLastChequesPeer(t *testing.T) { } lastReceivedChequeFunc := func(swarm.Address) (*chequebook.SignedCheque, error) { + lastReceivedCheque := &chequebook.SignedCheque{ Cheque: chequebook.Cheque{ Beneficiary: beneficiary0, @@ -494,6 +498,7 @@ func TestChequebookLastChequesPeer(t *testing.T) { if !reflect.DeepEqual(got, expected) { t.Fatalf("Got: \n %+v \n\n Expected: \n %+v \n\n", got, expected) } + } func TestChequebookCashout(t *testing.T) { @@ -775,6 +780,7 @@ func Test_chequebookLastPeerHandler_invalidInputs(t *testing.T) { } func LastChequesEqual(a, b *api.ChequebookLastChequesResponse) bool { + var state bool for akeys := range a.LastCheques { diff --git a/pkg/api/chunk.go b/pkg/api/chunk.go index 5acc9b42df3..21daa0d0f57 100644 --- a/pkg/api/chunk.go +++ b/pkg/api/chunk.go @@ -13,9 +13,10 @@ import ( "strconv" "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/ethersphere/bee/v2/pkg/postage" - "github.com/ethersphere/bee/v2/pkg/soc" "github.com/ethersphere/bee/v2/pkg/storage" "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" diff --git a/pkg/api/chunk_test.go b/pkg/api/chunk_test.go index 66f8dfae74a..c0e1fe9de9c 100644 --- a/pkg/api/chunk_test.go +++ b/pkg/api/chunk_test.go @@ -13,15 +13,16 @@ import ( "testing" "time" - "github.com/ethersphere/bee/v2/pkg/api" - "github.com/ethersphere/bee/v2/pkg/jsonhttp" - "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/v2/pkg/log" mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" "github.com/ethersphere/bee/v2/pkg/spinlock" - testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" "github.com/ethersphere/bee/v2/pkg/swarm" ) diff --git a/pkg/api/cors_test.go b/pkg/api/cors_test.go index 08c817c0389..73c3b343414 100644 --- a/pkg/api/cors_test.go +++ b/pkg/api/cors_test.go @@ -116,6 +116,7 @@ func TestCORSHeaders(t *testing.T) { } }) } + } // TestCors tests whether CORs work correctly with OPTIONS method @@ -134,8 +135,7 @@ func TestCors(t *testing.T) { { endpoint: "bzz", expectedMethods: "POST", - }, - { + }, { endpoint: "bzz/0101011", expectedMethods: "GET, HEAD", }, diff --git a/pkg/api/debugstorage_test.go b/pkg/api/debugstorage_test.go index 0a7c655fdec..bb12a5585fd 100644 --- a/pkg/api/debugstorage_test.go +++ b/pkg/api/debugstorage_test.go @@ -43,4 +43,5 @@ func TestDebugStorage(t *testing.T) { jsonhttptest.WithExpectedJSONResponse(want), ) }) + } diff --git a/pkg/api/dirs.go b/pkg/api/dirs.go index ce2b679c076..f187fbde01e 100644 --- a/pkg/api/dirs.go +++ b/pkg/api/dirs.go @@ -141,6 +141,7 @@ func storeDir( errorFilename string, rLevel redundancy.Level, ) (swarm.Address, error) { + logger := tracing.NewLoggerWithTraceID(ctx, log) loggerV1 := logger.V(1).Build() diff --git a/pkg/api/dirs_test.go b/pkg/api/dirs_test.go index 306e561c864..d49f0d281d6 100644 --- a/pkg/api/dirs_test.go +++ b/pkg/api/dirs_test.go @@ -371,6 +371,7 @@ func TestDirs(t *testing.T) { // check error document validateAltPath(t, "_non_existent_file_path_", errorDocumentPath) } + } t.Run(tc.name, func(t *testing.T) { t.Run("tar_upload", func(t *testing.T) { @@ -541,7 +542,7 @@ func tarFiles(t *testing.T, files []f) *bytes.Buffer { // create tar header and write it hdr := &tar.Header{ Name: filePath, - Mode: 0o600, + Mode: 0600, Size: int64(len(file.data)), } if err := tw.WriteHeader(hdr); err != nil { @@ -570,7 +571,7 @@ func tarEmptyDir(t *testing.T) *bytes.Buffer { hdr := &tar.Header{ Name: "empty/", - Mode: 0o600, + Mode: 0600, } if err := tw.WriteHeader(hdr); err != nil { @@ -603,9 +604,11 @@ func multipartFiles(t *testing.T, files []f) (*bytes.Buffer, string) { contentType := file.header.Get(api.ContentTypeHeader) if contentType != "" { hdr.Set(api.ContentTypeHeader, contentType) + } if len(file.data) > 0 { hdr.Set(api.ContentLengthHeader, strconv.Itoa(len(file.data))) + } part, err := mw.CreatePart(hdr) if err != nil { diff --git a/pkg/api/export_test.go b/pkg/api/export_test.go index 916992815a6..fd78ae6974f 100644 --- a/pkg/api/export_test.go +++ b/pkg/api/export_test.go @@ -29,7 +29,9 @@ var ( EmptyDir = errEmptyDir ) -var ContentTypeTar = contentTypeTar +var ( + ContentTypeTar = contentTypeTar +) var ( ErrNoResolver = errNoResolver @@ -137,7 +139,6 @@ type HexInvalidByteError = hexInvalidByteError func MapStructure(input, output interface{}, hooks map[string]func(v string) (string, error)) error { return mapStructure(input, output, hooks) } - func NewParseError(entry, value string, cause error) error { return newParseError(entry, value, cause) } diff --git a/pkg/api/feed_test.go b/pkg/api/feed_test.go index 7235ad93636..a35b9ce3423 100644 --- a/pkg/api/feed_test.go +++ b/pkg/api/feed_test.go @@ -161,6 +161,7 @@ func TestFeed_Post(t *testing.T) { ) }) }) + } // TestDirectUploadFeed tests that the direct upload endpoint give correct error message in dev mode diff --git a/pkg/api/metrics.go b/pkg/api/metrics.go index 6064595a0ed..7635468f4e3 100644 --- a/pkg/api/metrics.go +++ b/pkg/api/metrics.go @@ -68,6 +68,7 @@ func newMetrics() metrics { } func toFileSizeBucket(bytes int64) int64 { + for _, s := range fileSizeBucketsKBytes { if (s * bytesInKB) >= bytes { return s * bytesInKB diff --git a/pkg/api/pin_test.go b/pkg/api/pin_test.go index 00925135efd..a85c34a9594 100644 --- a/pkg/api/pin_test.go +++ b/pkg/api/pin_test.go @@ -136,6 +136,7 @@ func TestPinHandlers(t *testing.T) { rootHash = strings.Trim(header.Get(api.ETagHeader), "\"") checkPinHandlers(t, client, rootHash, false) }) + } func TestPinHandlersInvalidInputs(t *testing.T) { @@ -193,6 +194,7 @@ func TestPinHandlersInvalidInputs(t *testing.T) { const pinRef = "620fcd78c7ce54da2d1b7cc2274a02e190cbe8fecbc3bd244690ab6517ce8f39" func TestIntegrityHandler(t *testing.T) { + t.Parallel() t.Run("ok", func(t *testing.T) { diff --git a/pkg/api/postage_test.go b/pkg/api/postage_test.go index 56cfb606078..ebf808c1c7a 100644 --- a/pkg/api/postage_test.go +++ b/pkg/api/postage_test.go @@ -17,6 +17,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethersphere/bee/v2/pkg/api" "github.com/ethersphere/bee/v2/pkg/bigint" "github.com/ethersphere/bee/v2/pkg/jsonhttp" @@ -372,6 +373,7 @@ func TestPostageGetBuckets(t *testing.T) { jsonhttptest.Request(t, tsNotFound, http.MethodGet, "/stamps/"+batchOkStr+"/buckets", http.StatusNotFound) }) + } func TestReserveState(t *testing.T) { @@ -404,7 +406,6 @@ func TestReserveState(t *testing.T) { ) }) } - func TestChainState(t *testing.T) { t.Parallel() @@ -432,6 +433,7 @@ func TestChainState(t *testing.T) { }), ) }) + } func TestPostageTopUpStamp(t *testing.T) { @@ -701,6 +703,7 @@ func TestPostageDiluteStamp(t *testing.T) { TxHash: txHash.String(), }), ) + }) } diff --git a/pkg/api/probe.go b/pkg/api/probe.go index 5d0be5c1d69..8521d050f8d 100644 --- a/pkg/api/probe.go +++ b/pkg/api/probe.go @@ -58,6 +58,7 @@ func (p *Probe) Healthy() ProbeStatus { return ProbeStatusNOK } return p.healthy.get() + } // SetHealthy updates the value of the healthy status. diff --git a/pkg/api/pss_test.go b/pkg/api/pss_test.go index c97f6fcf40d..6624e6d8d21 100644 --- a/pkg/api/pss_test.go +++ b/pkg/api/pss_test.go @@ -88,6 +88,7 @@ func TestPssWebsocketSingleHandlerDeregister(t *testing.T) { ) err := cl.SetReadDeadline(time.Now().Add(longTimeout)) + if err != nil { t.Fatal(err) } @@ -445,12 +446,10 @@ func TestPssPostHandlerInvalidInputs(t *testing.T) { } } -type ( - pssSendFn func(context.Context, pss.Targets, swarm.Chunk) error - mpss struct { - f pssSendFn - } -) +type pssSendFn func(context.Context, pss.Targets, swarm.Chunk) error +type mpss struct { + f pssSendFn +} func newMockPss(f pssSendFn) *mpss { return &mpss{f} diff --git a/pkg/api/settlements_test.go b/pkg/api/settlements_test.go index 8096df88c9d..86f2e2e42e1 100644 --- a/pkg/api/settlements_test.go +++ b/pkg/api/settlements_test.go @@ -79,6 +79,7 @@ func TestSettlements(t *testing.T) { if !equalSettlements(got, expected) { t.Errorf("got settlements: %+v, expected: %+v", got, expected) } + } func TestSettlementsError(t *testing.T) { diff --git a/pkg/api/soc_test.go b/pkg/api/soc_test.go index 3f92e6684ff..79e72ffb603 100644 --- a/pkg/api/soc_test.go +++ b/pkg/api/soc_test.go @@ -122,6 +122,7 @@ func TestSOC(t *testing.T) { }) t.Run("ok batch", func(t *testing.T) { + s := testingsoc.GenerateMockSOC(t, testData) hexbatch := hex.EncodeToString(batchOk) client, _, _, chanStorer := newTestServer(t, testServerOptions{ diff --git a/pkg/api/staking.go b/pkg/api/staking.go index df588471ce3..5ca5b06d409 100644 --- a/pkg/api/staking.go +++ b/pkg/api/staking.go @@ -10,6 +10,7 @@ import ( "net/http" "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" "github.com/gorilla/mux" @@ -32,7 +33,6 @@ func (s *Service) stakingAccessHandler(h http.Handler) http.Handler { type getStakeResponse struct { StakedAmount *bigint.BigInt `json:"stakedAmount"` } - type stakeDepositResponse struct { TxHash string `json:"txhash"` } diff --git a/pkg/api/staking_test.go b/pkg/api/staking_test.go index d7d569a8de8..e6f4d0b2296 100644 --- a/pkg/api/staking_test.go +++ b/pkg/api/staking_test.go @@ -12,8 +12,9 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/v2/pkg/api" "github.com/ethersphere/bee/v2/pkg/bigint" + + "github.com/ethersphere/bee/v2/pkg/api" "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/v2/pkg/sctx" diff --git a/pkg/api/status_test.go b/pkg/api/status_test.go index 991806dbb86..cc2c568abf4 100644 --- a/pkg/api/status_test.go +++ b/pkg/api/status_test.go @@ -102,7 +102,6 @@ func (m *topologyPeersIterNoopMock) EachConnectedPeer(_ topology.EachPeerFunc, _ func (m *topologyPeersIterNoopMock) EachConnectedPeerRev(_ topology.EachPeerFunc, _ topology.Select) error { return nil } - func (m *topologyPeersIterNoopMock) IsReachable() bool { return true } diff --git a/pkg/api/stewardship.go b/pkg/api/stewardship.go index bf4d93f0356..99d330f78cc 100644 --- a/pkg/api/stewardship.go +++ b/pkg/api/stewardship.go @@ -8,10 +8,11 @@ import ( "errors" "net/http" - "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/ethersphere/bee/v2/pkg/postage" storage "github.com/ethersphere/bee/v2/pkg/storage" "github.com/ethersphere/bee/v2/pkg/swarm" + + "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/gorilla/mux" ) diff --git a/pkg/api/tag_test.go b/pkg/api/tag_test.go index 4536883c888..d3b8edeb4dc 100644 --- a/pkg/api/tag_test.go +++ b/pkg/api/tag_test.go @@ -11,19 +11,21 @@ import ( "strconv" "testing" - "github.com/ethersphere/bee/v2/pkg/api" - "github.com/ethersphere/bee/v2/pkg/jsonhttp" - "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" + + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func tagsWithIdResource(id uint64) string { return fmt.Sprintf("/tags/%d", id) } // nolint:paralleltest func TestTags(t *testing.T) { + var ( tagsResource = "/tags" storerMock = mockstorer.New() diff --git a/pkg/api/version.go b/pkg/api/version.go index 6838f773ca8..b9bf36154c4 100644 --- a/pkg/api/version.go +++ b/pkg/api/version.go @@ -5,7 +5,5 @@ package api // Version is set in the build process. -var ( - Version = "0.0.0" - DebugVersion = "0.0.0" -) +var Version = "0.0.0" +var DebugVersion = "0.0.0" diff --git a/pkg/api/wallet.go b/pkg/api/wallet.go index 75674e1f48b..5cdd0de087d 100644 --- a/pkg/api/wallet.go +++ b/pkg/api/wallet.go @@ -7,9 +7,10 @@ package api import ( "math/big" "net/http" - "slices" "strings" + "slices" + "github.com/ethereum/go-ethereum/common" "github.com/ethersphere/bee/v2/pkg/bigint" "github.com/ethersphere/bee/v2/pkg/jsonhttp" diff --git a/pkg/api/welcome_message_test.go b/pkg/api/welcome_message_test.go index faca74f8c9f..39d7c19a039 100644 --- a/pkg/api/welcome_message_test.go +++ b/pkg/api/welcome_message_test.go @@ -26,8 +26,7 @@ func TestGetWelcomeMessage(t *testing.T) { DebugAPI: true, P2P: mock.New(mock.WithGetWelcomeMessageFunc(func() string { return DefaultTestWelcomeMessage - })), - }) + }))}) jsonhttptest.Request(t, srv, http.MethodGet, "/welcome-message", http.StatusOK, jsonhttptest.WithExpectedJSONResponse(api.WelcomeMessageResponse{