Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove madmin pkg usage and improve mc tests #34

Merged
merged 1 commit into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions buildscripts/go-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
46 changes: 40 additions & 6 deletions run/core/init/initCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
letterBytes = "abcdefghijklmnopqrstuvwxyz01234569"
)

// randString generates random names and prepends them with a known prefix.
func randString(n int, src rand.Source, prefix string) string {
b := make([]byte, n)
// A rand.Int63() generates 63 random bits, enough for letterIdxMax letters!
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 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")
Expand All @@ -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)
}

Expand Down
19 changes: 13 additions & 6 deletions run/core/mc/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@
# 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
./mc ls target

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
Expand All @@ -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}'`
Expand All @@ -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