Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Test remaining handlers by matching their routes
Browse files Browse the repository at this point in the history
  • Loading branch information
scorphus committed Aug 29, 2014
1 parent 5aabd66 commit c2e90e2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 132 deletions.
38 changes: 4 additions & 34 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ func GetFileContents(w http.ResponseWriter, r *http.Request) {
if ref == "" {
ref = "master"
}
if path == "" || repo == "" {
err := fmt.Errorf("Error when trying to obtain file %s on ref %s of repository %s (repository and path are required).", path, ref, repo)
if path == "" {
err := fmt.Errorf("Error when trying to obtain an uknown file on ref %s of repository %s (path is required).", ref, repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
Expand All @@ -342,8 +342,8 @@ func GetArchive(w http.ResponseWriter, r *http.Request) {
repo := r.URL.Query().Get(":name")
ref := r.URL.Query().Get("ref")
format := r.URL.Query().Get("format")
if ref == "" || format == "" || repo == "" {
err := fmt.Errorf("Error when trying to obtain archive for ref '%s' (format: %s) of repository '%s' (repository, ref and format are required).", ref, format, repo)
if ref == "" || format == "" {
err := fmt.Errorf("Error when trying to obtain archive for ref '%s' (format: %s) of repository '%s' (ref and format are required).", ref, format, repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
Expand Down Expand Up @@ -384,11 +384,6 @@ func GetTree(w http.ResponseWriter, r *http.Request) {
if path == "" {
path = "."
}
if repo == "" {
err := fmt.Errorf("Error when trying to obtain tree for path %s on ref %s of repository %s (repository is required).", path, ref, repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
tree, err := repository.GetTree(repo, ref, path)
if err != nil {
err := fmt.Errorf("Error when trying to obtain tree for path %s on ref %s of repository %s (%s).", path, ref, repo, err)
Expand All @@ -406,11 +401,6 @@ func GetTree(w http.ResponseWriter, r *http.Request) {

func GetBranches(w http.ResponseWriter, r *http.Request) {
repo := r.URL.Query().Get(":name")
if repo == "" {
err := fmt.Errorf("Error when trying to obtain the branches of repository %s (repository is required).", repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
branches, err := repository.GetBranches(repo)
if err != nil {
err := fmt.Errorf("Error when trying to obtain the branches of repository %s (%s).", repo, err)
Expand All @@ -429,11 +419,6 @@ func GetBranches(w http.ResponseWriter, r *http.Request) {
func GetTags(w http.ResponseWriter, r *http.Request) {
repo := r.URL.Query().Get(":name")
ref := r.URL.Query().Get("ref")
if repo == "" {
err := fmt.Errorf("Error when trying to obtain tags on ref %s of repository %s (repository is required).", ref, repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
tags, err := repository.GetTags(repo)
if err != nil {
err := fmt.Errorf("Error when trying to obtain tags on ref %s of repository %s (%s).", ref, repo, err)
Expand All @@ -453,11 +438,6 @@ func GetDiff(w http.ResponseWriter, r *http.Request) {
repo := r.URL.Query().Get(":name")
previousCommit := r.URL.Query().Get("previous_commit")
lastCommit := r.URL.Query().Get("last_commit")
if repo == "" {
err := fmt.Errorf("Error when trying to obtain diff between hash commits of repository %s (repository is required).", repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if previousCommit == "" || lastCommit == "" {
err := fmt.Errorf("Error when trying to obtain diff between hash commits of repository %s (Hash Commit(s) are required).", repo)
http.Error(w, err.Error(), http.StatusBadRequest)
Expand All @@ -474,11 +454,6 @@ func GetDiff(w http.ResponseWriter, r *http.Request) {

func Commit(w http.ResponseWriter, r *http.Request) {
repo := r.URL.Query().Get(":name")
if repo == "" {
err := fmt.Errorf("Error when trying to commit to repository %s (repository is required).", repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
err := r.ParseMultipartForm(int64(maxMemoryValue()))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
Expand Down Expand Up @@ -535,11 +510,6 @@ func GetLog(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if repo == "" {
err := fmt.Errorf("Error when trying to obtain log for ref %s of repository %s (repository is required).", ref, repo)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
logs, err := repository.GetLog(repo, ref, total, path)
if err != nil {
err := fmt.Errorf("Error when trying to obtain log for ref %s of repository %s (%s).", ref, repo, err)
Expand Down
Loading

0 comments on commit c2e90e2

Please sign in to comment.