示例#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")
	}
}
示例#2
0
文件: oauth.go 项目: pocke/gh-feeds
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
	}
}
示例#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)
	}
}