gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renter/filesystem/siafile/consts_test.go (about)

     1  package siafile
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gitlab.com/NebulousLabs/writeaheadlog"
     7  )
     8  
     9  // TestMarshalChunkSize checks marshaledChunkSize against the expected values.
    10  // This guarantees that we can't accidentally change any constants without
    11  // noticing.
    12  func TestMarshalChunkSize(t *testing.T) {
    13  	chunkOverhead := 16 + 2 + 1
    14  	pieceSize := 4 + 4 + 32
    15  	for i := 0; i < 100; i++ {
    16  		if marshaledChunkSize(i) != int64(chunkOverhead+i*pieceSize) {
    17  			t.Fatalf("Expected chunkSize %v but was %v",
    18  				chunkOverhead+i*pieceSize, marshaledChunkSize(i))
    19  		}
    20  	}
    21  }
    22  
    23  // TestIsSiaFileUpdate tests the IsSiaFileUpdate method.
    24  func TestIsSiaFileUpdate(t *testing.T) {
    25  	if testing.Short() {
    26  		t.SkipNow()
    27  	}
    28  	t.Parallel()
    29  
    30  	sf := newTestFile()
    31  	insertUpdate := sf.createInsertUpdate(0, []byte{})
    32  	deleteUpdate := sf.createDeleteUpdate()
    33  	randomUpdate := writeaheadlog.Update{}
    34  
    35  	if !IsSiaFileUpdate(insertUpdate) {
    36  		t.Error("insertUpdate should be a SiaFileUpdate but wasn't")
    37  	}
    38  	if !IsSiaFileUpdate(deleteUpdate) {
    39  		t.Error("deleteUpdate should be a SiaFileUpdate but wasn't")
    40  	}
    41  	if IsSiaFileUpdate(randomUpdate) {
    42  		t.Error("randomUpdate shouldn't be a SiaFileUpdate but was one")
    43  	}
    44  }