Merge pull request #547 from harshavardhana/pr_out_re_implement_s3tests_with_minio_io_check_fixes_432
Re-implement s3tests with minio-io/check - fixes #432
This commit is contained in:
+15
-29
@@ -22,7 +22,8 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "github.com/minio-io/check"
|
||||
)
|
||||
|
||||
type reqAndExpected struct {
|
||||
@@ -37,7 +38,7 @@ func req(s string) *http.Request {
|
||||
return req
|
||||
}
|
||||
|
||||
func TestStringToSign(t *testing.T) {
|
||||
func (s *MySuite) TestStringToSign(c *C) {
|
||||
var a s3Client
|
||||
tests := []reqAndExpected{
|
||||
{`GET /photos/puppy.jpg HTTP/1.1
|
||||
@@ -87,16 +88,13 @@ Content-Length: 5913339
|
||||
`,
|
||||
"PUT\n4gJE4saaMU4BqNR0kLY+lw==\napplication/x-download\nTue, 27 Mar 2007 21:06:08 +0000\nx-amz-acl:public-read\nx-amz-meta-checksumalgorithm:crc32\nx-amz-meta-filechecksum:0x02661779\nx-amz-meta-reviewedby:joe@johnsmith.net,jane@johnsmith.net\n/db-backup.dat.gz", "static.johnsmith.net:8080"},
|
||||
}
|
||||
for idx, test := range tests {
|
||||
for _, test := range tests {
|
||||
got := a.stringToSign(req(test.req), test.host)
|
||||
if got != test.expected {
|
||||
t.Errorf("test %d: expected %q", idx, test.expected)
|
||||
t.Errorf("test %d: got %q", idx, got)
|
||||
}
|
||||
c.Assert(got, Equals, test.expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBucketFromHostname(t *testing.T) {
|
||||
func (s *MySuite) TestBucketFromHostname(c *C) {
|
||||
var a s3Client
|
||||
tests := []reqAndExpected{
|
||||
{"GET / HTTP/1.0\n\n", "", ""},
|
||||
@@ -105,15 +103,13 @@ func TestBucketFromHostname(t *testing.T) {
|
||||
{"GET / HTTP/1.0\nHost: foo.com:123\n\n", "foo.com", "foo.com"},
|
||||
{"GET / HTTP/1.0\nHost: bar.com\n\n", "", "bar.com"},
|
||||
}
|
||||
for idx, test := range tests {
|
||||
for _, test := range tests {
|
||||
got := a.bucketFromHost(req(test.req), test.host)
|
||||
if got != test.expected {
|
||||
t.Errorf("test %d: expected %q; got %q", idx, test.expected, got)
|
||||
}
|
||||
c.Assert(got, Equals, test.expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestsignRequest(t *testing.T) {
|
||||
func (s *MySuite) TestsignRequest(c *C) {
|
||||
r := req("GET /foo HTTP/1.1\n\n")
|
||||
config := &Config{
|
||||
HostURL: "localhost:9000",
|
||||
@@ -129,24 +125,14 @@ func TestsignRequest(t *testing.T) {
|
||||
}, url,
|
||||
}
|
||||
cl.signRequest(r, "localhost:9000")
|
||||
if r.Header.Get("Date") == "" {
|
||||
t.Error("expected a Date set")
|
||||
}
|
||||
c.Assert(r.Header.Get("Date"), Not(Equals), "")
|
||||
r.Header.Set("Date", "Sat, 02 Apr 2011 04:23:52 GMT")
|
||||
cl.signRequest(r, "localhost:9000")
|
||||
if e, g := r.Header.Get("Authorization"), "AWS key:kHpCR/N7Rw3PwRlDd8+5X40CFVc="; e != g {
|
||||
t.Errorf("got header %q; expected %q", g, e)
|
||||
}
|
||||
c.Assert(r.Header.Get("Authorization"), Equals, "AWS key:kHpCR/N7Rw3PwRlDd8+5X40CFVc=")
|
||||
}
|
||||
|
||||
func TestHasDotSuffix(t *testing.T) {
|
||||
if !hasDotSuffix("foo.com", "com") {
|
||||
t.Fail()
|
||||
}
|
||||
if hasDotSuffix("foocom", "com") {
|
||||
t.Fail()
|
||||
}
|
||||
if hasDotSuffix("com", "com") {
|
||||
t.Fail()
|
||||
}
|
||||
func (s *MySuite) TestHasDotSuffix(c *C) {
|
||||
c.Assert(hasDotSuffix("foo.com", "com"), Equals, true)
|
||||
c.Assert(hasDotSuffix("foocom", "com"), Equals, false)
|
||||
c.Assert(hasDotSuffix("com", "com"), Equals, false)
|
||||
}
|
||||
|
||||
@@ -20,15 +20,23 @@ import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"io"
|
||||
"reflect"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/minio-io/check"
|
||||
"github.com/minio-io/mc/pkg/client"
|
||||
"github.com/minio-io/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func listAllMyBuckets(r io.Reader) ([]*client.Item, error) {
|
||||
type bucket struct {
|
||||
Name string
|
||||
@@ -55,15 +63,48 @@ func listAllMyBuckets(r io.Reader) ([]*client.Item, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func TestParseBuckets(t *testing.T) {
|
||||
func (s *MySuite) TestConfig(c *C) {
|
||||
conf := new(Config)
|
||||
conf.AccessKeyID = ""
|
||||
conf.SecretAccessKey = ""
|
||||
conf.HostURL = "http://example.com/bucket1"
|
||||
conf.UserAgent = "Minio"
|
||||
clnt := New(conf)
|
||||
c.Assert(clnt, Not(IsNil))
|
||||
}
|
||||
|
||||
func (s *MySuite) TestBucketACL(c *C) {
|
||||
m := []struct {
|
||||
in string
|
||||
want bool
|
||||
}{
|
||||
{"private", true},
|
||||
{"public-read", true},
|
||||
{"public-read-write", true},
|
||||
{"", true},
|
||||
{"readonly", false},
|
||||
{"invalid", false},
|
||||
}
|
||||
for _, bt := range m {
|
||||
got := isValidBucketACL(bt.in)
|
||||
c.Assert(got, Equals, bt.want)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MySuite) TestError(c *C) {
|
||||
res := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><Resource>/mybucket/myphoto.jpg</Resource><RequestId>F19772218238A85A</RequestId><HostId>GuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD</HostId></Error>"
|
||||
response := new(http.Response)
|
||||
response.Body = ioutil.NopCloser(strings.NewReader(res))
|
||||
err := NewError(response)
|
||||
c.Assert(err, Not(IsNil))
|
||||
c.Assert(err.Error(), Equals, "Access Denied")
|
||||
}
|
||||
|
||||
func (s *MySuite) TestParseBuckets(c *C) {
|
||||
res := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>ownerIDField</ID><DisplayName>bobDisplayName</DisplayName></Owner><Buckets><Bucket><Name>bucketOne</Name><CreationDate>2006-06-21T07:04:31.000Z</CreationDate></Bucket><Bucket><Name>bucketTwo</Name><CreationDate>2006-06-21T07:04:32.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>"
|
||||
buckets, err := listAllMyBuckets(strings.NewReader(res))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if g, w := len(buckets), 2; g != w {
|
||||
t.Errorf("num parsed buckets = %d; want %d", g, w)
|
||||
}
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(len(buckets), Equals, 2)
|
||||
|
||||
t1, err := time.Parse(time.RFC3339, "2006-06-21T07:04:31.000Z")
|
||||
t2, err := time.Parse(time.RFC3339, "2006-06-21T07:04:32.000Z")
|
||||
@@ -71,20 +112,16 @@ func TestParseBuckets(t *testing.T) {
|
||||
{Name: "bucketOne", Time: t1},
|
||||
{Name: "bucketTwo", Time: t2},
|
||||
}
|
||||
dump := func(v []*client.Item) {
|
||||
for i, b := range v {
|
||||
t.Logf("Bucket #%d: %#v", i, b)
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(buckets, want) {
|
||||
t.Error("mismatch; GOT:")
|
||||
dump(buckets)
|
||||
t.Error("WANT:")
|
||||
dump(want)
|
||||
}
|
||||
c.Assert(buckets, DeepEquals, want)
|
||||
}
|
||||
|
||||
func TestValidBucketNames(t *testing.T) {
|
||||
func (s *MySuite) TestParseBucketsFail(c *C) {
|
||||
res := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>ownerIDField</ID><DisplayName>bobDisplayName</DisplayName></Owner><Buckets><Bucket><Name>bucketOne</Name><CreationDate>2006-06-21T07:04:31.000Z</CreationDate></Bucket><Bucket><Name>bucketTwo</Name><CreationDate>2006-06-21T07:04:32.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult"
|
||||
_, err := listAllMyBuckets(strings.NewReader(res))
|
||||
c.Assert(err, Not(IsNil))
|
||||
}
|
||||
|
||||
func (s *MySuite) TestValidBucketNames(c *C) {
|
||||
m := []struct {
|
||||
in string
|
||||
want bool
|
||||
@@ -104,8 +141,6 @@ func TestValidBucketNames(t *testing.T) {
|
||||
|
||||
for _, bt := range m {
|
||||
got := client.IsValidBucketName(bt.in)
|
||||
if got != bt.want {
|
||||
t.Errorf("func(%q) = %v; want %v", bt.in, got, bt.want)
|
||||
}
|
||||
c.Assert(got, Equals, bt.want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user