-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: when enable or disable existing SSL, an error occurred (#1064)
* fix: when enable or disable existing SSL, an error occurred * fix: keep the code uniform * fix: lint * fix: keep the code uniform * fix: license * chore: add comment to note that json.Marshal and json.Unmarshal may cause the precision loss Co-authored-by: 琚致远 <juzhiyuan@apache.org> Co-authored-by: YuanSheng Wang <membphis@gmail.com>
- Loading branch information
1 parent
d2b5772
commit 6fa6a16
Showing
6 changed files
with
130 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package consts | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder { | ||
req := httptest.NewRequest(method, path, nil) | ||
w := httptest.NewRecorder() | ||
r.ServeHTTP(w, req) | ||
return w | ||
} | ||
|
||
func TestRequestLogHandler(t *testing.T) { | ||
r := gin.New() | ||
r.GET("/", ErrorWrapper(func(c *gin.Context) (interface{}, error) { | ||
return nil, nil | ||
})) | ||
r.GET("/notfound", ErrorWrapper(func(c *gin.Context) (interface{}, error) { | ||
return nil, fmt.Errorf("data not found") | ||
})) | ||
r.GET("/invalid", ErrorWrapper(func(c *gin.Context) (interface{}, error) { | ||
return nil, fmt.Errorf("schema validate failed") | ||
})) | ||
r.GET("/error", ErrorWrapper(func(c *gin.Context) (interface{}, error) { | ||
return nil, fmt.Errorf("internal system error") | ||
})) | ||
|
||
w := performRequest(r, "GET", "/") | ||
assert.Equal(t, 200, w.Code) | ||
|
||
w = performRequest(r, "GET", "/notfound") | ||
assert.Equal(t, 404, w.Code) | ||
|
||
w = performRequest(r, "GET", "/invalid") | ||
assert.Equal(t, 400, w.Code) | ||
|
||
w = performRequest(r, "GET", "/error") | ||
assert.Equal(t, 500, w.Code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters