mirror of
https://github.com/minio/minio.git
synced 2025-11-10 22:10:12 -05:00
api/handlers: Implement streaming signature v4 support. (#2370)
* api/handlers: Implement streaming signature v4 support. Fixes #2326 * tests: Add tests for quick/safe
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package quick_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -81,6 +82,46 @@ func (s *MySuite) TestCheckData(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestLoadFile(c *C) {
|
||||
type myStruct struct {
|
||||
Version string
|
||||
User string
|
||||
Password string
|
||||
Folders []string
|
||||
}
|
||||
saveMe := myStruct{}
|
||||
_, err := quick.Load("test.json", &saveMe)
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
file, err := os.Create("test.json")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(file.Close(), IsNil)
|
||||
_, err = quick.Load("test.json", &saveMe)
|
||||
c.Assert(err, Not(IsNil))
|
||||
config, err := quick.New(&saveMe)
|
||||
c.Assert(err, IsNil)
|
||||
err = config.Load("test-non-exist.json")
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = config.Load("test.json")
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
saveMe = myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
|
||||
config, err = quick.New(&saveMe)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(config, Not(IsNil))
|
||||
err = config.Save("test.json")
|
||||
c.Assert(err, IsNil)
|
||||
saveMe1 := myStruct{}
|
||||
_, err = quick.Load("test.json", &saveMe1)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(saveMe1, DeepEquals, saveMe)
|
||||
|
||||
saveMe2 := myStruct{}
|
||||
err = json.Unmarshal([]byte(config.String()), &saveMe2)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(saveMe2, DeepEquals, saveMe1)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestVersion(c *C) {
|
||||
defer os.RemoveAll("test.json")
|
||||
type myStruct struct {
|
||||
|
||||
@@ -35,14 +35,14 @@ type File struct {
|
||||
|
||||
// Write writes len(b) bytes to the temporary File. In case of error, the temporary file is removed.
|
||||
func (file *File) Write(b []byte) (n int, err error) {
|
||||
if file.aborted {
|
||||
err = errors.New("write on aborted file")
|
||||
return
|
||||
}
|
||||
if file.closed {
|
||||
err = errors.New("write on closed file")
|
||||
return
|
||||
}
|
||||
if file.aborted {
|
||||
err = errors.New("write on aborted file")
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
@@ -64,7 +64,12 @@ func (file *File) Close() (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
if file.aborted || file.closed {
|
||||
if file.closed {
|
||||
err = errors.New("close on closed file")
|
||||
return
|
||||
}
|
||||
if file.aborted {
|
||||
err = errors.New("close on aborted file")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -80,7 +85,12 @@ func (file *File) Close() (err error) {
|
||||
|
||||
// Abort aborts the temporary File by closing and removing the temporary file.
|
||||
func (file *File) Abort() (err error) {
|
||||
if file.aborted || file.closed {
|
||||
if file.closed {
|
||||
err = errors.New("abort on closed file")
|
||||
return
|
||||
}
|
||||
if file.aborted {
|
||||
err = errors.New("abort on aborted file")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package safe
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
@@ -44,26 +44,60 @@ func (s *MySuite) TearDownSuite(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestSafe(c *C) {
|
||||
f, err := CreateFile(filepath.Join(s.root, "testfile"))
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(filepath.Join(s.root, "testfile"))
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = f.Close()
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(filepath.Join(s.root, "testfile"))
|
||||
c.Assert(err, IsNil)
|
||||
err = os.Remove(filepath.Join(s.root, "testfile"))
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestSafeAbort(c *C) {
|
||||
f, err := CreateFile(filepath.Join(s.root, "purgefile"))
|
||||
f, err := CreateFile(path.Join(s.root, "testfile-abort"))
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(filepath.Join(s.root, "purgefile"))
|
||||
_, err = os.Stat(path.Join(s.root, "testfile-abort"))
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = f.Abort()
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(filepath.Join(s.root, "purgefile"))
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = f.Close()
|
||||
c.Assert(err.Error(), Equals, "close on aborted file")
|
||||
}
|
||||
|
||||
func (s *MySuite) TestSafeClose(c *C) {
|
||||
f, err := CreateFile(path.Join(s.root, "testfile-close"))
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(path.Join(s.root, "testfile-close"))
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = f.Close()
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(path.Join(s.root, "testfile-close"))
|
||||
c.Assert(err, IsNil)
|
||||
err = os.Remove(path.Join(s.root, "testfile-close"))
|
||||
c.Assert(err, IsNil)
|
||||
err = f.Abort()
|
||||
c.Assert(err.Error(), Equals, "abort on closed file")
|
||||
}
|
||||
|
||||
func (s *MySuite) TestSafe(c *C) {
|
||||
f, err := CreateFile(path.Join(s.root, "testfile-safe"))
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(path.Join(s.root, "testfile-safe"))
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = f.Close()
|
||||
c.Assert(err, IsNil)
|
||||
_, err = f.Write([]byte("Test"))
|
||||
c.Assert(err.Error(), Equals, "write on closed file")
|
||||
err = f.Close()
|
||||
c.Assert(err.Error(), Equals, "close on closed file")
|
||||
_, err = os.Stat(path.Join(s.root, "testfile-safe"))
|
||||
c.Assert(err, IsNil)
|
||||
err = os.Remove(path.Join(s.root, "testfile-safe"))
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestSafeAbortWrite(c *C) {
|
||||
f, err := CreateFile(path.Join(s.root, "purgefile-abort"))
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(path.Join(s.root, "purgefile-abort"))
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = f.Abort()
|
||||
c.Assert(err, IsNil)
|
||||
_, err = os.Stat(path.Join(s.root, "purgefile-abort"))
|
||||
c.Assert(err, Not(IsNil))
|
||||
err = f.Abort()
|
||||
c.Assert(err.Error(), Equals, "abort on aborted file")
|
||||
_, err = f.Write([]byte("Test"))
|
||||
c.Assert(err.Error(), Equals, "write on aborted file")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user