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 Dec 11, 2019
1 parent 503d72d commit 5b8c550
Show file tree
Hide file tree
Showing 9 changed files with 1,073 additions and 1,150 deletions.
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,9 @@ before_install:
- sudo apt-get install -y build-essential gcc
- sudo apt-get install -y librados-dev librbd-dev
- sudo apt-get install -y lvm2 tgt open-iscsi
<<<<<<< 0feeb98168409d1666fe427663d0ab192adb5e68
- sudo docker pull p1c2u/openapi-spec-validator

=======
- 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
>>>>>>> end

matrix:
fast_finish: true
Expand Down
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")
}
812 changes: 812 additions & 0 deletions test/e2e/fileshare_test.go

Large diffs are not rendered by default.

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
}
173 changes: 173 additions & 0 deletions test/e2e/utils/fileshare_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package utils

import (
"encoding/json"
"fmt"
"github.com/onsi/gomega"
"io/ioutil"
"log"
"net/http"
)

func Resp_ok(resp int, err error){
gomega.Expect(resp).Should(gomega.Equal(200))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
fmt.Println("Resp. Ok....")
}

func Resp_processing(resp int, err error){
gomega.Expect(resp).Should(gomega.Equal(202))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
fmt.Println("Processing operations....")
}

func Not_allowed_operation(resp int, err error){
gomega.Expect(resp).Should(gomega.Equal(400))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
fmt.Println("Not allowed operation....")
}

func Resource_Not_found(resp int, err error){
gomega.Expect(resp).Should(gomega.Equal(404))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
fmt.Println("No resource....")
}

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 PUT_method_call(jsonStr map[string]interface{}, url string) (*http.Response, error) {
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/" + url
resp, err := ConnectToHTTP("PUT", 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 DELETE_method_call(url string) (*http.Response, error) {
inpurl := "http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/" + url
resp, err := ConnectToHTTP("DELETE", inpurl, nil)
return resp, err
}

func Non_read_onclose_get_method_call(url string)([]map[string]interface{}){
res, err := http.Get("http://127.0.0.1:50040/v1beta/e93b4c0934da416eb9c8d120c5d04d96/"+url)
if err != nil {
log.Fatalln(err)
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatalln(err)
}
lstmap := []map[string]interface{}{}
if err := json.Unmarshal(body, &lstmap); err != nil {
panic(err)
}
return lstmap
}

func Get_profile_id_by_name(name string) string {
profileslstmap := Non_read_onclose_get_method_call("profiles")
for _, k := range profileslstmap {
profilename := fmt.Sprintf("%v", k["name"])
storagetype := fmt.Sprintf("%v", k["storageType"])
if profilename == name && storagetype == "file" {
id := fmt.Sprintf("%v", k["id"])
return id
}
}
return "None"
}

func Get_file_share_Id_by_name(name string) string {
filesharelstmap := Non_read_onclose_get_method_call("file/shares")
for _, k := range filesharelstmap {
filesharename := fmt.Sprintf("%v", k["name"])
status := fmt.Sprintf("%v", k["status"])
if name == filesharename && status == "available" {
id := fmt.Sprintf("%v", k["id"])
return id
}
}
return "None"
}

func Get_snapshot_Id_by_name(name string) string {
filesharelstmap := Non_read_onclose_get_method_call("file/snapshots")
for _, k := range filesharelstmap {
snapname := fmt.Sprintf("%v", k["name"])
status := fmt.Sprintf("%v", k["status"])
if name == snapname && status == "available" {
id := fmt.Sprintf("%v", k["id"])
return id
}
}
return "None"
}

func Get_acl_Id_by_ip(name string) string {
filesharelstmap := Non_read_onclose_get_method_call("file/acls")
for _, k := range filesharelstmap {
ipaddr := fmt.Sprintf("%v", k["ip"])
status := fmt.Sprintf("%v", k["status"])
if name == ipaddr && status == "available" {
id := fmt.Sprintf("%v", k["id"])
return id
}
}
return "None"
}

func Get_all_file_shares()([]map[string]interface{}){
filesharelstmap := Non_read_onclose_get_method_call("file/shares")
return filesharelstmap
}


func Get_capacity_of_pool()string{
poolslstmap := Non_read_onclose_get_method_call("pools")
for _, k := range poolslstmap {
poolname := fmt.Sprintf("%v", k["name"])
pool_freecapacity := fmt.Sprintf("%v", k["freeCapacity"])
if poolname == "opensds-files-default"{
return pool_freecapacity
}
}
return "None"
}

//func Validateresponsecode(respcode int, err error) {
// switch respcode{
// case 200:
// gomega.Expect(respcode).Should(gomega.Equal(200))
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
// fmt.Println("Resp. Ok....")
// case 202:
// gomega.Expect(respcode).Should(gomega.Equal(202))
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
// fmt.Println("Processing req....")
// case 500:
// gomega.Expect(respcode).Should(gomega.Equal(500))
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
// fmt.Println("Internal server error....")
// case 404:
// gomega.Expect(respcode).Should(gomega.Equal(404))
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
// fmt.Println("Resource not found....")
// case 400:
// gomega.Expect(respcode).Should(gomega.Equal(400))
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
// fmt.Println("Bad req....")
// default:
// fmt.Println("Test case failed")
// }
//}
Loading

0 comments on commit 5b8c550

Please sign in to comment.