2016-09-28 14:19:07 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016, 2017 MinIO, Inc.
|
2016-09-28 14:19:07 -04:00
|
|
|
*
|
|
|
|
* 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 cmd
|
|
|
|
|
|
|
|
import (
|
2020-04-14 20:52:38 -04:00
|
|
|
"context"
|
2017-01-16 20:05:00 -05:00
|
|
|
"reflect"
|
2016-09-28 14:19:07 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Tests initializing new object layer.
|
|
|
|
func TestNewObjectLayer(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2017-01-16 20:05:00 -05:00
|
|
|
// Tests for FS object layer.
|
|
|
|
nDisks := 1
|
|
|
|
disks, err := getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to create disks for the backend")
|
|
|
|
}
|
|
|
|
defer removeRoots(disks)
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
obj, err := newObjectLayer(ctx, mustGetZoneEndpoints(disks...))
|
2017-01-16 20:05:00 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected object layer initialization error", err)
|
|
|
|
}
|
2018-02-20 15:21:12 -05:00
|
|
|
_, ok := obj.(*FSObjects)
|
2017-01-16 20:05:00 -05:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("Unexpected object layer detected", reflect.TypeOf(obj))
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Tests for Erasure object layer initialization.
|
2017-01-16 20:05:00 -05:00
|
|
|
|
|
|
|
// Create temporary backend for the test server.
|
|
|
|
nDisks = 16
|
|
|
|
disks, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to create disks for the backend")
|
|
|
|
}
|
|
|
|
defer removeRoots(disks)
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
obj, err = newObjectLayer(ctx, mustGetZoneEndpoints(disks...))
|
2017-01-16 20:05:00 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected object layer initialization error", err)
|
|
|
|
}
|
|
|
|
|
2020-10-15 17:28:50 -04:00
|
|
|
_, ok = obj.(*erasureServerSets)
|
2017-01-16 20:05:00 -05:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("Unexpected object layer detected", reflect.TypeOf(obj))
|
|
|
|
}
|
|
|
|
}
|