1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-21 16:46:35 +02:00

clean up field assignments with default values to make test configuration more concise/readable

This commit is contained in:
eolson 2024-10-16 17:45:35 -07:00 committed by Martti T.
parent 03c0236fb3
commit 5a0b4dd806

View File

@ -25,7 +25,6 @@ func TestBasicAuth(t *testing.T) {
return false, nil
}
// Define the test cases
tests := []struct {
name string
authHeader string
@ -36,23 +35,20 @@ func TestBasicAuth(t *testing.T) {
expectedErrMsg string
}{
{
name: "Valid credentials",
authHeader: basic + " " + base64.StdEncoding.EncodeToString([]byte("joe:secret")),
expectedCode: http.StatusOK,
skipperResult: false,
name: "Valid credentials",
authHeader: basic + " " + base64.StdEncoding.EncodeToString([]byte("joe:secret")),
expectedCode: http.StatusOK,
},
{
name: "Case-insensitive header scheme",
authHeader: strings.ToUpper(basic) + " " + base64.StdEncoding.EncodeToString([]byte("joe:secret")),
expectedCode: http.StatusOK,
skipperResult: false,
name: "Case-insensitive header scheme",
authHeader: strings.ToUpper(basic) + " " + base64.StdEncoding.EncodeToString([]byte("joe:secret")),
expectedCode: http.StatusOK,
},
{
name: "Invalid credentials",
authHeader: basic + " " + base64.StdEncoding.EncodeToString([]byte("joe:invalid-password")),
expectedCode: http.StatusUnauthorized,
expectedAuth: basic + ` realm="someRealm"`,
skipperResult: false,
expectedErr: true,
expectedErrMsg: "Unauthorized",
},
@ -60,14 +56,12 @@ func TestBasicAuth(t *testing.T) {
name: "Invalid base64 string",
authHeader: basic + " invalidString",
expectedCode: http.StatusBadRequest,
skipperResult: false,
expectedErr: true,
expectedErrMsg: "Bad Request",
},
{
name: "Missing Authorization header",
expectedCode: http.StatusUnauthorized,
skipperResult: false,
expectedErr: true,
expectedErrMsg: "Unauthorized",
},
@ -75,7 +69,6 @@ func TestBasicAuth(t *testing.T) {
name: "Invalid Authorization header",
authHeader: base64.StdEncoding.EncodeToString([]byte("invalid")),
expectedCode: http.StatusUnauthorized,
skipperResult: false,
expectedErr: true,
expectedErrMsg: "Unauthorized",
},