From eb9a301a9ecbdf44c73d96593a57a30604eb760d Mon Sep 17 00:00:00 2001 From: Eoin McAfee Date: Fri, 21 May 2021 13:31:06 +0100 Subject: [PATCH] deleted all.go - not required & fixed issue where template if none found return null instead of empty list. --- handler/api/api.go | 1 - handler/api/template/all.go | 26 -------------------------- handler/api/template/all_test.go | 31 ------------------------------- store/template/scan.go | 2 +- 4 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 handler/api/template/all.go delete mode 100644 handler/api/template/all_test.go diff --git a/handler/api/api.go b/handler/api/api.go index 8037158f..cb4588a1 100644 --- a/handler/api/api.go +++ b/handler/api/api.go @@ -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)) diff --git a/handler/api/template/all.go b/handler/api/template/all.go deleted file mode 100644 index f58370ab..00000000 --- a/handler/api/template/all.go +++ /dev/null @@ -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) - } -} diff --git a/handler/api/template/all_test.go b/handler/api/template/all_test.go deleted file mode 100644 index 0bfb9ee1..00000000 --- a/handler/api/template/all_test.go +++ /dev/null @@ -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) - } -} diff --git a/store/template/scan.go b/store/template/scan.go index 24846774..76a3f559 100644 --- a/store/template/scan.go +++ b/store/template/scan.go @@ -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)