Skip to content

Commit

Permalink
test clean path
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Sep 14, 2023
1 parent 8dab423 commit 2b54e2e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package api

import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"sort"
"sync"
"testing"
Expand Down Expand Up @@ -210,3 +212,22 @@ func (suite *serviceTestSuite) TestServiceLabels() {
apiutil.NewAccessPath("/pd/api/v1/metric/query", http.MethodGet))
suite.Equal("QueryMetric", serviceLabel)
}

func (suite *adminTestSuite) TestCleanPath() {
re := suite.Require()
// transfer path to /config
url := fmt.Sprintf("%s/admin/persist-file/../../config", suite.urlPrefix)
cfg := &config.Config{}
err := testutil.ReadGetJSON(re, testDialClient, url, cfg)
suite.NoError(err)

// handled by router
response := httptest.NewRecorder()
r, _, _ := NewHandler(context.Background(), suite.svr)
request, err := http.NewRequest(http.MethodGet, url, nil)
re.NoError(err)
r.ServeHTTP(response, request)
// handled by `cleanPath` which is in `mux.ServeHTTP`
re.NotNil(response.Result().Header["Location"])

Check failure on line 231 in server/api/server_test.go

View workflow job for this annotation

GitHub Actions / statics

response body must be closed (bodyclose)
re.Contains(response.Result().Header["Location"][0], "/pd/api/v1/config")

Check failure on line 232 in server/api/server_test.go

View workflow job for this annotation

GitHub Actions / statics

response body must be closed (bodyclose)
}

0 comments on commit 2b54e2e

Please sign in to comment.