-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shruthi-1MN
committed
Nov 11, 2019
1 parent
8adc006
commit 7ca1a73
Showing
10 changed files
with
202 additions
and
1,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.