-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
215 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/fiber/v2/utils" | ||
) | ||
|
||
func TestFileNameWithoutExtension(t *testing.T) { | ||
t.Parallel() | ||
var ( | ||
// err error | ||
subject string | ||
expect string | ||
) | ||
|
||
subject = "/dir0/dir1/test.ext" | ||
expect = "test" | ||
result := FileNameWithoutExtension(subject) | ||
|
||
utils.AssertEqual(t, expect, result) | ||
} | ||
|
||
func TestDateStrTotime(t *testing.T) { | ||
t.Parallel() | ||
var ( | ||
err error | ||
subject string | ||
expect time.Time | ||
) | ||
|
||
subject = "1990-12-09" | ||
expect = time.Date(1990, 12, 9, 0, 0, 0, 0, time.Local) | ||
result, err := DateStrTotime(subject) | ||
if err != nil { | ||
utils.AssertEqual(t, nil, err) | ||
} | ||
utils.AssertEqual(t, expect.Unix(), result.Unix()) | ||
|
||
subject = "09-12-1990" | ||
result, err = DateStrTotime(subject) | ||
if err != nil { | ||
utils.AssertEqual(t, nil, err) | ||
} | ||
utils.AssertEqual(t, expect.Unix(), result.Unix()) | ||
|
||
subject = "19901209" | ||
result, err = DateStrTotime(subject) | ||
if err != nil { | ||
utils.AssertEqual(t, nil, err) | ||
} | ||
utils.AssertEqual(t, expect.Unix(), result.Unix()) | ||
|
||
subject = "09121990" | ||
result, err = DateStrTotime(subject) | ||
if err != nil { | ||
utils.AssertEqual(t, nil, err) | ||
} | ||
utils.AssertEqual(t, expect.Unix(), result.Unix()) | ||
} | ||
|
||
func TestTimeToDGADate(t *testing.T) { | ||
t.Parallel() | ||
var ( | ||
// err error | ||
subject time.Time | ||
expect string | ||
) | ||
|
||
subject = time.Date(1990, 12, 9, 0, 0, 0, 0, time.Local) | ||
expect = "25331209" | ||
result := TimeToDGADate(subject) | ||
|
||
utils.AssertEqual(t, expect, result) | ||
} | ||
|
||
func TestValidCID(t *testing.T) { | ||
t.Parallel() | ||
var ( | ||
err error | ||
subject string | ||
expect bool | ||
) | ||
|
||
subject = "1111111111119" | ||
expect = true | ||
result, err := ValidCID(subject) | ||
if err != nil { | ||
utils.AssertEqual(t, nil, err) | ||
} | ||
utils.AssertEqual(t, expect, result) | ||
|
||
subject = "1111111111110" | ||
expect = true | ||
result, err = ValidCID(subject) | ||
if err != nil { | ||
utils.AssertEqual(t, fiber.NewError(http.StatusBadRequest, fmt.Sprintf("invalid cid: %+v", subject)), err) | ||
} | ||
utils.AssertEqual(t, false, result) | ||
|
||
subject = "111111111111" | ||
expect = true | ||
result, err = ValidCID(subject) | ||
if err != nil { | ||
utils.AssertEqual(t, fiber.NewError(http.StatusBadRequest, fmt.Sprintf("cid must be 13 digits: %+v", subject)), err) | ||
} | ||
utils.AssertEqual(t, false, result) | ||
} |
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,23 @@ | ||
package helpers | ||
|
||
type ResponseForm struct { | ||
Success bool `json:"success"` | ||
Result interface{} `json:"result"` | ||
Messages []string `json:"messages"` | ||
Errors []*ResposeError `json:"errors"` | ||
ResultInfo *ResultInfo `json:"result_info,omitempty"` | ||
} | ||
|
||
type ResposeError struct { | ||
Code int `json:"code"` | ||
Source interface{} `json:"source,omitempty"` | ||
Title string `json:"title,omitempty"` | ||
Message string `json:"message"` | ||
} | ||
|
||
type ResultInfo struct { | ||
Page int `json:"page"` | ||
PerPage int `json:"per_page"` | ||
Count int `json:"count"` | ||
TotalCont int `json:"total_count"` | ||
} |
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,68 @@ | ||
package helpers | ||
|
||
// OauthRequest oauth request by IETF | ||
type OauthRequest struct { | ||
APIKey string `json:"client_id" form:"client_id" query:"client_id"` | ||
APISecret string `json:"client_secret" form:"client_secret" query:"client_secret"` | ||
ResponseType string `json:"response_type" form:"response_type" query:"response_type"` | ||
RedirectURI string `json:"redirect_uri" form:"redirect_uri" query:"redirect_uri"` | ||
Scope string `json:"scope" form:"scope" query:"scope"` | ||
State string `json:"state" form:"state" query:"state"` | ||
Code string `json:"code" form:"code" query:"code"` | ||
GrantType string `json:"grant_type" form:"grant_type" query:"grant_type"` | ||
UserName string `json:"username" form:"username" query:"username"` | ||
Password string `json:"password" form:"password" query:"password"` | ||
RefreshToken string `json:"refresh_token" form:"refresh_token" query:"refresh_token"` | ||
Token string `json:"token" form:"token" query:"token"` | ||
} | ||
|
||
// OauthResponse oauth request by IETF | ||
type OauthResponse struct { | ||
Scope string `json:"scope,omitempty"` | ||
State string `json:"state,omitempty"` | ||
Code string `json:"code,omitempty"` | ||
Error OauthErr `json:"error,omitempty"` | ||
ErrorDesc string `json:"error_description,omitempty"` | ||
ErrorURI string `json:"error_uri,omitempty"` | ||
AccessToken string `json:"access_token,omitempty"` | ||
IDToken string `json:"id_token,omitempty"` | ||
TokenType string `json:"token_type,omitempty"` | ||
ExpiresIn int `json:"expires_in,omitempty"` | ||
RefreshToken string `json:"refresh_token,omitempty"` | ||
Data interface{} `json:"data,omitempty"` | ||
} | ||
|
||
// OauthErr Oauth error response | ||
type OauthErr string | ||
|
||
// Oauth Error Response | ||
const ( | ||
InvalidRequest OauthErr = "invalid_request" | ||
UnauthorizedClient OauthErr = "unauthorized_client" | ||
AccessDenied OauthErr = "access_denied" | ||
UnsupportType OauthErr = "unsupported_response_type" | ||
InvalidScope OauthErr = "invalid_scope" | ||
ServerError OauthErr = "server_error" | ||
Unavailable OauthErr = "temporarily_unavailable" | ||
) | ||
|
||
// GrantType Oauth grant type | ||
type GrantType string | ||
|
||
// GrantType constant | ||
const ( | ||
GrantTypeCode GrantType = "authorization_code" | ||
GrantTypeClient GrantType = "client_credentials" | ||
GrantTypeRefresh GrantType = "refresh_token" | ||
GrantTypeaccess GrantType = "access_token" | ||
GrantTypePassword GrantType = "password" | ||
) | ||
|
||
// ResponseType Oauth response type | ||
type ResponseType string | ||
|
||
// Responsetype constant | ||
const ( | ||
ResponseTypeCode ResponseType = "code" | ||
ResponseTypeToken ResponseType = "token" | ||
) |