Skip to content

Commit 93d041e

Browse files
cniackzdvaldivia
andauthored
Add test to create namespace (#2075)
Co-authored-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
1 parent 94e419e commit 93d041e

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

.github/workflows/jobs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ jobs:
15211521
go tool cover -func=all.out | grep total > tmp2
15221522
result=`cat tmp2 | awk 'END {print $3}'`
15231523
result=${result%\%}
1524-
threshold=50.9
1524+
threshold=51.00
15251525
echo "Result:"
15261526
echo "$result%"
15271527
if (( $(echo "$result >= $threshold" |bc -l) )); then

operator-integration/tenant_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,71 @@ func TestListPVCsForTenant(t *testing.T) {
727727
assert.Equal(strings.Contains(listObjs.Pvcs[i].Name, pvcArray[i]), true)
728728
}
729729
}
730+
731+
func CreateNamespace(nameSpace string) (*http.Response, error) {
732+
/*
733+
Description: Creates a new Namespace with given information
734+
URL: /namespace
735+
HTTP Verb: POST
736+
*/
737+
requestDataAdd := map[string]interface{}{
738+
"name": nameSpace,
739+
}
740+
requestDataJSON, _ := json.Marshal(requestDataAdd)
741+
requestDataBody := bytes.NewReader(requestDataJSON)
742+
request, err := http.NewRequest(
743+
"POST",
744+
"http://localhost:9090/api/v1/namespace/",
745+
requestDataBody,
746+
)
747+
if err != nil {
748+
log.Println(err)
749+
}
750+
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
751+
request.Header.Add("Content-Type", "application/json")
752+
client := &http.Client{
753+
Timeout: 2 * time.Second,
754+
}
755+
response, err := client.Do(request)
756+
return response, err
757+
}
758+
759+
func TestCreateNamespace(t *testing.T) {
760+
/*
761+
Function to Create a Namespace only once.
762+
*/
763+
assert := assert.New(t)
764+
namespace := "new-namespace-thujun2208pm"
765+
tests := []struct {
766+
name string
767+
nameSpace string
768+
expectedStatus int
769+
}{
770+
{
771+
name: "Create Namespace for the first time",
772+
expectedStatus: 201,
773+
nameSpace: namespace,
774+
},
775+
{
776+
name: "Create repeated namespace for second time",
777+
expectedStatus: 500,
778+
nameSpace: namespace,
779+
},
780+
}
781+
for _, tt := range tests {
782+
t.Run(tt.name, func(t *testing.T) {
783+
resp, err := CreateNamespace(tt.nameSpace)
784+
assert.Nil(err)
785+
if err != nil {
786+
log.Println(err)
787+
return
788+
}
789+
if resp != nil {
790+
assert.Equal(
791+
tt.expectedStatus, resp.StatusCode, "failed")
792+
} else {
793+
assert.Fail("resp cannot be nil")
794+
}
795+
})
796+
}
797+
}

0 commit comments

Comments
 (0)