-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving sessions test into a seperate file
- Loading branch information
1 parent
b010a27
commit ad0be06
Showing
3 changed files
with
44 additions
and
44 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package mango | ||
|
||
import ( | ||
"http" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func sessionsTestServer(env Env) (Status, Headers, Body) { | ||
env.Session()["test_attribute"] = "Never gonna give you up" | ||
return 200, Headers{}, Body("Hello World!") | ||
} | ||
|
||
func init() { | ||
runtime.GOMAXPROCS(4) | ||
} | ||
|
||
func TestSessions(t *testing.T) { | ||
// Compile the stack | ||
sessionsStack := new(Stack) | ||
sessionsStack.Middleware(Sessions("my_secret", "my_key", ".my.domain.com")) | ||
sessionsApp := sessionsStack.Compile(sessionsTestServer) | ||
|
||
// Request against it | ||
request, err := http.NewRequest("GET", "http://localhost:3000/", nil) | ||
status, headers, _ := sessionsApp(Env{"mango.request": &Request{request}}) | ||
|
||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if status != 200 { | ||
t.Error("Expected status to equal 200, got:", status) | ||
} | ||
|
||
// base 64 encoded, hmac-hashed, and gob encoded stuff | ||
cookie := headers.Get("Set-Cookie") | ||
expected_cookie := "my_key=Dv+BBAEC/4IAAQwBEAAANf+CAAEOdGVzdF9hdHRyaWJ1dGUGc3RyaW5nDBkAF05ldmVyIGdvbm5hIGdpdmUgeW91IHVw--bdHyJ5lvPpk6EoZiSSSiHKZtQHk=; Domain=.my.domain.com;" | ||
if cookie != expected_cookie { | ||
t.Error("Expected Set-Cookie to equal: \"", expected_cookie, "\" got: \"", cookie, "\"") | ||
} | ||
} |