Skip to content

Commit 74f207d

Browse files
author
Shruthi-1MN
committed
FileShare IT automation
1 parent 089dca6 commit 74f207d

6 files changed

Lines changed: 580 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2019 The OpenSDS Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// +build integration
16+
17+
package integration
18+
19+
import (
20+
"fmt"
21+
"testing"
22+
23+
. "github.com/onsi/ginkgo"
24+
. "github.com/onsi/gomega"
25+
)
26+
27+
//Function to run the Ginkgo Test
28+
func TestFileShareIntegration(t *testing.T) {
29+
RegisterFailHandler(Fail)
30+
//var UID string
31+
var _ = BeforeSuite(func() {
32+
fmt.Println("Before Suite Execution")
33+
34+
})
35+
AfterSuite(func() {
36+
By("After Suite Execution....!")
37+
})
38+
39+
RunSpecs(t, "File Share Integration Test Suite")
40+
}

test/integration/fileshare_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2019 The OpenSDS Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// +build integration
16+
17+
package integration
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/gomega"
24+
"github.com/opensds/opensds/test/integration/utils"
25+
)
26+
27+
func TestFileShare(t *testing.T) {
28+
RegisterFailHandler(Fail)
29+
RunSpecs(t, "FileShare Suite")
30+
}
31+
32+
var (
33+
OPERATION_FAILED = "OPERATION_FAILED"
34+
)
35+
36+
var _ = Describe("FileShare Testing", func() {
37+
Context("create FileShare ", func() {
38+
It("TC_FS_IT_01: Create fileshare with name input ", func() {
39+
var jsonStr = map[string]interface{}{"name": "share2223", "description": "This is just for test222", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
40+
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares"
41+
methodName := "POST"
42+
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr)
43+
Expect(resp.StatusCode).Should(Equal(202))
44+
Expect(err).NotTo(HaveOccurred())
45+
})
46+
It("TC_FS_IT_02: Create fileshare with empty file share name ", func() {
47+
var jsonStr2 = map[string]interface{}{"name": "", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
48+
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares"
49+
methodName := "POST"
50+
resp, _ := utils.ConnectToHTTP(methodName, url, jsonStr2)
51+
Expect(resp.StatusCode).Should(Equal(400))
52+
})
53+
It("TC_FS_IT_03: Create file share name with other encoding characters(except utf-8) ", func() {
54+
var jsonStr2 = map[string]interface{}{"name": "İnanç Esasları", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
55+
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares"
56+
methodName := "POST"
57+
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2)
58+
Expect(resp.StatusCode).Should(Equal(202))
59+
Expect(err).NotTo(HaveOccurred())
60+
})
61+
It("TC_FS_IT_04: Create file share name having special characters ", func() {
62+
var jsonStr2 = map[string]interface{}{"name": "#FileShare Code!$!test", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
63+
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares"
64+
methodName := "POST"
65+
resp, _ := utils.ConnectToHTTP(methodName, url, jsonStr2)
66+
Expect(resp.StatusCode).Should(Equal(202))
67+
})
68+
It("TC_FS_IT_05: Create file share name starts with numbers ", func() {
69+
var jsonStr2 = map[string]interface{}{"name": "123test", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
70+
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares"
71+
methodName := "POST"
72+
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2)
73+
Expect(resp.StatusCode).Should(Equal(202))
74+
Expect(err).NotTo(HaveOccurred())
75+
})
76+
It("TC_FS_IT_06: Create file share name length more than 255 characters ", func() {
77+
var jsonStr2 = map[string]interface{}{"name": "abqwqwqwggg012345678910gggggggggggggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "description": "This is just for testxxx", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
78+
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares"
79+
methodName := "POST"
80+
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2)
81+
Expect(resp.StatusCode).Should(Equal(400))
82+
Expect(err).NotTo(HaveOccurred())
83+
})
84+
It("TC_FS_IT_08: Create file share description with empty string ", func() {
85+
var jsonStr2 = map[string]interface{}{"name": "abcd123", "description": "#FileShare Code!$!test", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
86+
url := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/file/shares"
87+
methodName := "POST"
88+
resp, err := utils.ConnectToHTTP(methodName, url, jsonStr2)
89+
Expect(resp.StatusCode).Should(Equal(400))
90+
Expect(err).NotTo(HaveOccurred())
91+
})
92+
93+
})
94+
})

test/integration/sample.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//// Copyright 2019 The OpenSDS Authors.
2+
////
3+
//// Licensed under the Apache License, Version 2.0 (the "License");
4+
//// you may not use this file except in compliance with the License.
5+
//// You may obtain a copy of the License at
6+
////
7+
//// http://www.apache.org/licenses/LICENSE-2.0
8+
////
9+
//// Unless required by applicable law or agreed to in writing, software
10+
//// distributed under the License is distributed on an "AS IS" BASIS,
11+
//// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//// See the License for the specific language governing permissions and
13+
//// limitations under the License.
14+
//
15+
//// +build integration
16+
//
17+
//package integration
18+
//
19+
//import (
20+
// "fmt"
21+
// "reflect"
22+
// "testing"
23+
//
24+
// . "github.com/onsi/ginkgo"
25+
// . "github.com/onsi/gomega"
26+
// "github.com/opensds/opensds/test/integration/utils"
27+
//)
28+
//
29+
//func TestFileShare(t *testing.T) {
30+
// RegisterFailHandler(Fail)
31+
// RunSpecs(t, "FileShare Suite")
32+
//}
33+
//
34+
//var (
35+
// OPERATION_FAILED = "OPERATION_FAILED"
36+
//)
37+
//var _ = Describe("FileShare Testing", func() {
38+
//
39+
// Context("create FileShare ", func() {
40+
//
41+
// BeforeEach(func() {
42+
//
43+
// })
44+
// AfterEach(func() {
45+
// })
46+
// //It("TC_FS_IT_01: Create fileshare with name input ", func() {
47+
// // var jsonStr = map[string]interface{}{"name": "share2223", "description": "This is just for test222", "size": 2, "profileId": "df40af1a-17b5-48e5-899f-fa098b0bd5da"}
48+
// //
49+
// // 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"
50+
// // methodName := "POST"
51+
// // resp, err := utils.ConnectToHTTP(methodName, url, jsonStr)
52+
// //
53+
// // Expect(resp.StatusCode).Should(Equal(202))
54+
// // Expect(err).NotTo(HaveOccurred())
55+
// //
56+
// //})
57+
// //It("TC_FS_IT_02: Create fileshare with duplicate name input ", func() {
58+
// // var jsonStr2 = map[string]interface{}{"name": "sharexxx", "description": "This is just for testxxx", "size": 2}
59+
// // 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"
60+
// // methodName := "POST"
61+
// // utils.ConnectToHTTP(methodName, url, jsonStr2)
62+
// //})
63+
// // It("has 0 units", func() {})
64+
// // Specify("the total amount is 0.00", func() {})
65+
// })
66+
// Context("Get FileShare ", func() {
67+
// // var jsonStr1 = []byte(`{"name":"share2223", "description":"This is just for test222", "size": 2}`)
68+
// // var jsonStr = map[string]interface{}{"name": "share2223", "description": "This is just for test222", "size": 2}
69+
// BeforeEach(func() {
70+
// })
71+
// AfterEach(func() {
72+
// })
73+
// It("TC_FS_IT_03: fileshare GET all ", func() {
74+
// 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"
75+
// methodName := "GET"
76+
// resp, err := utils.ConnectToHTTP(methodName, url, nil)
77+
// fmt.Println(reflect.TypeOf(resp.Body))
78+
// Expect(resp.StatusCode).Should(Equal(200))
79+
// Expect(err).NotTo(HaveOccurred())
80+
// })
81+
// // It("TC_FS_IT_04: fileshare GET of specific Id", func() {
82+
// // fId := "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96/578288ba-f562-4053-a916-85e62c1128cf"
83+
// // //fId := "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96"
84+
// // 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"
85+
// // methodName := "GET"
86+
// // utils.ConnectToHTTP(methodName, url, nil)
87+
// // // ctx, kv := utils.ConnectToDB()
88+
// // //ret := utils.GetValueByKeyFromDB(fId)
89+
// // //Expect(ret).ShouldNot(Equal(OPERATION_FAILED))
90+
// // //textFound := utils.ReadAndFindTextInFile("C:/go/src/opensds/opensds/test/integration/utils/output.json", "17c60641-63c9-4f7f-992a-c0dcd9abd502")
91+
// // //Expect(textFound).To(BeTrue(), "Text found in the log file")
92+
// ////
93+
// // })
94+
// // // It("has 0 units", func() {})
95+
// // Specify("the total amount is 0.00", func() {})
96+
// })
97+
//})

test/integration/utils/DBHelper.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright 2019 The OpenSDS Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package utils
15+
16+
import (
17+
"context"
18+
"fmt"
19+
"log"
20+
"time"
21+
22+
"github.com/coreos/etcd/clientv3"
23+
)
24+
25+
var (
26+
dialTimeout = 10 * time.Second
27+
requestTimeout = 200 * time.Second
28+
)
29+
30+
func GetValueByKeyFromDB(key string) string {
31+
ctx, _ := context.WithTimeout(context.Background(), requestTimeout)
32+
cli, err := clientv3.New(clientv3.Config{
33+
DialTimeout: dialTimeout,
34+
Endpoints: []string{"192.168.20.123:62379"},
35+
})
36+
if err != nil {
37+
log.Fatal(err)
38+
// can define the below one in constants file and import
39+
return "OPERATION_FAILED"
40+
}
41+
defer cli.Close()
42+
kv := clientv3.NewKV(cli)
43+
//GetallKeys(ctx, kv, key)
44+
GetValueByKey(ctx, kv, key)
45+
// GetSingleValueDemo(ctx, kv)
46+
// GetMultipleValuesWithPaginationDemo(ctx, kv)
47+
// WatchDemo(ctx, cli, kv)
48+
// LeaseDemo(ctx, cli, kv)
49+
return "Done"
50+
}
51+
52+
func GetallKeys(ctx context.Context, kv clientv3.KV, key string) string {
53+
opts := []clientv3.OpOption{
54+
clientv3.WithPrefix(),
55+
clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend),
56+
clientv3.WithLimit(3),
57+
}
58+
59+
gr, _ := kv.Get(ctx, "key", opts...)
60+
61+
fmt.Println("--- First page ---")
62+
for _, item := range gr.Kvs {
63+
fmt.Println(string(item.Key), string(item.Value))
64+
}
65+
return "Done2"
66+
}
67+
68+
func GetKeys(ctx context.Context, kv clientv3.KV, key string) string {
69+
fmt.Println("*** GetKeys()")
70+
// Delete all keys
71+
// kv.Delete(ctx, "key", clientv3.WithPrefix())
72+
gr, err := kv.Get(ctx, "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96")
73+
if err != nil {
74+
log.Fatal(err)
75+
// can define the below one in constants file and import
76+
return "OPERATION_FAILED"
77+
}
78+
79+
fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision)
80+
return string(gr.Kvs[0].Value)
81+
}
82+
83+
func GetValueByKey(ctx context.Context, kv clientv3.KV, key string) string {
84+
fmt.Println("*** GetValueByKey()")
85+
// Delete all keys
86+
// kv.Delete(ctx, "key", clientv3.WithPrefix())
87+
88+
// // Insert a key value
89+
// pr, err := kv.Put(ctx, "key", "444")
90+
// if err != nil {
91+
// log.Fatal(err)
92+
// }
93+
94+
// rev := pr.Header.Revision
95+
96+
// fmt.Println("Revision:", rev)
97+
98+
// gr, err := kv.Get(ctx, "v1beta/file/shares/e93b4c0934da416eb9c8d120c5d04d96/f2ab9308-f208-40c6-bb1f-6fbfa8bf14b5")
99+
//gr, err := kv.Get(ctx, "v1beta/file/shares")
100+
// 09b1c6e4-9dac-46cc-bb09-54795a354a79
101+
//gr, err := kv.Get(ctx, "09b1c6e4-9dac-46cc-bb09-54795a354a79")
102+
103+
gr, err := kv.Get(ctx, key)
104+
if err != nil {
105+
log.Fatal(err)
106+
// can define the below one in constants file and import
107+
return "OPERATION_FAILED"
108+
}
109+
110+
fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision)
111+
return string(gr.Kvs[0].Value)
112+
// // Modify the value of an existing key (create new revision)
113+
// kv.Put(ctx, "key", "555")
114+
115+
// gr, _ = kv.Get(ctx, "key")
116+
// fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision)
117+
118+
// // Get the value of the previous revision
119+
// gr, _ = kv.Get(ctx, "key", clientv3.WithRev(rev))
120+
// fmt.Println("Value: ", string(gr.Kvs[0].Value), "Revision: ", gr.Header.Revision)
121+
}

0 commit comments

Comments
 (0)