Skip to content

Commit 7ca1a73

Browse files
author
Shruthi-1MN
committed
E2E test cases for file share
1 parent 8adc006 commit 7ca1a73

10 files changed

Lines changed: 202 additions & 1146 deletions

File tree

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ before_install:
2727
- sudo apt-get install -y lvm2 tgt open-iscsi
2828
- go get -v github.com/onsi/gomega
2929
- 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
3330

3431
matrix:
3532
fast_finish: true

test/e2e/e2etest.sh

100644100755
File mode changed.
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 e2e
16+
17+
package e2e
18+
19+
import (
20+
"testing"
21+
22+
"github.com/onsi/ginkgo"
23+
"github.com/onsi/gomega"
24+
"github.com/opensds/opensds/test/e2e/utils"
25+
)
26+
27+
func TestFileShare(t *testing.T) {
28+
gomega.RegisterFailHandler(ginkgo.Fail)
29+
ginkgo.RunSpecs(t, "FileShare Suite")
30+
}
31+
32+
var _ = ginkgo.Describe("FileShare Testing", func() {
33+
ginkgo.Context("Create FileShare Scenarios", func() {
34+
35+
var profile_id string
36+
var jsonStr map[string]interface{}
37+
38+
ginkgo.It("TC_FS_IT_01: Create profile for file share", func() {
39+
jsonStr = map[string]interface{}{"name": "file_profile", "description": "This is for TC_FS_IT_01", "storageType": "file"}
40+
urlstr := "profiles"
41+
resp, err := utils.POST_method_call(jsonStr, urlstr)
42+
utils.Validateresponsecode(resp.StatusCode, err)
43+
})
44+
ginkgo.It("TC_FS_IT_02: Get profile for file share", func() {
45+
profile_id = utils.Get_default_profile_id()
46+
url := "profiles/" + profile_id
47+
resp, err := utils.GET_method_call(url)
48+
utils.Validateresponsecode(resp.StatusCode, err)
49+
})
50+
ginkgo.It("TC_FS_IT_03: Create fileshare with name 'filesharetest' and size 2", func() {
51+
jsonStr = map[string]interface{}{"name": "filesharetest", "description": "This is for TCFSIT03", "size": 2}
52+
url := "file/shares"
53+
resp, err := utils.POST_method_call(jsonStr, url)
54+
utils.Validateresponsecode(resp.StatusCode, err)
55+
})
56+
})
57+
})

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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package utils
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"log"
8+
"net/http"
9+
10+
"github.com/onsi/gomega"
11+
)
12+
13+
func Validateresponsecode(respcode int, err error){
14+
if respcode == 200 {
15+
gomega.Expect(respcode).Should(gomega.Equal(200))
16+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
17+
}
18+
}
19+
20+
func POST_method_call(jsonStr map[string]interface{}, url string)(*http.Response, error){
21+
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/"+url
22+
resp, err := ConnectToHTTP("POST", inpurl, jsonStr)
23+
return resp, err
24+
}
25+
26+
func GET_method_call(url string)(*http.Response, error){
27+
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/"+url
28+
resp, err := ConnectToHTTP("GET", inpurl, nil)
29+
return resp, err
30+
}
31+
32+
func Get_default_profile_id() string {
33+
res, err := http.Get("http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/profiles")
34+
if err != nil {
35+
log.Fatalln(err)
36+
}
37+
38+
defer res.Body.Close()
39+
body, err := ioutil.ReadAll(res.Body)
40+
if err != nil {
41+
log.Fatalln(err)
42+
}
43+
44+
filesharelstmap := []map[string]interface{}{}
45+
if err := json.Unmarshal(body, &filesharelstmap); err != nil {
46+
panic(err)
47+
}
48+
for _, k := range filesharelstmap {
49+
profilename := fmt.Sprintf("%v", k["name"])
50+
storagetype := fmt.Sprintf("%v", k["storageType"])
51+
if profilename == "default_file" && storagetype == "file" {
52+
id := fmt.Sprintf("%v", k["id"])
53+
return id
54+
}
55+
}
56+
return "None"
57+
}

0 commit comments

Comments
 (0)