33 lines
608 B
Go
33 lines
608 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
)
|
|
|
|
func TestReadIDParam(t *testing.T) {
|
|
app := newTestApplication(t)
|
|
|
|
const test_id int64 = 3
|
|
|
|
r := httptest.NewRequest(http.MethodGet, "/v1/issues/" + strconv.FormatInt(test_id, 10), nil)
|
|
|
|
params := httprouter.Params{{Key: "id", Value: "3"}}
|
|
ctx := context.WithValue(r.Context(), httprouter.ParamsKey, params)
|
|
r = r.WithContext(ctx)
|
|
|
|
id, err := app.readIDParam(r)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if id != test_id {
|
|
t.Errorf("want %d, got id %d", test_id, id)
|
|
}
|
|
}
|