Skip to content

Commit

Permalink
test(parameters_name_decoding_handler_test.go): add test cases
Browse files Browse the repository at this point in the history
add test cases
  • Loading branch information
XdpCs committed Jan 20, 2024
1 parent 2747753 commit 1828c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 0 additions & 1 deletion parameters_name_decoding_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (handler *ParametersNameDecodingHandler) Intercept(pipeline Pipeline, middl
ctx := req.Context()
if obsOptions != nil {
ctx, span := otel.GetTracerProvider().Tracer(obsOptions.GetTracerInstrumentationName()).Start(ctx, "ParametersNameDecodingHandler_Intercept")

span.SetAttributes(attribute.Bool("com.microsoft.kiota.handler.parameters_name_decoding.enable", reqOption.GetEnable()))
req = req.WithContext(ctx)
defer span.End()
Expand Down
10 changes: 9 additions & 1 deletion parameters_name_decoding_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ func TestItDecodesQueryParameterNames(t *testing.T) {
{"?%24select=diplayName&api%2Eversion=2", "/?$select=diplayName&api.version=2"},
{"/api-version/?%24select=diplayName&api%2Eversion=2", "/api-version/?$select=diplayName&api.version=2"},
{"", "/"},
{"?q=1%2B2", "/?q=1%2B2"}, //Values are not decoded
{"?q=M%26A", "/?q=M%26A"}, //Values are not decoded
{"?q%2D1=M%26A", "/?q-1=M%26A"}, //Values are not decoded but params are
{"?q%2D1&q=M%26A=M%26A", "/?q-1&q=M%26A=M%26A"}, //Values are not decoded but params are
{"?%24select=diplayName&api%2Dversion=1%2B2", "/?$select=diplayName&api-version=1%2B2"}, //Values are not decoded but params are
{"?%24select=diplayName&api%2Dversion=M%26A", "/?$select=diplayName&api-version=M%26A"}, //Values are not decoded but params are
{"?%24select=diplayName&api%7Eversion=M%26A", "/?$select=diplayName&api~version=M%26A"}, //Values are not decoded but params are
{"?%24select=diplayName&api%2Eversion=M%26A", "/?$select=diplayName&api.version=M%26A"}, //Values are not decoded but params are
{"?%24select=diplayName&api%2Eversion=M%26A", "/?$select=diplayName&api.version=M%26A"}, //Values are not decoded but params are
}
result := ""
testServer := httptest.NewServer(nethttp.HandlerFunc(func(res nethttp.ResponseWriter, req *nethttp.Request) {
Expand All @@ -24,7 +33,6 @@ func TestItDecodesQueryParameterNames(t *testing.T) {
}))
defer func() { testServer.Close() }()
for _, data := range testData {

handler := NewParametersNameDecodingHandler()
input := testServer.URL + data[0]
expected := data[1]
Expand Down

0 comments on commit 1828c65

Please sign in to comment.