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

Unified Diff: milo/appengine/buildbot/grpc_test.go

Issue 2856273004: Milo: Increase test coverage for appengine/buildbot (Closed)
Patch Set: review Created 3 years, 7 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: milo/appengine/buildbot/grpc_test.go
diff --git a/milo/appengine/buildbot/grpc_test.go b/milo/appengine/buildbot/grpc_test.go
index e2e6dd52ce0520680c6cc5f5b07007063455fc21..7035068ef1eab39e9e71acc15f66bc000d85b3e3 100644
--- a/milo/appengine/buildbot/grpc_test.go
+++ b/milo/appengine/buildbot/grpc_test.go
@@ -7,6 +7,9 @@ package buildbot
import (
"testing"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+
"github.com/luci/gae/impl/memory"
ds "github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/common/clock/testclock"
@@ -20,13 +23,29 @@ func TestGRPC(t *testing.T) {
c, _ = testclock.UseTime(c, testclock.TestTimeUTC)
Convey(`A test environment`, t, func() {
- // Add in a public master to satisfy acl.
name := "testmaster"
bname := "testbuilder"
- me := &buildbotMasterEntry{Name: name, Internal: false}
- ds.Put(c, me)
+ master := &buildbotMaster{
+ Name: name,
+ Builders: map[string]*buildbotBuilder{"fake": {}},
+ Slaves: map[string]*buildbotSlave{
+ "foo": {
+ RunningbuildsMap: map[string][]int{
+ "fake": {1},
+ },
+ },
+ },
+ }
+
+ So(putDSMasterJSON(c, master, false), ShouldBeNil)
+ So(ds.Put(c, &buildbotBuild{
+ Master: name,
+ Buildername: "fake",
+ Number: 1,
+ }), ShouldBeNil)
ds.GetTestable(c).Consistent(true)
ds.GetTestable(c).AutoIndex(true)
+ svc := Service{}
Convey(`Get finished builds`, func() {
// Add in some builds.
@@ -46,7 +65,6 @@ func TestGRPC(t *testing.T) {
})
ds.GetTestable(c).CatchupIndexes()
- svc := Service{}
r := &milo.BuildbotBuildsRequest{
Master: name,
Builder: bname,
@@ -65,6 +83,61 @@ func TestGRPC(t *testing.T) {
So(err, ShouldBeNil)
So(len(result.Builds), ShouldEqual, 6)
})
+
+ Convey(`Good cursor`, func() {
+ r.Cursor = result.GetCursor()
+ _, err := svc.GetBuildbotBuildsJSON(c, r)
+ So(err, ShouldBeNil)
+ })
+ Convey(`Bad cursor`, func() {
+ r.Cursor = "foobar"
+ _, err := svc.GetBuildbotBuildsJSON(c, r)
+ So(err, ShouldResemble,
+ grpc.Errorf(codes.InvalidArgument,
+ "Invalid cursor: Failed to Base64-decode cursor: illegal base64 data at input byte 4"))
+ })
+ Convey(`Bad request`, func() {
+ _, err := svc.GetBuildbotBuildsJSON(c, &milo.BuildbotBuildsRequest{})
+ So(err, ShouldResemble, grpc.Errorf(codes.InvalidArgument, "No master specified"))
+ _, err = svc.GetBuildbotBuildsJSON(c, &milo.BuildbotBuildsRequest{Master: name})
+ So(err, ShouldResemble, grpc.Errorf(codes.InvalidArgument, "No builder specified"))
+ })
+ })
+
+ Convey(`Get Master`, func() {
+ Convey(`Bad request`, func() {
+ _, err := svc.GetCompressedMasterJSON(c, &milo.MasterRequest{})
+ So(err, ShouldResemble, grpc.Errorf(codes.InvalidArgument, "No master specified"))
+ })
+ _, err := svc.GetCompressedMasterJSON(c, &milo.MasterRequest{Name: name})
+ So(err, ShouldBeNil)
+ })
+
+ Convey(`Get Build`, func() {
+ Convey(`Invalid input`, func() {
+ _, err := svc.GetBuildbotBuildJSON(c, &milo.BuildbotBuildRequest{})
+ So(err, ShouldResemble, grpc.Errorf(codes.InvalidArgument, "No master specified"))
+ _, err = svc.GetBuildbotBuildJSON(c, &milo.BuildbotBuildRequest{
+ Master: "foo",
+ })
+ So(err, ShouldResemble, grpc.Errorf(codes.InvalidArgument, "No builder specified"))
+ })
+ Convey(`Basic`, func() {
+ _, err := svc.GetBuildbotBuildJSON(c, &milo.BuildbotBuildRequest{
+ Master: name,
+ Builder: "fake",
+ BuildNum: 1,
+ })
+ So(err, ShouldBeNil)
+ })
+ Convey(`Basic Not found`, func() {
+ _, err := svc.GetBuildbotBuildJSON(c, &milo.BuildbotBuildRequest{
+ Master: name,
+ Builder: "fake",
+ BuildNum: 2,
+ })
+ So(err, ShouldResemble, grpc.Errorf(codes.Unauthenticated, "Unauthenticated request"))
+ })
})
})
}
« no previous file with comments | « milo/appengine/buildbot/expectations/chromium_presubmit.426944.build.json ('k') | milo/appengine/buildbot/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698