From ca2a99334cdb5a8e24f11a48d3e62eee7c520f0a Mon Sep 17 00:00:00 2001 From: Nitish Tiwar Date: Fri, 23 Jun 2017 17:35:39 -0700 Subject: [PATCH] Remove madmin pkg usage and improve mc tests --- buildscripts/go-deps.sh | 3 +-- run/core/init/initCheck.go | 46 +++++++++++++++++++++++++++++++++----- run/core/mc/test.sh | 19 +++++++++++----- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/buildscripts/go-deps.sh b/buildscripts/go-deps.sh index ccc3218e..d0ba9ebe 100755 --- a/buildscripts/go-deps.sh +++ b/buildscripts/go-deps.sh @@ -33,13 +33,12 @@ installMinioGoDeps() { # Build init tests buildInitTests() { - go get -u github.com/minio/minio/pkg/madmin && \ + go get -u github.com/minio/minio-go && \ go build -o ${init_test_path}/initCheck ${init_test_path}/initCheck.go } # Build Minio Go tests buildMinioGoTests() { - go get -u github.com/minio/minio-go && \ go test -o ${minio_go_sdk_path}/minio.test -c ${minio_go_sdk_path}/api_functional_v4_test.go } diff --git a/run/core/init/initCheck.go b/run/core/init/initCheck.go index 832d992d..f9f56539 100644 --- a/run/core/init/initCheck.go +++ b/run/core/init/initCheck.go @@ -18,11 +18,38 @@ package main import ( "log" + "math/rand" "os" + "time" - "github.com/minio/minio/pkg/madmin" + minio "github.com/minio/minio-go" ) +const ( + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1<= 0; { + if remain == 0 { + cache, remain = src.Int63(), letterIdxMax + } + if idx := int(cache & letterIdxMask); idx < len(letterBytes) { + b[i] = letterBytes[idx] + i-- + } + cache >>= letterIdxBits + remain-- + } + return prefix + string(b[0:30-len(prefix)]) +} + func main() { endpoint := os.Getenv("SERVER_ENDPOINT") accessKeyID := os.Getenv("ACCESS_KEY") @@ -33,16 +60,23 @@ func main() { useSSL = true } - madmClnt, err := madmin.New(endpoint, accessKeyID, secretAccessKey, useSSL) + // Instantiate new minio client object. + minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL) + if err != nil { + log.Fatalln(err) + } + + // Make a new bucket to see if the server is reachable. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test") + location := "us-east-1" + + err = minioClient.MakeBucket(bucketName, location) if err != nil { - // Print() followed by a call to os.Exit(1). log.Fatalln(err) } - // check the status of the Minio server. - _, err = madmClnt.ServiceStatus() + err = minioClient.RemoveBucket(bucketName) if err != nil { - // Print() followed by a call to os.Exit(1). log.Fatalln(err) } diff --git a/run/core/mc/test.sh b/run/core/mc/test.sh index 483ce7ae..6f91165c 100755 --- a/run/core/mc/test.sh +++ b/run/core/mc/test.sh @@ -15,10 +15,15 @@ # limitations under the License. # +create_random_string() { + bucketName=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1) +} + createBuckets_01(){ + create_random_string echo "Running createBuckets_01" # Make bucket - ./mc mb target/testbucket1 + ./mc mb target/$bucketName echo "Testing if the bucket was created" # list buckets @@ -26,10 +31,11 @@ createBuckets_01(){ echo "Removing the bucket" # remove bucket - ./mc rm target/testbucket1 + ./mc rm target/$bucketName } createFile_02(){ + create_random_string echo "Running createFile_02" # Create a temp 2m file @@ -41,14 +47,14 @@ createFile_02(){ # create a bucket echo "Creating a bucket" - ./mc mb target/testbucket1 + ./mc mb target/$bucketName # copy the file echo "Uploading the 2mb temp file" - ./mc cp /tmp/file target/testbucket1 + ./mc cp /tmp/file target/$bucketName echo "Download the file" - ./mc cp target/testbucket1/file /tmp/file_downloaded + ./mc cp target/${bucketName}/file /tmp/file_downloaded #save md5 hash of downloaded file hash2=`md5sum /tmp/file_downloaded | awk '{print $1}'` @@ -60,8 +66,9 @@ createFile_02(){ echo "Removing the bucket" # remove bucket - ./mc rm --force --recursive target/testbucket1 + ./mc rm --force --recursive target/$bucketName } +# Run tests createBuckets_01 createFile_02 \ No newline at end of file