forked from TrueCloudLab/distribution
5c372ded1b
This change refreshes the updated version of Azure SDK for Go that has the latest changes. I manually vendored the new SDK (github.com/Azure/azure-sdk-for-go) and I removed `management/` `core/` packages manually simply because they're not used here and they have a fork of `net/http` and `crypto/tls` for a particular reason. It was introducing a 44k SLOC change otherwise... This also undoes the `include_azure` flag (actually Steven removed the driver from imports but forgot to add the build flag apparently, so the flag wasn't really including azure. 😄 ). This also must be obsolete now. Fixes #620, #175. Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package azure
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
azure "github.com/Azure/azure-sdk-for-go/storage"
|
|
)
|
|
|
|
func Test_blockIdGenerator(t *testing.T) {
|
|
r := newBlockIDGenerator()
|
|
|
|
for i := 1; i <= 10; i++ {
|
|
if expected := i - 1; len(r.pool) != expected {
|
|
t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
|
|
}
|
|
if id := r.Generate(); id == "" {
|
|
t.Fatal("returned empty id")
|
|
}
|
|
if expected := i; len(r.pool) != expected {
|
|
t.Fatalf("rand pool has wrong number of items: %d, expected:%d", len(r.pool), expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func Test_blockIdGenerator_Feed(t *testing.T) {
|
|
r := newBlockIDGenerator()
|
|
if expected := 0; len(r.pool) != expected {
|
|
t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
|
|
}
|
|
|
|
// feed empty list
|
|
blocks := azure.BlockListResponse{}
|
|
r.Feed(blocks)
|
|
if expected := 0; len(r.pool) != expected {
|
|
t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
|
|
}
|
|
|
|
// feed blocks
|
|
blocks = azure.BlockListResponse{
|
|
CommittedBlocks: []azure.BlockResponse{
|
|
{"1", 1},
|
|
{"2", 2},
|
|
},
|
|
UncommittedBlocks: []azure.BlockResponse{
|
|
{"3", 3},
|
|
}}
|
|
r.Feed(blocks)
|
|
if expected := 3; len(r.pool) != expected {
|
|
t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
|
|
}
|
|
|
|
// feed same block IDs with committed/uncommitted place changed
|
|
blocks = azure.BlockListResponse{
|
|
CommittedBlocks: []azure.BlockResponse{
|
|
{"3", 3},
|
|
},
|
|
UncommittedBlocks: []azure.BlockResponse{
|
|
{"1", 1},
|
|
}}
|
|
r.Feed(blocks)
|
|
if expected := 3; len(r.pool) != expected {
|
|
t.Fatalf("rand pool had wrong number of items: %d, expected:%d", len(r.pool), expected)
|
|
}
|
|
}
|
|
|
|
func Test_toBlockId(t *testing.T) {
|
|
min := 0
|
|
max := math.MaxInt64
|
|
|
|
if len(toBlockID(min)) != len(toBlockID(max)) {
|
|
t.Fatalf("different-sized blockIDs are returned")
|
|
}
|
|
}
|