minio/pkg/donut/disk/disk_test.go

79 lines
1.9 KiB
Go
Raw Normal View History

/*
* Minimalist Object Storage, (C) 2015 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 impliedisk.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package disk
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
. "github.com/minio/check"
)
func TestDisk(t *testing.T) { TestingT(t) }
type MyDiskSuite struct {
path string
disk Disk
}
var _ = Suite(&MyDiskSuite{})
func (s *MyDiskSuite) SetUpSuite(c *C) {
path, err := ioutil.TempDir(os.TempDir(), "disk-")
c.Assert(err, IsNil)
s.path = path
d, err := New(s.path)
c.Assert(err, IsNil)
s.disk = d
}
func (s *MyDiskSuite) TearDownSuite(c *C) {
os.RemoveAll(s.path)
}
func (s *MyDiskSuite) TestDiskInfo(c *C) {
c.Assert(s.path, Equals, s.disk.GetPath())
fsInfo := s.disk.GetFSInfo()
c.Assert(fsInfo["MountPoint"], Equals, s.disk.GetPath())
c.Assert(fsInfo["FSType"], Not(Equals), "UNKNOWN")
}
func (s *MyDiskSuite) TestDiskCreateDir(c *C) {
c.Assert(s.disk.MakeDir("hello"), IsNil)
}
func (s *MyDiskSuite) TestDiskCreateFile(c *C) {
f, err := s.disk.CreateFile("hello1")
c.Assert(err, IsNil)
c.Assert(f.Name(), Equals, filepath.Join(s.path, "hello1"))
defer f.Close()
}
func (s *MyDiskSuite) TestDiskOpenFile(c *C) {
f, err := s.disk.CreateFile("hello2")
c.Assert(err, IsNil)
c.Assert(f.Name(), Equals, filepath.Join(s.path, "hello2"))
defer f.Close()
f, err = s.disk.OpenFile("hello2")
c.Assert(err, IsNil)
c.Assert(f.Name(), Equals, filepath.Join(s.path, "hello2"))
defer f.Close()
}