Skip to content

Commit

Permalink
E2E test cases for file share
Browse files Browse the repository at this point in the history
  • Loading branch information
Shruthi-1MN committed Nov 11, 2019
1 parent 8adc006 commit 7ca1a73
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 1,146 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ before_install:
- sudo apt-get install -y lvm2 tgt open-iscsi
- go get -v github.com/onsi/gomega
- go get -v github.com/onsi/ginkgo/ginkgo
- go get github.com/modocache/gover
- go get -v -t ./...
- export PATH=$PATH:$HOME/gopath/bin

matrix:
fast_finish: true
Expand Down
Empty file modified test/e2e/e2etest.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build integration
// +build e2e

package integration
package e2e

import (
"fmt"
Expand All @@ -27,7 +27,7 @@ import (
//Function to run the Ginkgo Test
func TestFileShareIntegration(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
//var UID string

var _ = ginkgo.BeforeSuite(func() {
fmt.Println("Before Suite Execution")

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

ginkgo.RunSpecs(t, "File Share Integration Test Suite")
}
ginkgo.RunSpecs(t, "File Share E2E Test Suite")
}
57 changes: 57 additions & 0 deletions test/e2e/fileshare_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 e2e

package e2e

import (
"testing"

"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"github.com/opensds/opensds/test/e2e/utils"
)

func TestFileShare(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "FileShare Suite")
}

var _ = ginkgo.Describe("FileShare Testing", func() {
ginkgo.Context("Create FileShare Scenarios", func() {

var profile_id string
var jsonStr map[string]interface{}

ginkgo.It("TC_FS_IT_01: Create profile for file share", func() {
jsonStr = map[string]interface{}{"name": "file_profile", "description": "This is for TC_FS_IT_01", "storageType": "file"}
urlstr := "profiles"
resp, err := utils.POST_method_call(jsonStr, urlstr)
utils.Validateresponsecode(resp.StatusCode, err)
})
ginkgo.It("TC_FS_IT_02: Get profile for file share", func() {
profile_id = utils.Get_default_profile_id()
url := "profiles/" + profile_id
resp, err := utils.GET_method_call(url)
utils.Validateresponsecode(resp.StatusCode, err)
})
ginkgo.It("TC_FS_IT_03: Create fileshare with name 'filesharetest' and size 2", func() {
jsonStr = map[string]interface{}{"name": "filesharetest", "description": "This is for TCFSIT03", "size": 2}
url := "file/shares"
resp, err := utils.POST_method_call(jsonStr, url)
utils.Validateresponsecode(resp.StatusCode, err)
})
})
})
83 changes: 83 additions & 0 deletions test/e2e/utils/HttpHelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
)

func readResponseBody(resp *http.Response) {
if resp.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("reading response body failed: %v", err)
}
bodyString := string(bodyBytes)
fmt.Printf(bodyString)
}
}


func ConnectToHTTP(operation, testMgrEndPoint string, payload map[string]interface{}) (*http.Response, error) {
var httpMethod string

switch operation {
case "PUT":
httpMethod = http.MethodPut

case "POST":
httpMethod = http.MethodPost
case "DELETE":
httpMethod = http.MethodDelete

case "GET":
httpMethod = http.MethodGet
default:

}

respbytes, err := json.Marshal(payload)
if err != nil {
fmt.Printf("payload marshal failed: %v", err)
}

req, err := http.NewRequest(httpMethod, testMgrEndPoint, bytes.NewBuffer(respbytes))
if err != nil {
fmt.Printf("error while getting http request: %v", err)

}

client := &http.Client{}
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Printf("hTTP request is failed :%v", err)

}
if resp != nil {
fmt.Printf("resp is ... :%v", resp)
io.Copy(os.Stdout, resp.Body)
defer resp.Body.Close()
readResponseBody(resp)
}

return resp, err
}
57 changes: 57 additions & 0 deletions test/e2e/utils/fileshare_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package utils

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"

"github.com/onsi/gomega"
)

func Validateresponsecode(respcode int, err error){
if respcode == 200 {
gomega.Expect(respcode).Should(gomega.Equal(200))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}

func POST_method_call(jsonStr map[string]interface{}, url string)(*http.Response, error){
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/"+url
resp, err := ConnectToHTTP("POST", inpurl, jsonStr)
return resp, err
}

func GET_method_call(url string)(*http.Response, error){
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/"+url
resp, err := ConnectToHTTP("GET", inpurl, nil)
return resp, err
}

func Get_default_profile_id() string {
res, err := http.Get("http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/profiles")
if err != nil {
log.Fatalln(err)
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatalln(err)
}

filesharelstmap := []map[string]interface{}{}
if err := json.Unmarshal(body, &filesharelstmap); err != nil {
panic(err)
}
for _, k := range filesharelstmap {
profilename := fmt.Sprintf("%v", k["name"])
storagetype := fmt.Sprintf("%v", k["storageType"])
if profilename == "default_file" && storagetype == "file" {
id := fmt.Sprintf("%v", k["id"])
return id
}
}
return "None"
}
Loading

0 comments on commit 7ca1a73

Please sign in to comment.