-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#18 Implement unit test for book controller
- Loading branch information
Showing
8 changed files
with
242 additions
and
56 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,41 @@ | ||
package controller | ||
|
||
const ( | ||
// API represents the group of API. | ||
API = "/api" | ||
// APIBook represents the group of book management API. | ||
APIBook = API + "/book" | ||
// APIBookList is | ||
APIBookList = APIBook + "/list" | ||
// APIBookSearch is | ||
APIBookSearch = APIBook + "/search" | ||
// APIBookRegist is | ||
APIBookRegist = APIBook + "/new" | ||
// APIBookEdit is | ||
APIBookEdit = APIBook + "/edit" | ||
// APIBookDelete is | ||
APIBookDelete = APIBook + "/delete" | ||
) | ||
|
||
const ( | ||
// APIMaster represents the group of master management API. | ||
APIMaster = API + "/master" | ||
// APIMasterCategory is | ||
APIMasterCategory = APIMaster + "/category" | ||
// APIMasterFormat is | ||
APIMasterFormat = APIMaster + "/format" | ||
) | ||
|
||
const ( | ||
// APIAccount represents the group of account management API. | ||
APIAccount = API + "/account" | ||
// APIAccountLoginStatus is | ||
APIAccountLoginStatus = APIAccount + "/loginStatus" | ||
// APIAccountLoginAccount is | ||
APIAccountLoginAccount = APIAccount + "/loginAccount" | ||
) | ||
|
||
const ( | ||
// APIHealth is | ||
APIHealth = API + "/health" | ||
) |
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
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,53 @@ | ||
package test | ||
|
||
// RequestBuilder builds request URL. | ||
type RequestBuilder struct { | ||
url string | ||
params map[string]string | ||
} | ||
|
||
// NewRequestBuilder is constructor. | ||
func NewRequestBuilder() *RequestBuilder { | ||
return &RequestBuilder{url: "", params: make(map[string]string)} | ||
} | ||
|
||
// URL sets request base url. | ||
func (b *RequestBuilder) URL(url string) *RequestBuilder { | ||
b.url = url | ||
return b | ||
} | ||
|
||
// Params set a request parameter of the reqest. | ||
func (b *RequestBuilder) Params(name string, value string) *RequestBuilder { | ||
b.params[name] = value | ||
return b | ||
} | ||
|
||
// Build builds request url. | ||
func (b *RequestBuilder) Build() *RequestURL { | ||
return &RequestURL{url: b.url, params: b.params} | ||
} | ||
|
||
// RequestURL is the element to compose request url. | ||
type RequestURL struct { | ||
url string | ||
params map[string]string | ||
} | ||
|
||
// GetRequestURL returns request url builded by request builder. | ||
func (r *RequestURL) GetRequestURL() string { | ||
return r.url + "?" + r.getParams() | ||
} | ||
|
||
func (r *RequestURL) getParams() string { | ||
count := 0 | ||
result := "" | ||
for key, value := range r.params { | ||
result += key + "=" + value | ||
if count != len(r.params)-1 { | ||
result += "&" | ||
count++ | ||
} | ||
} | ||
return result | ||
} |