github.com/anacrolix/torrent@v1.61.0/storage/bolt-piece-completion_test.go (about)

     1  package storage
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/go-quicktest/qt"
     7  
     8  	"github.com/anacrolix/torrent/metainfo"
     9  )
    10  
    11  func TestBoltPieceCompletion(t *testing.T) {
    12  	td := t.TempDir()
    13  
    14  	pc, err := NewBoltPieceCompletion(td)
    15  	qt.Assert(t, qt.IsNil(err))
    16  	defer pc.Close()
    17  
    18  	pk := metainfo.PieceKey{}
    19  
    20  	b, err := pc.Get(pk)
    21  	qt.Assert(t, qt.IsNil(err))
    22  	qt.Check(t, qt.IsFalse(b.Ok))
    23  
    24  	qt.Check(t, qt.IsNil(pc.Set(pk, false)))
    25  
    26  	b, err = pc.Get(pk)
    27  	qt.Assert(t, qt.IsNil(err))
    28  	qt.Check(t, qt.Equals(b, Completion{Complete: false, Ok: true}))
    29  
    30  	qt.Check(t, qt.IsNil(pc.Set(pk, true)))
    31  
    32  	b, err = pc.Get(pk)
    33  	qt.Assert(t, qt.IsNil(err))
    34  	qt.Check(t, qt.Equals(b, Completion{Complete: true, Ok: true}))
    35  }