github.com/mika/distribution@v2.2.2-0.20160108133430-a75790e3d8e0+incompatible/registry/storage/driver/azure/blockid_test.go (about)

     1  package azure
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  
     7  	azure "github.com/Azure/azure-sdk-for-go/storage"
     8  )
     9  
    10  func Test_blockIdGenerator(t *testing.T) {
    11  	r := newBlockIDGenerator()
    12  
    13  	for i := 1; i <= 10; i++ {
    14  		if expected := i - 1; len(r.pool) != expected {
    15  			t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
    16  		}
    17  		if id := r.Generate(); id == "" {
    18  			t.Fatal("returned empty id")
    19  		}
    20  		if expected := i; len(r.pool) != expected {
    21  			t.Fatalf("rand pool has wrong number of items: %d, expected:%d", len(r.pool), expected)
    22  		}
    23  	}
    24  }
    25  
    26  func Test_blockIdGenerator_Feed(t *testing.T) {
    27  	r := newBlockIDGenerator()
    28  	if expected := 0; len(r.pool) != expected {
    29  		t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
    30  	}
    31  
    32  	// feed empty list
    33  	blocks := azure.BlockListResponse{}
    34  	r.Feed(blocks)
    35  	if expected := 0; len(r.pool) != expected {
    36  		t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
    37  	}
    38  
    39  	// feed blocks
    40  	blocks = azure.BlockListResponse{
    41  		CommittedBlocks: []azure.BlockResponse{
    42  			{"1", 1},
    43  			{"2", 2},
    44  		},
    45  		UncommittedBlocks: []azure.BlockResponse{
    46  			{"3", 3},
    47  		}}
    48  	r.Feed(blocks)
    49  	if expected := 3; len(r.pool) != expected {
    50  		t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
    51  	}
    52  
    53  	// feed same block IDs with committed/uncommitted place changed
    54  	blocks = azure.BlockListResponse{
    55  		CommittedBlocks: []azure.BlockResponse{
    56  			{"3", 3},
    57  		},
    58  		UncommittedBlocks: []azure.BlockResponse{
    59  			{"1", 1},
    60  		}}
    61  	r.Feed(blocks)
    62  	if expected := 3; len(r.pool) != expected {
    63  		t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
    64  	}
    65  }
    66  
    67  func Test_toBlockId(t *testing.T) {
    68  	min := 0
    69  	max := math.MaxInt64
    70  
    71  	if len(toBlockID(min)) != len(toBlockID(max)) {
    72  		t.Fatalf("different-sized blockIDs are returned")
    73  	}
    74  }