Skip to content

Commit 3a09361

Browse files
authored
List tenants by namespace test (#1736)
1 parent 6ca17a3 commit 3a09361

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

.github/workflows/jobs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ jobs:
830830
result=${result%\%}
831831
echo "result:"
832832
echo $result
833-
threshold=51.4
833+
threshold=51.8
834834
if (( $(echo "$result >= $threshold" |bc -l) )); then
835835
echo "It is equal or greater than threshold, passed!"
836836
else

operator-integration/tenant_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,48 @@ func TestCreateTenant(t *testing.T) {
432432

433433
printEndFunc("TestCreateTenant")
434434
}
435+
436+
func ListTenantsByNameSpace(namespace string) (*http.Response, error) {
437+
/*
438+
Helper function to list buckets
439+
HTTP Verb: GET
440+
URL: http://localhost:9090/api/v1/namespaces/{namespace}/tenants
441+
*/
442+
request, err := http.NewRequest(
443+
"GET", "http://localhost:9090/api/v1/namespaces/"+namespace+"/tenants", nil)
444+
if err != nil {
445+
log.Println(err)
446+
}
447+
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
448+
request.Header.Add("Content-Type", "application/json")
449+
client := &http.Client{
450+
Timeout: 2 * time.Second,
451+
}
452+
response, err := client.Do(request)
453+
return response, err
454+
}
455+
456+
func TestListTenantsByNameSpace(t *testing.T) {
457+
assert := assert.New(t)
458+
namespace := "default"
459+
resp, err := ListTenantsByNameSpace(namespace)
460+
assert.Nil(err)
461+
if err != nil {
462+
log.Println(err)
463+
return
464+
}
465+
if resp != nil {
466+
assert.Equal(
467+
200, resp.StatusCode, "Status Code is incorrect")
468+
}
469+
bodyBytes, _ := ioutil.ReadAll(resp.Body)
470+
result := models.ListTenantsResponse{}
471+
err = json.Unmarshal(bodyBytes, &result)
472+
if err != nil {
473+
log.Println(err)
474+
assert.Nil(err)
475+
}
476+
TenantName := &result.Tenants[0].Name // The array has to be empty, no index accessible
477+
fmt.Println(*TenantName)
478+
assert.Equal("new-tenant", *TenantName, *TenantName)
479+
}

0 commit comments

Comments
 (0)