Beispiel #1
0
func TestDo(t *testing.T) {
	MockHTTP()
	defer httpmock.DeactivateAndReset()

	err := UseTestDB()
	if err != nil {
		t.Fatal(err)
	}
	u, err := db.CreateUser(&db.UserParams{
		ID:   1,
		Name: "pocke",
		Auth: "",
	})
	if err != nil {
		t.Fatal(err)
	}

	err = Do(u.ID, 1)
	if err != nil {
		t.Error(err)
	}

	if ev := new(db.Event); ev.All().Count() == 0 {
		t.Error("count should not be 0, but got 0")
	}
}
Beispiel #2
0
func Callback(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	code := q.Get("code")
	tok, err := oauthConf.Exchange(oauth2.NoContext, code)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	ghc := github.NewClient(oauthConf.Client(oauth2.NoContext, tok))
	u, _, err := ghc.Users.Get("") // get me
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	_, err = db.CreateUser(&db.UserParams{
		ID:   *u.ID,
		Name: *u.Login,
		Auth: tok.AccessToken,
	})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
Beispiel #3
0
func TestFeedURI(t *testing.T) {
	MockHTTP()
	defer httpmock.DeactivateAndReset()

	err := UseTestDB()
	if err != nil {
		t.Fatal(err)
	}
	u, err := db.CreateUser(&db.UserParams{
		ID:   1,
		Name: "pocke",
		Auth: "",
	})
	if err != nil {
		t.Fatal(err)
	}

	uri, err := feedURI(u.ID)
	if err != nil {
		t.Fatal(err)
	}

	e := "https://github.com/pocke.private?token=abc123"
	if uri != e {
		t.Errorf("Expected: %s, but got %s", e, uri)
	}
}