deleted all.go - not required & fixed issue where template if none found return null instead of empty list.

This commit is contained in:
Eoin McAfee 2021-05-21 13:31:06 +01:00
parent b63facdc62
commit eb9a301a9e
4 changed files with 1 additions and 59 deletions

View file

@ -358,7 +358,6 @@ func (s Server) Handler() http.Handler {
})
r.Route("/templates", func(r chi.Router) {
r.With(acl.AuthorizeAdmin).Get("/", template.HandleAll(s.Template))
r.With(acl.CheckMembership(s.Orgs, false)).Get("/", template.HandleList(s.Template))
r.With(acl.CheckMembership(s.Orgs, true)).Post("/", template.HandleCreate(s.Template))
r.With(acl.CheckMembership(s.Orgs, false)).Get("/{name}", template.HandleFind(s.Template))

View file

@ -1,26 +0,0 @@
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package template
import (
"github.com/drone/drone/core"
"github.com/drone/drone/handler/api/render"
"net/http"
)
// HandleAll returns an http.HandlerFunc that writes a json-encoded
// list of secrets to the response body.
func HandleAll(templates core.TemplateStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
list, err := templates.ListAll(r.Context())
if err != nil {
render.NotFound(w, err)
return
}
render.JSON(w, list, 200)
}
}

View file

@ -1,31 +0,0 @@
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package template
import (
"github.com/drone/drone/mock"
"github.com/golang/mock/gomock"
"net/http"
"net/http/httptest"
"testing"
)
func TestHandleAll(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()
templates := mock.NewMockTemplateStore(controller)
templates.EXPECT().ListAll(gomock.Any()).Return(dummyTemplateList, nil)
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/", nil)
HandleAll(templates).ServeHTTP(w, r)
if got, want := w.Code, http.StatusOK; want != got {
t.Errorf("Want response code %d, got %d", want, got)
}
}

View file

@ -45,7 +45,7 @@ func scanRow(scanner db.Scanner, dst *core.Template) error {
func scanRows(rows *sql.Rows) ([]*core.Template, error) {
defer rows.Close()
var template []*core.Template
template := []*core.Template{}
for rows.Next() {
tem := new(core.Template)
err := scanRow(rows, tem)