2023-06-23 14:20:01 +05:30
|
|
|
//go:build !plan9 && !solaris && !js
|
2018-09-10 18:55:06 -07:00
|
|
|
|
|
|
|
package azureblob
|
|
|
|
|
|
|
|
import (
|
2024-12-21 11:13:45 +00:00
|
|
|
"encoding/base64"
|
2018-09-10 18:55:06 -07:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-12-21 11:13:45 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-09-10 18:55:06 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func (f *Fs) InternalTest(t *testing.T) {
|
|
|
|
// Check first feature flags are set on this
|
|
|
|
// remote
|
2018-09-18 05:25:20 -07:00
|
|
|
enabled := f.Features().SetTier
|
2018-09-10 18:55:06 -07:00
|
|
|
assert.True(t, enabled)
|
|
|
|
enabled = f.Features().GetTier
|
|
|
|
assert.True(t, enabled)
|
|
|
|
}
|
2024-12-21 11:13:45 +00:00
|
|
|
|
|
|
|
func TestBlockIDCreator(t *testing.T) {
|
|
|
|
// Check creation and random number
|
|
|
|
bic, err := newBlockIDCreator()
|
|
|
|
require.NoError(t, err)
|
|
|
|
bic2, err := newBlockIDCreator()
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotEqual(t, bic.random, bic2.random)
|
|
|
|
assert.NotEqual(t, bic.random, [8]byte{})
|
|
|
|
|
|
|
|
// Set random to known value for tests
|
|
|
|
bic.random = [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
|
|
|
|
chunkNumber := uint64(0xFEDCBA9876543210)
|
|
|
|
|
|
|
|
// Check creation of ID
|
|
|
|
want := base64.StdEncoding.EncodeToString([]byte{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 1, 2, 3, 4, 5, 6, 7, 8})
|
|
|
|
assert.Equal(t, "/ty6mHZUMhABAgMEBQYHCA==", want)
|
|
|
|
got := bic.newBlockID(chunkNumber)
|
|
|
|
assert.Equal(t, want, got)
|
|
|
|
assert.Equal(t, "/ty6mHZUMhABAgMEBQYHCA==", got)
|
|
|
|
|
|
|
|
// Test checkID is working
|
|
|
|
assert.NoError(t, bic.checkID(chunkNumber, got))
|
|
|
|
assert.ErrorContains(t, bic.checkID(chunkNumber, "$"+got), "illegal base64")
|
|
|
|
assert.ErrorContains(t, bic.checkID(chunkNumber, "AAAA"+got), "bad block ID length")
|
|
|
|
assert.ErrorContains(t, bic.checkID(chunkNumber+1, got), "expecting decoded")
|
|
|
|
assert.ErrorContains(t, bic2.checkID(chunkNumber, got), "random bytes")
|
|
|
|
}
|