-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shruthi-1MN
committed
Sep 5, 2019
1 parent
bc79715
commit 140905a
Showing
6 changed files
with
580 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2019 The OpenSDS Authors. | ||
// | ||
// 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. | ||
|
||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
//Function to run the Ginkgo Test | ||
func TestFileShareIntegration(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
//var UID string | ||
var _ = BeforeSuite(func() { | ||
fmt.Println("Before Suite Execution") | ||
|
||
}) | ||
AfterSuite(func() { | ||
By("After Suite Execution....!") | ||
}) | ||
|
||
RunSpecs(t, "File Share Integration Test Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2019 The OpenSDS Authors. | ||
// | ||
// 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. | ||
|
||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/opensds/opensds/test/integration/utils" | ||
) | ||
|
||
func TestFileShare(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "FileShare Suite") | ||
} | ||
|
||
var ( | ||
OPERATION_FAILED = "OPERATION_FAILED" | ||
) | ||
|
||
var _ = Describe("FileShare Testing", func() { | ||
Context("create FileShare ", func() { | ||
It("TC_FS_IT_01: Create fileshare with name input ", func() { | ||
var jsonStr = map[string]interface{}{"name": "share2223", "description": "This is just for test222", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
methodName := "POST" | ||
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr) | ||
Expect(resp.StatusCode).Should(Equal(202)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
It("TC_FS_IT_02: Create fileshare with empty file share name ", func() { | ||
var jsonStr2 = map[string]interface{}{"name": "", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
methodName := "POST" | ||
resp, _ := utils.ConnectToHTTP(methodName, url, jsonStr2) | ||
Expect(resp.StatusCode).Should(Equal(400)) | ||
}) | ||
It("TC_FS_IT_03: Create file share name with other encoding characters(except utf-8) ", func() { | ||
var jsonStr2 = map[string]interface{}{"name": "İnanç Esasları", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
methodName := "POST" | ||
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2) | ||
Expect(resp.StatusCode).Should(Equal(202)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
It("TC_FS_IT_04: Create file share name having special characters ", func() { | ||
var jsonStr2 = map[string]interface{}{"name": "#FileShare Code!$!test", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
methodName := "POST" | ||
resp, _ := utils.ConnectToHTTP(methodName, url, jsonStr2) | ||
Expect(resp.StatusCode).Should(Equal(202)) | ||
}) | ||
It("TC_FS_IT_05: Create file share name starts with numbers ", func() { | ||
var jsonStr2 = map[string]interface{}{"name": "123test", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
methodName := "POST" | ||
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2) | ||
Expect(resp.StatusCode).Should(Equal(202)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
It("TC_FS_IT_06: Create file share name length more than 255 characters ", func() { | ||
var jsonStr2 = map[string]interface{}{"name": "abqwqwqwggg012345678910gggggggggggggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
methodName := "POST" | ||
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2) | ||
Expect(resp.StatusCode).Should(Equal(400)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
It("TC_FS_IT_08: Create file share description with empty string ", func() { | ||
var jsonStr2 = map[string]interface{}{"name": "abcd123", "description": "#FileShare Code!$!test", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
methodName := "POST" | ||
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2) | ||
Expect(resp.StatusCode).Should(Equal(400)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//// Copyright 2019 The OpenSDS Authors. | ||
//// | ||
//// 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. | ||
// | ||
//// +build integration | ||
// | ||
//package integration | ||
// | ||
//import ( | ||
// "fmt" | ||
// "reflect" | ||
// "testing" | ||
// | ||
// . "github.com/onsi/ginkgo" | ||
// . "github.com/onsi/gomega" | ||
// "github.com/opensds/opensds/test/integration/utils" | ||
//) | ||
// | ||
//func TestFileShare(t *testing.T) { | ||
// RegisterFailHandler(Fail) | ||
// RunSpecs(t, "FileShare Suite") | ||
//} | ||
// | ||
//var ( | ||
// OPERATION_FAILED = "OPERATION_FAILED" | ||
//) | ||
//var _ = Describe("FileShare Testing", func() { | ||
// | ||
// Context("create FileShare ", func() { | ||
// | ||
// BeforeEach(func() { | ||
// | ||
// }) | ||
// AfterEach(func() { | ||
// }) | ||
// //It("TC_FS_IT_01: Create fileshare with name input ", func() { | ||
// // var jsonStr = map[string]interface{}{"name": "share2223", "description": "This is just for test222", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"} | ||
// // | ||
// // url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" //curl -X POST -H "Content-Type: application/json" -d '{"name":"share1", "description":"This is just for test", "size": 1}' -url "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
// // methodName := "POST" | ||
// // resp, err := utils.ConnectToHTTP(methodName, url, jsonStr) | ||
// // | ||
// // Expect(resp.StatusCode).Should(Equal(202)) | ||
// // Expect(err).NotTo(HaveOccurred()) | ||
// // | ||
// //}) | ||
// //It("TC_FS_IT_02: Create fileshare with duplicate name input ", func() { | ||
// // var jsonStr2 = map[string]interface{}{"name": "sharexxx", "description": "This is just for testxxx", "size": 2} | ||
// // url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" //curl -X POST -H "Content-Type: application/json" -d '{"name":"share1", "description":"This is just for test", "size": 1}' -url "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
// // methodName := "POST" | ||
// // utils.ConnectToHTTP(methodName, url, jsonStr2) | ||
// //}) | ||
// // It("has 0 units", func() {}) | ||
// // Specify("the total amount is 0.00", func() {}) | ||
// }) | ||
// Context("Get FileShare ", func() { | ||
// // var jsonStr1 = []byte(`{"name":"share2223", "description":"This is just for test222", "size": 2}`) | ||
// // var jsonStr = map[string]interface{}{"name": "share2223", "description": "This is just for test222", "size": 2} | ||
// BeforeEach(func() { | ||
// }) | ||
// AfterEach(func() { | ||
// }) | ||
// It("TC_FS_IT_03: fileshare GET all ", func() { | ||
// url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" //curl -X POST -H "Content-Type: application/json" -d '{"name":"share1", "description":"This is just for test", "size": 1}' -url "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
// methodName := "GET" | ||
// resp, err := utils.ConnectToHTTP(methodName, url, nil) | ||
// fmt.Println(reflect.TypeOf(resp.Body)) | ||
// Expect(resp.StatusCode).Should(Equal(200)) | ||
// Expect(err).NotTo(HaveOccurred()) | ||
// }) | ||
// // It("TC_FS_IT_04: fileshare GET of specific Id", func() { | ||
// // fId := "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96/578288ba-f562-4053-a916-85e62c1128cf" | ||
// // //fId := "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96" | ||
// // url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares/578288ba-f562-4053-a916-85e62c1128cf" //curl -X POST -H "Content-Type: application/json" -d '{"name":"share1", "description":"This is just for test", "size": 1}' -url "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares" | ||
// // methodName := "GET" | ||
// // utils.ConnectToHTTP(methodName, url, nil) | ||
// // // ctx, kv := utils.ConnectToDB() | ||
// // //ret := utils.GetValueByKeyFromDB(fId) | ||
// // //Expect(ret).ShouldNot(Equal(OPERATION_FAILED)) | ||
// // //textFound := utils.ReadAndFindTextInFile("C:/go/src/opensds/opensds/test/integration/utils/output.json", "17c60641-63c9-4f7f-992a-c0dcd9abd502") | ||
// // //Expect(textFound).To(BeTrue(), "Text found in the log file") | ||
// //// | ||
// // }) | ||
// // // It("has 0 units", func() {}) | ||
// // Specify("the total amount is 0.00", func() {}) | ||
// }) | ||
//}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright 2019 The OpenSDS Authors. | ||
// | ||
// 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 utils | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/coreos/etcd/clientv3" | ||
) | ||
|
||
var ( | ||
dialTimeout = 10 * time.Second | ||
requestTimeout = 200 * time.Second | ||
) | ||
|
||
func GetValueByKeyFromDB(key string) string { | ||
ctx, _ := context.WithTimeout(context.Background(), requestTimeout) | ||
cli, err := clientv3.New(clientv3.Config{ | ||
DialTimeout: dialTimeout, | ||
Endpoints: []string{"192.168.20.123:62379"}, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
// can define the below one in constants file and import | ||
return "OPERATION_FAILED" | ||
} | ||
defer cli.Close() | ||
kv := clientv3.NewKV(cli) | ||
//GetallKeys(ctx, kv, key) | ||
GetValueByKey(ctx, kv, key) | ||
// GetSingleValueDemo(ctx, kv) | ||
// GetMultipleValuesWithPaginationDemo(ctx, kv) | ||
// WatchDemo(ctx, cli, kv) | ||
// LeaseDemo(ctx, cli, kv) | ||
return "Done" | ||
} | ||
|
||
func GetallKeys(ctx context.Context, kv clientv3.KV, key string) string { | ||
opts := []clientv3.OpOption{ | ||
clientv3.WithPrefix(), | ||
clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend), | ||
clientv3.WithLimit(3), | ||
} | ||
|
||
gr, _ := kv.Get(ctx, "key", opts...) | ||
|
||
fmt.Println("--- First page ---") | ||
for _, item := range gr.Kvs { | ||
fmt.Println(string(item.Key), string(item.Value)) | ||
} | ||
return "Done2" | ||
} | ||
|
||
func GetKeys(ctx context.Context, kv clientv3.KV, key string) string { | ||
fmt.Println("*** GetKeys()") | ||
// Delete all keys | ||
// kv.Delete(ctx, "key", clientv3.WithPrefix()) | ||
gr, err := kv.Get(ctx, "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96") | ||
if err != nil { | ||
log.Fatal(err) | ||
// can define the below one in constants file and import | ||
return "OPERATION_FAILED" | ||
} | ||
|
||
fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision) | ||
return string(gr.Kvs[0].Value) | ||
} | ||
|
||
func GetValueByKey(ctx context.Context, kv clientv3.KV, key string) string { | ||
fmt.Println("*** GetValueByKey()") | ||
// Delete all keys | ||
// kv.Delete(ctx, "key", clientv3.WithPrefix()) | ||
|
||
// // Insert a key value | ||
// pr, err := kv.Put(ctx, "key", "444") | ||
// if err != nil { | ||
// log.Fatal(err) | ||
// } | ||
|
||
// rev := pr.Header.Revision | ||
|
||
// fmt.Println("Revision:", rev) | ||
|
||
// gr, err := kv.Get(ctx, "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96/f2ab9308-f208-40c6-bb1f-6fbfa8bf14b5") | ||
//gr, err := kv.Get(ctx, "v1beta/file/shares") | ||
// 09b1c6e4-9dac-46cc-bb09-54795a354a79 | ||
//gr, err := kv.Get(ctx, "09b1c6e4-9dac-46cc-bb09-54795a354a79") | ||
|
||
gr, err := kv.Get(ctx, key) | ||
if err != nil { | ||
log.Fatal(err) | ||
// can define the below one in constants file and import | ||
return "OPERATION_FAILED" | ||
} | ||
|
||
fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision) | ||
return string(gr.Kvs[0].Value) | ||
// // Modify the value of an existing key (create new revision) | ||
// kv.Put(ctx, "key", "555") | ||
|
||
// gr, _ = kv.Get(ctx, "key") | ||
// fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision) | ||
|
||
// // Get the value of the previous revision | ||
// gr, _ = kv.Get(ctx, "key", clientv3.WithRev(rev)) | ||
// fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision) | ||
} |
Oops, something went wrong.