From ea0c83ea748d20105830bee405b1a8633fe20926 Mon Sep 17 00:00:00 2001 From: Cesar Celis Hernandez Date: Thu, 31 Mar 2022 20:35:25 -0400 Subject: [PATCH] Node Labels Test (#1787) --- .github/workflows/jobs.yaml | 2 +- operator-integration/tenant_test.go | 52 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/.github/workflows/jobs.yaml b/.github/workflows/jobs.yaml index f17a49b18..510e1017e 100644 --- a/.github/workflows/jobs.yaml +++ b/.github/workflows/jobs.yaml @@ -1142,7 +1142,7 @@ jobs: result=${result%\%} echo "result:" echo $result - threshold=53.20 + threshold=54.00 if (( $(echo "$result >= $threshold" |bc -l) )); then echo "It is equal or greater than threshold, passed!" else diff --git a/operator-integration/tenant_test.go b/operator-integration/tenant_test.go index 39f3b9f0f..2cb848e6c 100644 --- a/operator-integration/tenant_test.go +++ b/operator-integration/tenant_test.go @@ -21,12 +21,14 @@ import ( b64 "encoding/base64" "encoding/json" "fmt" + "io" "io/ioutil" "log" "net/http" "os" "os/exec" "strconv" + "strings" "testing" "time" @@ -39,6 +41,17 @@ import ( var token string +func inspectHTTPResponse(httpResponse *http.Response) string { + /* + Helper function to inspect the content of a HTTP response. + */ + b, err := io.ReadAll(httpResponse.Body) + if err != nil { + log.Fatalln(err) + } + return "Http Response: " + string(b) +} + func decodeBase64(value string) string { /* Helper function to decode in base64 @@ -477,3 +490,42 @@ func TestListTenantsByNameSpace(t *testing.T) { fmt.Println(*TenantName) assert.Equal("new-tenant", *TenantName, *TenantName) } + +func ListNodeLabels() (*http.Response, error) { + /* + Helper function to list buckets + HTTP Verb: GET + URL: http://localhost:9090/api/v1/nodes/labels + */ + request, err := http.NewRequest( + "GET", "http://localhost:9090/api/v1/nodes/labels", 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 TestListNodeLabels(t *testing.T) { + assert := assert.New(t) + resp, err := ListNodeLabels() + assert.Nil(err) + if err != nil { + log.Println(err) + return + } + finalResponse := inspectHTTPResponse(resp) + if resp != nil { + assert.Equal( + 200, resp.StatusCode, finalResponse) + } + // "beta.kubernetes.io/arch" is a label of our nodes and is expected + assert.True( + strings.Contains(finalResponse, "beta.kubernetes.io/arch"), + finalResponse) +}