Commit 94aabce1 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

fix errors reported by deepsource (#101)

parent c52fd30e
......@@ -21,11 +21,14 @@ func TestMain(m *testing.M) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer os.RemoveAll(dir)
homeDir = dir
os.Exit(m.Run())
code := m.Run()
if err := os.RemoveAll(dir); err != nil {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(code)
}
func newCommand(t *testing.T, opts ...cmd.Option) (c *cmd.Command) {
......
......@@ -119,11 +119,13 @@ func (s *Service) peersHandler(_ context.Context, peer p2p.Peer, stream p2p.Stre
_, r := protobuf.NewWriterAndReader(stream)
var peersReq pb.Peers
if err := r.ReadMsgWithTimeout(messageTimeout, &peersReq); err != nil {
stream.Close()
_ = stream.Close()
return fmt.Errorf("read requestPeers message: %w", err)
}
stream.Close()
if err := stream.Close(); err != nil {
return fmt.Errorf("close stream: %w", err)
}
for _, newPeer := range peersReq.Peers {
addr, err := ma.NewMultiaddr(newPeer.Underlay)
if err != nil {
......
......@@ -308,7 +308,7 @@ func New(path string, baseKey []byte, o *Options, logger logging.Logger) (db *DB
EncodeKey: func(fields shed.Item) (key []byte, err error) {
key = make([]byte, 40)
binary.BigEndian.PutUint64(key[:8], uint64(fields.StoreTimestamp))
copy(key[8:], fields.Address[:])
copy(key[8:], fields.Address)
return key, nil
},
DecodeKey: func(key []byte) (e shed.Item, err error) {
......
......@@ -308,12 +308,14 @@ func Example_store() {
ch := testing.GenerateTestRandomChunk()
err = s.Put(context.Background(), ch)
if err != nil {
log.Fatal(err)
fmt.Println(err)
return
}
got, err := s.Get(context.Background(), ch.Address())
if err != nil {
log.Fatal(err)
fmt.Println(err)
return
}
fmt.Println(bytes.Equal(got.Data(), ch.Data()))
......
......@@ -61,7 +61,9 @@ func RunPersist(t *testing.T, f func(t *testing.T, dir string) storage.StateStor
testStoreIterator(t, store, "some_prefix", 1000)
// close the store
store.Close()
if err := store.Close(); err != nil {
t.Fatal(err)
}
// bootstrap with the same old dir
persistedStore := f(t, dir)
......
......@@ -37,9 +37,9 @@ func init() {
// using this function.
func GenerateTestRandomChunk() swarm.Chunk {
data := make([]byte, swarm.ChunkSize)
rand.Read(data)
_, _ = rand.Read(data)
key := make([]byte, 32)
rand.Read(key)
_, _ = rand.Read(key)
return swarm.NewChunk(swarm.NewAddress(key), data)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment