aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--internal/webui/login.go4
-rw-r--r--internal/webui/utils.go4
-rw-r--r--internal/webui/utils_test.go23
-rw-r--r--internal/webui/webui.go2
6 files changed, 21 insertions, 18 deletions
diff --git a/go.mod b/go.mod
index 1234cf2..14cae33 100644
--- a/go.mod
+++ b/go.mod
@@ -9,7 +9,7 @@ require (
github.com/kr/pretty v0.2.1 // indirect
github.com/mattn/go-sqlite3 v1.14.8
github.com/stretchr/testify v1.7.0
- golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
+ golang.org/x/crypto v0.0.0-20210915214749-c084706c2272
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
diff --git a/go.sum b/go.sum
index 44b88ed..fb92645 100644
--- a/go.sum
+++ b/go.sum
@@ -17,8 +17,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
-golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 h1:3erb+vDS8lU1sxfDHF4/hhWyaXnhIaO+7RgL4fDZORA=
+golang.org/x/crypto v0.0.0-20210915214749-c084706c2272/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
diff --git a/internal/webui/login.go b/internal/webui/login.go
index 706cd29..84d477f 100644
--- a/internal/webui/login.go
+++ b/internal/webui/login.go
@@ -57,10 +57,10 @@ func loginHandler(e *env, w http.ResponseWriter, r *http.Request) error {
user, err := e.dbEnv.Login(&model.UserLogin{Username: username[0], Password: password[0]})
if err != nil {
switch e := err.(type) {
- case *database.PasswordError:
+ case database.PasswordError:
// TODO : handle in page
return e
- case *database.QueryError:
+ case database.QueryError:
return e
default:
return e
diff --git a/internal/webui/utils.go b/internal/webui/utils.go
index 28a7add..5bc1e04 100644
--- a/internal/webui/utils.go
+++ b/internal/webui/utils.go
@@ -41,8 +41,8 @@ type statusError struct {
err error
}
-func (e *statusError) Error() string { return e.err.Error() }
-func (e *statusError) Status() int { return e.code }
+func (e statusError) Error() string { return e.err.Error() }
+func (e statusError) Status() int { return e.code }
func newStatusError(code int, err error) error { return &statusError{code: code, err: err} }
type handler struct {
diff --git a/internal/webui/utils_test.go b/internal/webui/utils_test.go
index bd24dd5..6de1aad 100644
--- a/internal/webui/utils_test.go
+++ b/internal/webui/utils_test.go
@@ -10,10 +10,13 @@ import (
"testing"
"git.adyxax.org/adyxax/trains/pkg/model"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
+func requireErrorTypeMatch(t *testing.T, err error, expected error) {
+ require.Equalf(t, reflect.TypeOf(err), reflect.TypeOf(expected), "Invalid error type. Got %s but expected %s", reflect.TypeOf(err), reflect.TypeOf(expected))
+}
+
type NavitiaMockClient struct {
departures []model.Departure
stops []model.Stop
@@ -46,7 +49,7 @@ type httpTestExpect struct {
bodyString string
location string
setsCookie bool
- err interface{}
+ err error
}
func runHttpTest(t *testing.T, e *env, h func(e *env, w http.ResponseWriter, r *http.Request) error, tc *httpTestCase) {
@@ -64,22 +67,22 @@ func runHttpTest(t *testing.T, e *env, h func(e *env, w http.ResponseWriter, r *
err := h(e, rr, req)
if tc.expect.err != nil {
require.Error(t, err)
- assert.Equalf(t, reflect.TypeOf(err), reflect.TypeOf(tc.expect.err), "Invalid error type. Got %s but expected %s", reflect.TypeOf(err), reflect.TypeOf(tc.expect.err))
+ requireErrorTypeMatch(t, err, tc.expect.err)
} else {
require.NoError(t, err)
- assert.Equal(t, tc.expect.code, rr.Code)
+ require.Equal(t, tc.expect.code, rr.Code)
if tc.expect.bodyString != "" {
- assert.Contains(t, rr.Body.String(), tc.expect.bodyString)
+ require.Contains(t, rr.Body.String(), tc.expect.bodyString)
}
if tc.expect.location != "" {
- assert.Contains(t, rr.HeaderMap, "Location")
- assert.Len(t, rr.HeaderMap["Location"], 1)
- assert.Equal(t, rr.HeaderMap["Location"][0], tc.expect.location)
+ require.Contains(t, rr.HeaderMap, "Location")
+ require.Len(t, rr.HeaderMap["Location"], 1)
+ require.Equal(t, rr.HeaderMap["Location"][0], tc.expect.location)
}
if tc.expect.setsCookie {
- assert.Contains(t, rr.HeaderMap, "Set-Cookie")
+ require.Contains(t, rr.HeaderMap, "Set-Cookie")
} else {
- assert.NotContains(t, rr.HeaderMap, "Set-Cookie")
+ require.NotContains(t, rr.HeaderMap, "Set-Cookie")
}
}
})
diff --git a/internal/webui/webui.go b/internal/webui/webui.go
index 63173c6..8685df5 100644
--- a/internal/webui/webui.go
+++ b/internal/webui/webui.go
@@ -26,7 +26,7 @@ func Run(c *config.Config, dbEnv *database.DBEnv) {
if stops, err := e.navitia.GetStops(); err == nil {
log.Printf("Updated trains stops data from navitia api, got %d results", len(stops))
if err = dbEnv.ReplaceAndImportStops(stops); err != nil {
- if dberr, ok := err.(*database.QueryError); ok {
+ if dberr, ok := err.(database.QueryError); ok {
log.Printf("%+v", dberr.Unwrap())
}
}