Skip to content

Commit 11de663

Browse files
author
Shruthi-1MN
committed
E2E test cases for file share
1 parent 503d72d commit 11de663

9 files changed

Lines changed: 1074 additions & 1150 deletions

File tree

.travis.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,9 @@ before_install:
2121
- sudo apt-get install -y build-essential gcc
2222
- sudo apt-get install -y librados-dev librbd-dev
2323
- sudo apt-get install -y lvm2 tgt open-iscsi
24-
<<<<<<< 0feeb98168409d1666fe427663d0ab192adb5e68
2524
- sudo docker pull p1c2u/openapi-spec-validator
26-
27-
=======
2825
- go get -v github.com/onsi/gomega
2926
- go get -v github.com/onsi/ginkgo/ginkgo
30-
- go get github.com/modocache/gover
31-
- go get -v -t ./...
32-
- export PATH=$PATH:$HOME/gopath/bin
33-
>>>>>>> end
3427

3528
matrix:
3629
fast_finish: true
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// +build integration
15+
// +build e2e
1616

17-
package integration
17+
package e2e
1818

1919
import (
2020
"fmt"
@@ -27,7 +27,7 @@ import (
2727
//Function to run the Ginkgo Test
2828
func TestFileShareIntegration(t *testing.T) {
2929
gomega.RegisterFailHandler(ginkgo.Fail)
30-
//var UID string
30+
3131
var _ = ginkgo.BeforeSuite(func() {
3232
fmt.Println("Before Suite Execution")
3333

@@ -36,5 +36,5 @@ func TestFileShareIntegration(t *testing.T) {
3636
ginkgo.By("After Suite Execution....!")
3737
})
3838

39-
ginkgo.RunSpecs(t, "File Share Integration Test Suite")
40-
}
39+
ginkgo.RunSpecs(t, "File Share E2E Test Suite")
40+
}

test/e2e/fileshare_test.go

Lines changed: 813 additions & 0 deletions
Large diffs are not rendered by default.

test/e2e/utils/HttpHelper.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
package utils
16+
17+
import (
18+
"bytes"
19+
"encoding/json"
20+
"fmt"
21+
"io"
22+
"io/ioutil"
23+
"net/http"
24+
"os"
25+
)
26+
27+
func readResponseBody(resp *http.Response) {
28+
if resp.StatusCode == http.StatusOK {
29+
bodyBytes, err := ioutil.ReadAll(resp.Body)
30+
if err != nil {
31+
fmt.Printf("reading response body failed: %v", err)
32+
}
33+
bodyString := string(bodyBytes)
34+
fmt.Printf(bodyString)
35+
}
36+
}
37+
38+
39+
func ConnectToHTTP(operation, testMgrEndPoint string, payload map[string]interface{}) (*http.Response, error) {
40+
var httpMethod string
41+
42+
switch operation {
43+
case "PUT":
44+
httpMethod = http.MethodPut
45+
46+
case "POST":
47+
httpMethod = http.MethodPost
48+
case "DELETE":
49+
httpMethod = http.MethodDelete
50+
51+
case "GET":
52+
httpMethod = http.MethodGet
53+
default:
54+
55+
}
56+
57+
respbytes, err := json.Marshal(payload)
58+
if err != nil {
59+
fmt.Printf("payload marshal failed: %v", err)
60+
}
61+
62+
req, err := http.NewRequest(httpMethod, testMgrEndPoint, bytes.NewBuffer(respbytes))
63+
if err != nil {
64+
fmt.Printf("error while getting http request: %v", err)
65+
66+
}
67+
68+
client := &http.Client{}
69+
req.Header.Set("Content-Type", "application/json")
70+
resp, err := client.Do(req)
71+
if err != nil {
72+
fmt.Printf("hTTP request is failed :%v", err)
73+
74+
}
75+
if resp != nil {
76+
fmt.Printf("resp is ... :%v", resp)
77+
io.Copy(os.Stdout, resp.Body)
78+
defer resp.Body.Close()
79+
readResponseBody(resp)
80+
}
81+
82+
return resp, err
83+
}

test/e2e/utils/fileshare_helper.go

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package utils
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/onsi/gomega"
7+
"io/ioutil"
8+
"log"
9+
"net/http"
10+
)
11+
12+
func Resp_ok(resp int, err error){
13+
gomega.Expect(resp).Should(gomega.Equal(200))
14+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
15+
fmt.Println("Resp. Ok....")
16+
}
17+
18+
func Resp_processing(resp int, err error){
19+
gomega.Expect(resp).Should(gomega.Equal(202))
20+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
21+
fmt.Println("Processing operations....")
22+
}
23+
24+
func Not_allowed_operation(resp int, err error){
25+
gomega.Expect(resp).Should(gomega.Equal(400))
26+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
27+
fmt.Println("Not allowed operation....")
28+
}
29+
30+
func Resource_Not_found(resp int, err error){
31+
gomega.Expect(resp).Should(gomega.Equal(404))
32+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
33+
fmt.Println("No resource....")
34+
}
35+
36+
func POST_method_call(jsonStr map[string]interface{}, url string) (*http.Response, error) {
37+
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/" + url
38+
resp, err := ConnectToHTTP("POST", inpurl, jsonStr)
39+
return resp, err
40+
}
41+
42+
func PUT_method_call(jsonStr map[string]interface{}, url string) (*http.Response, error) {
43+
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/" + url
44+
resp, err := ConnectToHTTP("PUT", inpurl, jsonStr)
45+
return resp, err
46+
}
47+
48+
func GET_method_call(url string) (*http.Response, error) {
49+
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/" + url
50+
resp, err := ConnectToHTTP("GET", inpurl, nil)
51+
return resp, err
52+
}
53+
54+
func DELETE_method_call(url string) (*http.Response, error) {
55+
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/" + url
56+
resp, err := ConnectToHTTP("DELETE", inpurl, nil)
57+
return resp, err
58+
}
59+
60+
func Non_read_onclose_get_method_call(url string)([]map[string]interface{}){
61+
res, err := http.Get("http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/"+url)
62+
if err != nil {
63+
log.Fatalln(err)
64+
}
65+
66+
defer res.Body.Close()
67+
body, err := ioutil.ReadAll(res.Body)
68+
if err != nil {
69+
log.Fatalln(err)
70+
}
71+
lstmap := []map[string]interface{}{}
72+
if err := json.Unmarshal(body, &lstmap); err != nil {
73+
panic(err)
74+
}
75+
return lstmap
76+
}
77+
78+
func Get_profile_id_by_name(name string) string {
79+
profileslstmap := Non_read_onclose_get_method_call("profiles")
80+
for _, k := range profileslstmap {
81+
profilename := fmt.Sprintf("%v", k["name"])
82+
storagetype := fmt.Sprintf("%v", k["storageType"])
83+
if profilename == name && storagetype == "file" {
84+
id := fmt.Sprintf("%v", k["id"])
85+
return id
86+
}
87+
}
88+
return "None"
89+
}
90+
91+
func Get_file_share_Id_by_name(name string) string {
92+
filesharelstmap := Non_read_onclose_get_method_call("file/shares")
93+
for _, k := range filesharelstmap {
94+
filesharename := fmt.Sprintf("%v", k["name"])
95+
status := fmt.Sprintf("%v", k["status"])
96+
if name == filesharename && status == "available" {
97+
id := fmt.Sprintf("%v", k["id"])
98+
return id
99+
}
100+
}
101+
return "None"
102+
}
103+
104+
func Get_snapshot_Id_by_name(name string) string {
105+
filesharelstmap := Non_read_onclose_get_method_call("file/snapshots")
106+
for _, k := range filesharelstmap {
107+
snapname := fmt.Sprintf("%v", k["name"])
108+
status := fmt.Sprintf("%v", k["status"])
109+
if name == snapname && status == "available" {
110+
id := fmt.Sprintf("%v", k["id"])
111+
return id
112+
}
113+
}
114+
return "None"
115+
}
116+
117+
func Get_acl_Id_by_ip(name string) string {
118+
filesharelstmap := Non_read_onclose_get_method_call("file/acls")
119+
for _, k := range filesharelstmap {
120+
ipaddr := fmt.Sprintf("%v", k["ip"])
121+
status := fmt.Sprintf("%v", k["status"])
122+
if name == ipaddr && status == "available" {
123+
id := fmt.Sprintf("%v", k["id"])
124+
return id
125+
}
126+
}
127+
return "None"
128+
}
129+
130+
func Get_all_file_shares()([]map[string]interface{}){
131+
filesharelstmap := Non_read_onclose_get_method_call("file/shares")
132+
return filesharelstmap
133+
}
134+
135+
136+
func Get_capacity_of_pool()string{
137+
poolslstmap := Non_read_onclose_get_method_call("pools")
138+
for _, k := range poolslstmap {
139+
poolname := fmt.Sprintf("%v", k["name"])
140+
pool_freecapacity := fmt.Sprintf("%v", k["freeCapacity"])
141+
if poolname == "opensds-files-default"{
142+
return pool_freecapacity
143+
}
144+
}
145+
return "None"
146+
}
147+
148+
//func Validateresponsecode(respcode int, err error) {
149+
// switch respcode{
150+
// case 200:
151+
// gomega.Expect(respcode).Should(gomega.Equal(200))
152+
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
153+
// fmt.Println("Resp. Ok....")
154+
// case 202:
155+
// gomega.Expect(respcode).Should(gomega.Equal(202))
156+
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
157+
// fmt.Println("Processing req....")
158+
// case 500:
159+
// gomega.Expect(respcode).Should(gomega.Equal(500))
160+
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
161+
// fmt.Println("Internal server error....")
162+
// case 404:
163+
// gomega.Expect(respcode).Should(gomega.Equal(404))
164+
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
165+
// fmt.Println("Resource not found....")
166+
// case 400:
167+
// gomega.Expect(respcode).Should(gomega.Equal(400))
168+
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
169+
// fmt.Println("Bad req....")
170+
// default:
171+
// fmt.Println("Test case failed")
172+
// }
173+
//}

0 commit comments

Comments
 (0)