Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Unified Diff: logdog/appengine/coordinator/endpoints/logs/list_test.go

Issue 2991253004: [logdog] Remove list functionality. (Closed)
Patch Set: fix test Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: logdog/appengine/coordinator/endpoints/logs/list_test.go
diff --git a/logdog/appengine/coordinator/endpoints/logs/list_test.go b/logdog/appengine/coordinator/endpoints/logs/list_test.go
deleted file mode 100644
index 3e380816230369c93997f9bbb36d3d5d84f8b011..0000000000000000000000000000000000000000
--- a/logdog/appengine/coordinator/endpoints/logs/list_test.go
+++ /dev/null
@@ -1,220 +0,0 @@
-// Copyright 2015 The LUCI Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package logs
-
-import (
- "fmt"
- "testing"
-
- ds "github.com/luci/gae/service/datastore"
- "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1"
- ct "github.com/luci/luci-go/logdog/appengine/coordinator/coordinatorTest"
- "github.com/luci/luci-go/logdog/appengine/coordinator/hierarchy"
- "github.com/luci/luci-go/logdog/common/types"
- "github.com/luci/luci-go/luci_config/common/cfgtypes"
- "golang.org/x/net/context"
-
- . "github.com/luci/luci-go/common/testing/assertions"
- . "github.com/smartystreets/goconvey/convey"
-)
-
-func listPaths(l *logdog.ListResponse) []string {
- s := make([]string, len(l.Components))
- for i, c := range l.Components {
- s[i] = c.Name
-
- var suffix string
- switch c.Type {
- case logdog.ListResponse_Component_STREAM:
- s[i] += "$"
- case logdog.ListResponse_Component_PATH:
- suffix = "/"
- case logdog.ListResponse_Component_PROJECT:
- suffix = "#"
- }
- s[i] += suffix
- }
- return s
-}
-
-func TestList(t *testing.T) {
- t.Parallel()
-
- Convey(`With a testing configuration, a List request`, t, func() {
- c, env := ct.Install()
-
- svc := New()
-
- const project = cfgtypes.ProjectName("proj-foo")
-
- // Install a set of stock log streams to query against.
- for i, v := range []types.StreamPath{
- "blargh/+/foo",
- "other/+/foo/bar",
- "other/+/baz",
- "testing/+/foo",
- "testing/+/foo/bar",
- } {
- tls := ct.MakeStream(c, project, v)
-
- ct.WithProjectNamespace(c, project, func(c context.Context) {
- if err := tls.Put(c); err != nil {
- panic(fmt.Errorf("failed to put log stream %d: %v", i, err))
- }
-
- for _, comp := range hierarchy.Components(tls.Path, true) {
- if err := comp.Put(c); err != nil {
- panic(fmt.Errorf("failed to put log component %d: %v", i, err))
- }
- }
- })
- }
- ds.GetTestable(c).CatchupIndexes()
-
- var req logdog.ListRequest
-
- Convey(`A project-level list request`, func() {
- req.Project = ""
-
- Convey(`Empty list request will return projects.`, func() {
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- So(listPaths(l), ShouldResemble, []string{"proj-bar#", "proj-foo#"})
- })
-
- Convey(`Empty list request can skip projects.`, func() {
- req.Offset = 1
-
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- So(listPaths(l), ShouldResemble, []string{"proj-foo#"})
- })
-
- Convey(`When authenticated, empty list includes authenticated project.`, func() {
- env.JoinGroup("auth")
-
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- So(listPaths(l), ShouldResemble, []string{"proj-bar#", "proj-exclusive#", "proj-foo#"})
- })
- })
-
- Convey(`A project-bound list request`, func() {
- req.Project = string(project)
-
- Convey(`Can list within a project, when the project is empty.`, func() {
- req.PathBase = "proj-bar"
-
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- So(listPaths(l), ShouldResemble, []string{})
- })
-
- Convey(`Empty list request will return top-level stream paths.`, func() {
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- So(listPaths(l), ShouldResemble, []string{"blargh/", "other/", "testing/"})
- })
-
- Convey(`Will skip elements if requested.`, func() {
- req.Offset = 2
-
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- So(listPaths(l), ShouldResemble, []string{"testing/"})
- })
-
- Convey(`Can list within a populated project.`, func() {
- req.Project = "proj-foo"
-
- list := func(b string) []string {
- req.PathBase = b
-
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- return listPaths(l)
- }
-
- So(list(""), ShouldResemble, []string{"blargh/", "other/", "testing/"})
- So(list("blargh"), ShouldResemble, []string{"+/"})
- So(list("blargh/+"), ShouldResemble, []string{"foo$"})
- So(list("other"), ShouldResemble, []string{"+/"})
- So(list("other/+"), ShouldResemble, []string{"baz$", "foo/"})
- So(list("other/+/baz"), ShouldResemble, []string{})
- So(list("other/+/foo"), ShouldResemble, []string{"bar$"})
- So(list("testing"), ShouldResemble, []string{"+/"})
- So(list("testing/+"), ShouldResemble, []string{"foo$", "foo/"})
- So(list("testing/+/foo"), ShouldResemble, []string{"bar$"})
- })
-
- Convey(`Can use a cursor to fully enumerate a space.`, func() {
- req.MaxResults = 1
-
- all := []string{"blargh/", "other/", "testing/"}
- for len(all) > 0 {
- l, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- So(listPaths(l), ShouldResemble, all[:1])
-
- all = all[1:]
- req.Next = l.Next
- }
- })
- })
-
- Convey(`If the user is logged in`, func() {
- env.LogIn()
-
- Convey(`When accessing a restricted project`, func() {
- req.Project = "proj-exclusive"
-
- Convey(`Will succeed if the user can access the project.`, func() {
- env.JoinGroup("auth")
-
- _, err := svc.List(c, &req)
- So(err, ShouldBeRPCOK)
- })
-
- Convey(`If the user can't access the project, will return PermissionDenied.`, func() {
- req.Project = "proj-exclusive"
-
- _, err := svc.List(c, &req)
- So(err, ShouldBeRPCPermissionDenied)
- })
- })
-
- Convey(`If the project does not exist, will return PermissionDenied.`, func() {
- req.Project = "does-not-exist"
-
- _, err := svc.List(c, &req)
- So(err, ShouldBeRPCPermissionDenied)
- })
- })
-
- Convey(`If the project does not exist, will return Unauthenticated.`, func() {
- req.Project = "does-not-exist"
-
- _, err := svc.List(c, &req)
- So(err, ShouldBeRPCUnauthenticated)
- })
-
- Convey(`If the user can't access the project, will return Unauthenticated.`, func() {
- req.Project = "proj-exclusive"
-
- _, err := svc.List(c, &req)
- So(err, ShouldBeRPCUnauthenticated)
- })
- })
-}

Powered by Google App Engine
This is Rietveld 408576698