Merge pull request #921 from harshavardhana/pr_out_add_common_test_methods

Add common methods test
This commit is contained in:
Harshavardhana
2015-07-24 04:01:41 +00:00
3 changed files with 85 additions and 33 deletions
+4
View File
@@ -47,6 +47,10 @@ func (h objectAPIHandler) getHandler(w http.ResponseWriter, r *http.Request) {
w.Write(response)
return
case r.URL.Path != "":
if _, ok := h.object[filepath.Base(r.URL.Path)]; !ok {
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Length", strconv.Itoa(len(h.object[filepath.Base(r.URL.Path)])))
w.Header().Set("Last-Modified", time.Now().UTC().Format(http.TimeFormat))
w.Header().Set("ETag", "b1946ac92492d2347c6235b4d2611184")
-33
View File
@@ -17,8 +17,6 @@
package main
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
@@ -297,34 +295,3 @@ func (ta *testAddr) Error() string {
func (ta *testAddr) String() string {
return "testAddr"
}
func (s *CmdTestSuite) TestCommonMethods(c *C) {
/// filesystem
root, err := ioutil.TempDir(os.TempDir(), "cmd-")
c.Assert(err, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object1")
data := "hello"
dataLen := len(data)
err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(err, IsNil)
reader, size, err := getSource(objectPath)
c.Assert(err, IsNil)
c.Assert(size, Not(Equals), 0)
var results bytes.Buffer
_, err = io.CopyN(&results, reader, int64(size))
c.Assert(err, IsNil)
c.Assert([]byte(data), DeepEquals, results.Bytes())
_, content, err := url2Stat(objectPath)
c.Assert(err, IsNil)
c.Assert(content.Name, Equals, filepath.Join(root, "object1"))
c.Assert(content.Type.IsRegular(), Equals, true)
_, _, err = url2Stat(objectPath + "invalid")
c.Assert(err, Not(IsNil))
}
+81
View File
@@ -0,0 +1,81 @@
/*
* Minio Client (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 implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
. "gopkg.in/check.v1"
)
func (s *CmdTestSuite) TestCommonMethods(c *C) {
/// filesystem
root, err := ioutil.TempDir(os.TempDir(), "cmd-")
c.Assert(err, IsNil)
defer os.RemoveAll(root)
objectPath := filepath.Join(root, "object1")
c.Assert(isTargetURLDir(root), Equals, true)
c.Assert(isTargetURLDir(objectPath), Equals, false)
objectPathServer := server.URL + "/bucket/object1"
data := "hello"
dataLen := len(data)
err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(err, IsNil)
err = putTarget(objectPathServer, int64(dataLen), bytes.NewReader([]byte(data)))
c.Assert(err, IsNil)
c.Assert(isTargetURLDir(objectPathServer), Equals, false)
c.Assert(isTargetURLDir(server.URL+"/bucket"), Equals, true)
reader, size, err := getSource(objectPathServer)
c.Assert(err, IsNil)
c.Assert(size, Not(Equals), 0)
var results bytes.Buffer
_, err = io.CopyN(&results, reader, int64(size))
c.Assert(err, IsNil)
c.Assert([]byte(data), DeepEquals, results.Bytes())
_, content, err := url2Stat(objectPathServer)
c.Assert(err, IsNil)
c.Assert(content.Name, Equals, "object1")
c.Assert(content.Type.IsRegular(), Equals, true)
_, _, err = getSource(objectPathServer + "invalid")
c.Assert(err, Not(IsNil))
_, _, err = url2Stat(objectPath + "invalid")
c.Assert(err, Not(IsNil))
_, err = source2Client(objectPathServer)
c.Assert(err, IsNil)
_, err = target2Client(objectPathServer)
c.Assert(err, IsNil)
_, err = source2Client("http://test.minio.io" + "/bucket/fail")
c.Assert(err, Not(IsNil))
_, err = target2Client("http://test.minio.io" + "/bucket/fail")
c.Assert(err, Not(IsNil))
}