Browse Source

Fixed unit tests 1/2

dependabot/npm_and_yarn/web/prismjs-1.21.0
Schmitt, Max 8 years ago
parent
commit
c4dd39aae2
  1. 3
      handlers/handlers.go
  2. 4
      handlers/handlers_test.go
  3. 2
      store/store_test.go

3
handlers/handlers.go

@ -23,6 +23,7 @@ type Handler struct {
store store.Store
engine *gin.Engine
oAuthConf *oauth2.Config
DoNotCheckConfigViaGet bool // DoNotCheckConfigViaGet is for the unit testing usage
}
// New initializes the http handlers
@ -56,6 +57,7 @@ func (h *Handler) setTemplateFromFS(name string) error {
}
func (h *Handler) checkIfSecretExist() error {
if h.DoNotCheckConfigViaGet {
conf := config.Get()
if conf.Handlers.Secret == nil {
b := make([]byte, 128)
@ -67,6 +69,7 @@ func (h *Handler) checkIfSecretExist() error {
return err
}
}
}
return nil
}

4
handlers/handlers_test.go

@ -244,13 +244,13 @@ func getBackend() (func(), error) {
}
handler, err := New(config.Handlers{
ListenAddr: ":8080",
Secret: []byte(""),
Secret: []byte("our really great secret"),
BaseURL: "http://127.0.0.1",
}, *store)
if err != nil {
return nil, errors.Wrap(err, "could not create handler")
}
handler.DoNotCheckConfigViaGet = true
server = httptest.NewServer(handler.engine)
return func() {
server.Close()

2
store/store_test.go

@ -20,7 +20,7 @@ var validConfig = config.Store{
func TestGenerateRandomString(t *testing.T) {
tt := []struct {
name string
length int
length uint
}{
{"fourtytwo long", 42},
{"sixteen long", 16},

Loading…
Cancel
Save