-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens_test.go
59 lines (39 loc) · 1.11 KB
/
tokens_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
// "fmt"
"bytes"
"net/http"
"net/http/httptest"
"database/sql"
_ "github.com/erikstmartin/go-testdb"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreateTokenAndVerifySuccessful(t *testing.T) {
assert := assert.New(t)
db, _ := sql.Open("testdb", "")
router := createRouter(db, []byte("public_key"), []byte("private_key"))
req, _ := http.NewRequest("POST", "/token/", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if !assert.Equal(200, w.Code) {
return
}
token := w.Body.Bytes()
req, _ = http.NewRequest("POST", "/token/verify", bytes.NewBuffer(token))
w = httptest.NewRecorder()
assert.Equal(200, w.Code)
}
func TestCreateTokenShouldGiveError(t *testing.T) {
}
func TestVerifyTokenShouldReturn400(t *testing.T) {
// assert := assert.New(t)
// db, _ := sql.Open("testdb", "")
// router := createRouter(db, "public_key", "private_key")
// req, _ := http.NewRequest("POST", "/token/verify", nil)
// w := httptest.NewRecorder()
// router.ServeHTTP(w, req)
// assert.Equal(400, w.Code)
}
func TestVerifyTokenShouldReturn200(t *testing.T) {
}