From e9cc5679777912cda496ea5cd7f5490aff823298 Mon Sep 17 00:00:00 2001 From: Cesar Celis Hernandez Date: Mon, 11 Apr 2022 12:56:16 -0400 Subject: [PATCH] correcting the testing package (#1819) --- .github/workflows/jobs.yaml | 2 +- Makefile | 2 +- operator-integration/tenant_test.go | 59 +++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/.github/workflows/jobs.yaml b/.github/workflows/jobs.yaml index 510e1017e..95bea2717 100644 --- a/.github/workflows/jobs.yaml +++ b/.github/workflows/jobs.yaml @@ -1142,7 +1142,7 @@ jobs: result=${result%\%} echo "result:" echo $result - threshold=54.00 + threshold=35.20 if (( $(echo "$result >= $threshold" |bc -l) )); then echo "It is equal or greater than threshold, passed!" else diff --git a/Makefile b/Makefile index 902778124..bf9fc046f 100644 --- a/Makefile +++ b/Makefile @@ -182,7 +182,7 @@ test-sso-integration: test-operator-integration: @(echo "Start cd operator-integration && go test:") @(pwd) - @(cd operator-integration && go test -coverpkg=../restapi -c -tags testrunmain . && mkdir -p coverage && ./operator-integration.test -test.v -test.run "^Test*" -test.coverprofile=coverage/operator-api.out) + @(cd operator-integration && go test -coverpkg=../operatorapi -c -tags testrunmain . && mkdir -p coverage && ./operator-integration.test -test.v -test.run "^Test*" -test.coverprofile=coverage/operator-api.out) test-operator: @(env bash $(PWD)/portal-ui/tests/scripts/operator.sh) diff --git a/operator-integration/tenant_test.go b/operator-integration/tenant_test.go index 2cb848e6c..3f43428da 100644 --- a/operator-integration/tenant_test.go +++ b/operator-integration/tenant_test.go @@ -34,8 +34,8 @@ import ( "github.com/go-openapi/loads" "github.com/minio/console/models" - "github.com/minio/console/restapi" - "github.com/minio/console/restapi/operations" + "github.com/minio/console/operatorapi" + "github.com/minio/console/operatorapi/operations" "github.com/stretchr/testify/assert" ) @@ -87,11 +87,11 @@ func printEndFunc(functionName string) { fmt.Println("") } -func initConsoleServer() (*restapi.Server, error) { +func initConsoleServer() (*operatorapi.Server, error) { //os.Setenv("CONSOLE_MINIO_SERVER", "localhost:9000") - swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON) + swaggerSpec, err := loads.Embedded(operatorapi.SwaggerJSON, operatorapi.FlatSwaggerJSON) if err != nil { return nil, err } @@ -101,24 +101,22 @@ func initConsoleServer() (*restapi.Server, error) { } // Initialize MinIO loggers - restapi.LogInfo = noLog - restapi.LogError = noLog + operatorapi.LogInfo = noLog + operatorapi.LogError = noLog - api := operations.NewConsoleAPI(swaggerSpec) + api := operations.NewOperatorAPI(swaggerSpec) api.Logger = noLog - server := restapi.NewServer(api) + server := operatorapi.NewServer(api) // register all APIs server.ConfigureAPI() - //restapi.GlobalRootCAs, restapi.GlobalPublicCerts, restapi.GlobalTLSCertsManager = globalRootCAs, globalPublicCerts, globalTLSCerts - consolePort, _ := strconv.Atoi("9090") server.Host = "0.0.0.0" server.Port = consolePort - restapi.Port = "9090" - restapi.Hostname = "0.0.0.0" + operatorapi.Port = "9090" + operatorapi.Hostname = "0.0.0.0" return server, nil } @@ -529,3 +527,40 @@ func TestListNodeLabels(t *testing.T) { strings.Contains(finalResponse, "beta.kubernetes.io/arch"), finalResponse) } + +func GetPodEvents(nameSpace string, tenant string, podName string) (*http.Response, error) { + /* + Helper function to get events for pod + URL: /namespaces/{namespace}/tenants/{tenant}/pods/{podName}/events + HTTP Verb: GET + */ + request, err := http.NewRequest( + "GET", "http://localhost:9090/api/v1/namespaces/"+nameSpace+"/tenants/"+tenant+"/pods/"+podName+"/events", 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 TestGetPodEvents(t *testing.T) { + assert := assert.New(t) + namespace := "tenant-lite" + tenant := "storage-lite" + podName := "storage-lite-pool-0-0" + resp, err := GetPodEvents(namespace, tenant, podName) + assert.Nil(err) + if err != nil { + log.Println(err) + return + } + if resp != nil { + assert.Equal( + 200, resp.StatusCode, "Status Code is incorrect") + } +}