Skip to content

Commit

Permalink
Adding Tenant Log Test (#2093)
Browse files Browse the repository at this point in the history
  • Loading branch information
cniackz committed Jun 7, 2022
1 parent d09d6e1 commit 969feb8
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/jobs.yaml
Expand Up @@ -1536,7 +1536,7 @@ jobs:
go tool cover -func=all.out | grep total > tmp2
result=`cat tmp2 | awk 'END {print $3}'`
result=${result%\%}
threshold=51.90
threshold=52.20
echo "Result:"
echo "$result%"
if (( $(echo "$result >= $threshold" |bc -l) )); then
Expand Down
128 changes: 128 additions & 0 deletions operator-integration/tenant_test.go
Expand Up @@ -955,3 +955,131 @@ func TestDisableTenantLogging(t *testing.T) {
)
}
}

func GetTenantLogs(nameSpace, tenant string) (*http.Response, error) {
/*
URL: /namespaces/{namespace}/tenants/{tenant}/log
summary: Get Tenant Logs
HTTP Verb:GET
*/
request, err := http.NewRequest(
"GET",
"http://localhost:9090/api/v1/namespaces/"+nameSpace+"/tenants/"+tenant+"/log",
nil,
)
if err != nil {
log.Println(err)
}
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
request.Header.Add("Content-Type", "application/json")
client := &http.Client{
Timeout: 2 * time.Second,
}
response, err := client.Do(request)
return response, err
}

func SetTenantLogs(labels, annotations, nodeSelector, dbLabels, dbAnnotations, dbNodeSelector []string, nameSpace, tenant, dbServiceAccountName, logMemRequest, logDBMemRequest, diskCapacityGB, serviceAccountName string) (*http.Response, error) {
/*
URL: /namespaces/{namespace}/tenants/{tenant}/log
summary: Set Tenant Logs
HTTP Verb: PUT
*/
requestDataAdd := map[string]interface{}{
"labels": labels,
"annotations": annotations,
"dbAnnotations": dbAnnotations,
"dbLabels": dbLabels,
"dbNodeSelector": dbNodeSelector,
"diskCapacityGB": diskCapacityGB,
"nodeSelector": nodeSelector,
"serviceAccountName": serviceAccountName,
"dbServiceAccountName": dbServiceAccountName,
"logMemRequest": logMemRequest,
"logDBMemRequest": logDBMemRequest,
}
requestDataJSON, _ := json.Marshal(requestDataAdd)
requestDataBody := bytes.NewReader(requestDataJSON)
request, err := http.NewRequest(
"PUT",
"http://localhost:9090/api/v1/namespaces/"+nameSpace+"/tenants/"+tenant+"/log",
requestDataBody,
)
if err != nil {
log.Println(err)
}
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
request.Header.Add("Content-Type", "application/json")
client := &http.Client{
Timeout: 2 * time.Second,
}
response, err := client.Do(request)
return response, err
}

func TestGetTenantLogs(t *testing.T) {
// Vars
assert := assert.New(t)
namespace := "tenant-lite"
tenant := "storage-lite"

// Get Log Settings
resp, err := GetTenantLogs(namespace, tenant)
if err != nil {
log.Println(err)
return
}
if resp != nil {
assert.Equal(
200,
resp.StatusCode,
inspectHTTPResponse(resp),
)
}
}

func TestSetTenantLogs(t *testing.T) {
// Vars
assert := assert.New(t)
nameSpace := "tenant-lite"
tenant := "storage-lite"
var nodeSelector []string
var labels []string
var annotations []string
var dbAnnotations []string
var dbNodeSelector []string
var dbLabels []string
diskCapacityGB := "2"
dbServiceAccountName := ""
logMemRequest := "0Gi"
logDBMemRequest := "0Gi"
serviceAccountName := ""

// Set Tenant Logs
resp, err := SetTenantLogs(
labels,
annotations,
nodeSelector,
dbLabels,
dbAnnotations,
dbNodeSelector,
nameSpace,
tenant,
dbServiceAccountName,
logMemRequest,
logDBMemRequest,
diskCapacityGB,
serviceAccountName,
)
if err != nil {
log.Println(err)
return
}
if resp != nil {
assert.Equal(
200,
resp.StatusCode,
inspectHTTPResponse(resp),
)
}
}

0 comments on commit 969feb8

Please sign in to comment.