2016-07-21 20:31:14 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-07-21 20:31:14 -04:00
|
|
|
|
2016-08-15 19:09:08 -04:00
|
|
|
import (
|
2016-09-16 16:06:49 -04:00
|
|
|
"bytes"
|
|
|
|
"path/filepath"
|
2016-08-15 19:09:08 -04:00
|
|
|
"testing"
|
|
|
|
)
|
2016-07-21 20:31:14 -04:00
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Tests ToObjectInfo function.
|
|
|
|
func TestFSV1MetadataObjInfo(t *testing.T) {
|
|
|
|
fsMeta := newFSMetaV1()
|
|
|
|
objInfo := fsMeta.ToObjectInfo("testbucket", "testobject", nil)
|
|
|
|
if objInfo.Size != 0 {
|
|
|
|
t.Fatal("Unexpected object info value for Size", objInfo.Size)
|
2016-10-18 15:49:24 -04:00
|
|
|
}
|
2017-01-16 20:05:00 -05:00
|
|
|
if objInfo.ModTime != timeSentinel {
|
|
|
|
t.Fatal("Unexpected object info value for ModTime ", objInfo.ModTime)
|
|
|
|
}
|
|
|
|
if objInfo.IsDir {
|
|
|
|
t.Fatal("Unexpected object info value for IsDir", objInfo.IsDir)
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// TestReadFSMetadata - readFSMetadata testing with a healthy and faulty disk
|
2016-09-16 16:06:49 -04:00
|
|
|
func TestReadFSMetadata(t *testing.T) {
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2016-09-16 16:06:49 -04:00
|
|
|
defer removeAll(disk)
|
2016-10-05 15:48:07 -04:00
|
|
|
|
|
|
|
obj := initFSObjects(disk, t)
|
2017-01-16 20:05:00 -05:00
|
|
|
fs := obj.(*fsObjects)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
objectName := "object"
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
if err := obj.MakeBucket(bucketName); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
2016-10-02 18:51:49 -04:00
|
|
|
sha256sum := ""
|
2016-10-05 15:48:07 -04:00
|
|
|
if _, err := obj.PutObject(bucketName, objectName, int64(len("abcd")), bytes.NewReader([]byte("abcd")),
|
2016-10-02 18:51:49 -04:00
|
|
|
map[string]string{"X-Amz-Meta-AppId": "a"}, sha256sum); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the full path of fs.json
|
2017-05-05 11:49:09 -04:00
|
|
|
fsPath := pathJoin(bucketMetaPrefix, bucketName, objectMetaPrefix, objectName, "fs.json")
|
2017-01-16 20:05:00 -05:00
|
|
|
fsPath = pathJoin(fs.fsPath, minioMetaBucket, fsPath)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
rlk, err := fs.rwPool.Open(fsPath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected error ", err)
|
|
|
|
}
|
|
|
|
defer rlk.Close()
|
|
|
|
|
2016-09-16 16:06:49 -04:00
|
|
|
// Regular fs metadata reading, no errors expected
|
2017-01-16 20:05:00 -05:00
|
|
|
fsMeta := fsMetaV1{}
|
2017-01-25 15:29:06 -05:00
|
|
|
if _, err = fsMeta.ReadFrom(rlk.LockedFile); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// TestWriteFSMetadata - tests of writeFSMetadata with healthy disk.
|
2016-09-16 16:06:49 -04:00
|
|
|
func TestWriteFSMetadata(t *testing.T) {
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2016-09-16 16:06:49 -04:00
|
|
|
defer removeAll(disk)
|
2017-01-16 20:05:00 -05:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
obj := initFSObjects(disk, t)
|
2017-01-16 20:05:00 -05:00
|
|
|
fs := obj.(*fsObjects)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
objectName := "object"
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
if err := obj.MakeBucket(bucketName); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
2016-10-02 18:51:49 -04:00
|
|
|
sha256sum := ""
|
2016-10-05 15:48:07 -04:00
|
|
|
if _, err := obj.PutObject(bucketName, objectName, int64(len("abcd")), bytes.NewReader([]byte("abcd")),
|
2016-10-02 18:51:49 -04:00
|
|
|
map[string]string{"X-Amz-Meta-AppId": "a"}, sha256sum); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected err: ", err)
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Construct the full path of fs.json
|
2017-05-05 11:49:09 -04:00
|
|
|
fsPath := pathJoin(bucketMetaPrefix, bucketName, objectMetaPrefix, objectName, "fs.json")
|
2017-01-16 20:05:00 -05:00
|
|
|
fsPath = pathJoin(fs.fsPath, minioMetaBucket, fsPath)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
rlk, err := fs.rwPool.Open(fsPath)
|
2016-09-16 16:06:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected error ", err)
|
|
|
|
}
|
2017-01-16 20:05:00 -05:00
|
|
|
defer rlk.Close()
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// FS metadata reading, no errors expected (healthy disk)
|
|
|
|
fsMeta := fsMetaV1{}
|
2017-01-25 15:29:06 -05:00
|
|
|
_, err = fsMeta.ReadFrom(rlk.LockedFile)
|
2017-01-16 20:05:00 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected error ", err)
|
|
|
|
}
|
2017-05-14 15:05:51 -04:00
|
|
|
if fsMeta.Version != fsMetaVersion {
|
2017-01-16 20:05:00 -05:00
|
|
|
t.Fatalf("Unexpected version %s", fsMeta.Version)
|
|
|
|
}
|
2017-05-14 15:05:51 -04:00
|
|
|
if fsMeta.Format != fsMetaFormat {
|
2017-01-16 20:05:00 -05:00
|
|
|
t.Fatalf("Unexpected format %s", fsMeta.Format)
|
2016-09-16 16:06:49 -04:00
|
|
|
}
|
|
|
|
}
|