2015-07-03 03:29:54 -04:00
|
|
|
/*
|
|
|
|
* 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)
|
2015-07-06 21:14:52 -04:00
|
|
|
c.Assert(f.Name(), Not(Equals), filepath.Join(s.path, "hello1"))
|
|
|
|
// close renames the file
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
// Openfile should be a success
|
|
|
|
_, err = s.disk.OpenFile("hello1")
|
|
|
|
c.Assert(err, IsNil)
|
2015-07-03 03:29:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MyDiskSuite) TestDiskOpenFile(c *C) {
|
2015-07-06 21:14:52 -04:00
|
|
|
f1, err := s.disk.CreateFile("hello2")
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
2015-07-06 21:14:52 -04:00
|
|
|
c.Assert(f1.Name(), Not(Equals), filepath.Join(s.path, "hello2"))
|
|
|
|
// close renames the file
|
|
|
|
f1.Close()
|
2015-07-03 03:29:54 -04:00
|
|
|
|
2015-07-06 21:14:52 -04:00
|
|
|
f2, err := s.disk.OpenFile("hello2")
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
2015-07-06 21:14:52 -04:00
|
|
|
c.Assert(f2.Name(), Equals, filepath.Join(s.path, "hello2"))
|
|
|
|
defer f2.Close()
|
2015-07-03 03:29:54 -04:00
|
|
|
}
|