Skip to content

Commit

Permalink
fixed default test
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Jun 12, 2018
1 parent 2d5ae07 commit 92a7681
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import (
. "github.com/smartystreets/goconvey/convey"
)

func TestDefaultStart(t *testing.T) {
cookieName := "test_default_start"
var defaultCookieName = "test_default_start"

func init() {
InitManager(
SetCookieName(cookieName),
SetCookieName(defaultCookieName),
)
}

func TestDefaultStart(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
store, err := Start(nil, w, r)
if err != nil {
Expand Down Expand Up @@ -46,7 +49,7 @@ func TestDefaultStart(t *testing.T) {
So(len(res.Cookies()), ShouldBeGreaterThan, 0)

cookie := res.Cookies()[0]
So(cookie.Name, ShouldEqual, cookieName)
So(cookie.Name, ShouldEqual, defaultCookieName)

req, err := http.NewRequest("GET", fmt.Sprintf("%s?login=1", ts.URL), nil)
So(err, ShouldBeNil)
Expand All @@ -64,12 +67,6 @@ func TestDefaultStart(t *testing.T) {
}

func TestDefaultDestroy(t *testing.T) {
cookieName := "test_default_destroy"

InitManager(
SetCookieName(cookieName),
)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("logout") == "1" {
err := Destroy(nil, w, r)
Expand Down Expand Up @@ -110,7 +107,7 @@ func TestDefaultDestroy(t *testing.T) {
So(len(res.Cookies()), ShouldBeGreaterThan, 0)

cookie := res.Cookies()[0]
So(cookie.Name, ShouldEqual, cookieName)
So(cookie.Name, ShouldEqual, defaultCookieName)

req, err := http.NewRequest("GET", fmt.Sprintf("%s?logout=1", ts.URL), nil)
So(err, ShouldBeNil)
Expand All @@ -135,12 +132,6 @@ func TestDefaultDestroy(t *testing.T) {
}

func TestDefaultRefresh(t *testing.T) {
cookieName := "test_default_refresh"

InitManager(
SetCookieName(cookieName),
)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
store, err := Start(nil, w, r)
if err != nil {
Expand Down Expand Up @@ -182,7 +173,7 @@ func TestDefaultRefresh(t *testing.T) {
So(len(res.Cookies()), ShouldBeGreaterThan, 0)

cookie := res.Cookies()[0]
So(cookie.Name, ShouldEqual, cookieName)
So(cookie.Name, ShouldEqual, defaultCookieName)

req, err := http.NewRequest("GET", fmt.Sprintf("%s?refresh=1", ts.URL), nil)
So(err, ShouldBeNil)
Expand Down

0 comments on commit 92a7681

Please sign in to comment.