minio_chunk_manager_test.go 2.0 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.

package storage

import (
	"context"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestMinioChunkManager_GetPath(t *testing.T) {
	bucketName := "minio-chunk-manager"
	kv, err := newMinIOKVClient(context.TODO(), bucketName)
	assert.Nil(t, err)

	minioMgr := NewMinioChunkManager(kv)
	path, err := minioMgr.GetPath("invalid")
	assert.Empty(t, path)
	assert.Error(t, err)
}

func TestMinioChunkManager_ReadAt(t *testing.T) {
	bucketName := "minio-chunk-manager"
	kv, err := newMinIOKVClient(context.TODO(), bucketName)
	assert.Nil(t, err)

	minioMgr := NewMinioChunkManager(kv)

	key := "1"
	bin := []byte{1, 2, 3}
	content := make([]byte, 8)
G
godchen 已提交
42 43
	err = minioMgr.minio.Remove(key)
	assert.Nil(t, err)
G
groot 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

	n, err := minioMgr.ReadAt(key, content, 0)
	assert.Equal(t, n, -1)
	assert.Error(t, err)

	err = minioMgr.Write(key, bin)
	assert.Nil(t, err)

	n, err = minioMgr.ReadAt(key, content, -1)
	assert.Equal(t, n, 0)
	assert.Error(t, err)

	offset := int64(1)
	n, err = minioMgr.ReadAt(key, content, offset)
	assert.Error(t, err)
	assert.Equal(t, n, len(bin)-int(offset))
	for i := offset; i < int64(len(bin)); i++ {
		assert.Equal(t, content[i-offset], bin[i])
	}

	content = make([]byte, 2)
	n, err = minioMgr.ReadAt(key, content, offset)
	assert.Nil(t, err)
	assert.Equal(t, n, len(bin)-int(offset))
	for i := offset; i < int64(len(bin)); i++ {
		assert.Equal(t, content[i-offset], bin[i])
	}
}