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
// GetReposHandler returns a list of (public) repositories for a given GitHub user | |
func (a *App) GetReposHandler(w http.ResponseWriter, r *http.Request) { | |
user := r.FormValue("user") | |
if user == "" { | |
http.Error(w, "MISSING_ARG_USER", 400) | |
return | |
} | |
repos, err := a.repos.Get(user) | |
if err != nil { |
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
type App struct { | |
repos repos.Client | |
} |
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
type Client interface { | |
Get(string) ([]Repo, error) | |
} | |
type ReposClient struct{} | |
func (c ReposClient) Get(user string) ([]Repo, error) { | |
// call github api | |
} |
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
type ReposTestClient struct { | |
Repos []repos.Repo | |
Err error | |
} | |
func (c ReposTestClient) Get(string) ([]repos.Repo, error) { | |
return c.Repos, c.Err | |
} |
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
func TestGetReposHandler(t *testing.T) { | |
assert := assert.New(t) | |
tests := []struct { | |
description string | |
reposClient *ReposTestClient | |
url string | |
expectedStatusCode int | |
expectedBody string | |
}{ |
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
var c = ReposClient{} | |
func TestGet(t *testing.T) { | |
assert := assert.New(t) | |
httpmock.Activate() | |
defer httpmock.DeactivateAndReset() | |
tests := []struct { | |
description string |
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
package main | |
import ( | |
"log" | |
"net/http" | |
"github.com/gorilla/context" | |
) | |
var ( |
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
// GetTestHandler returns a http.HandlerFunc for testing http middleware | |
func GetTestHandler() http.HandlerFunc { | |
fn := func(rw http.ResponseWriter, req *http.Request) { | |
panic("test entered test handler, this should not happen") | |
} | |
return http.HandlerFunc(fn) | |
} |
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
func TestAuth(t *testing.T) { | |
assert := assert.New(t) | |
tests := []struct { | |
description string | |
url string | |
expectedBody string | |
expectedCode int | |
}{ | |
{ |
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
package main | |
import ( | |
"context" | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"os/signal" |
OlderNewer