Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package buildbot | 5 package buildbot |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "google.golang.org/grpc" | |
| 11 "google.golang.org/grpc/codes" | |
| 12 | |
| 10 "github.com/luci/gae/impl/memory" | 13 "github.com/luci/gae/impl/memory" |
| 11 ds "github.com/luci/gae/service/datastore" | 14 ds "github.com/luci/gae/service/datastore" |
| 12 "github.com/luci/luci-go/common/clock/testclock" | 15 "github.com/luci/luci-go/common/clock/testclock" |
| 13 milo "github.com/luci/luci-go/milo/api/proto" | 16 milo "github.com/luci/luci-go/milo/api/proto" |
| 14 . "github.com/smartystreets/goconvey/convey" | 17 . "github.com/smartystreets/goconvey/convey" |
| 15 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
| 16 ) | 19 ) |
| 17 | 20 |
| 18 func TestGRPC(t *testing.T) { | 21 func TestGRPC(t *testing.T) { |
| 19 c := memory.Use(context.Background()) | 22 c := memory.Use(context.Background()) |
| 20 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) | 23 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) |
| 21 | 24 |
| 22 Convey(`A test environment`, t, func() { | 25 Convey(`A test environment`, t, func() { |
| 23 // Add in a public master to satisfy acl. | |
| 24 name := "testmaster" | 26 name := "testmaster" |
| 25 bname := "testbuilder" | 27 bname := "testbuilder" |
| 26 » » me := &buildbotMasterEntry{Name: name, Internal: false} | 28 » » master := &buildbotMaster{ |
| 27 » » ds.Put(c, me) | 29 » » » Name: name, |
| 30 » » » Builders: map[string]*buildbotBuilder{"fake": {}}, | |
| 31 » » » Slaves: map[string]*buildbotSlave{ | |
| 32 » » » » "foo": { | |
| 33 » » » » » RunningbuildsMap: map[string][]int{ | |
| 34 » » » » » » "fake": {1}, | |
| 35 » » » » » }, | |
| 36 » » » » }, | |
| 37 » » » }, | |
| 38 » » } | |
| 39 | |
| 40 » » So(putDSMasterJSON(c, master, false), ShouldBeNil) | |
| 41 » » So(ds.Put(c, &buildbotBuild{ | |
| 42 » » » Master: name, | |
| 43 » » » Buildername: "fake", | |
| 44 » » » Number: 1, | |
| 45 » » }), ShouldBeNil) | |
| 28 ds.GetTestable(c).Consistent(true) | 46 ds.GetTestable(c).Consistent(true) |
| 29 ds.GetTestable(c).AutoIndex(true) | 47 ds.GetTestable(c).AutoIndex(true) |
| 48 svc := Service{} | |
| 30 | 49 |
| 31 Convey(`Get finished builds`, func() { | 50 Convey(`Get finished builds`, func() { |
| 32 // Add in some builds. | 51 // Add in some builds. |
| 33 for i := 0; i < 5; i++ { | 52 for i := 0; i < 5; i++ { |
| 34 ds.Put(c, &buildbotBuild{ | 53 ds.Put(c, &buildbotBuild{ |
| 35 Master: name, | 54 Master: name, |
| 36 Buildername: bname, | 55 Buildername: bname, |
| 37 Number: i, | 56 Number: i, |
| 38 Finished: true, | 57 Finished: true, |
| 39 }) | 58 }) |
| 40 } | 59 } |
| 41 ds.Put(c, &buildbotBuild{ | 60 ds.Put(c, &buildbotBuild{ |
| 42 Master: name, | 61 Master: name, |
| 43 Buildername: bname, | 62 Buildername: bname, |
| 44 Number: 6, | 63 Number: 6, |
| 45 Finished: false, | 64 Finished: false, |
| 46 }) | 65 }) |
| 47 ds.GetTestable(c).CatchupIndexes() | 66 ds.GetTestable(c).CatchupIndexes() |
| 48 | 67 |
| 49 svc := Service{} | |
| 50 r := &milo.BuildbotBuildsRequest{ | 68 r := &milo.BuildbotBuildsRequest{ |
| 51 Master: name, | 69 Master: name, |
| 52 Builder: bname, | 70 Builder: bname, |
| 53 } | 71 } |
| 54 result, err := svc.GetBuildbotBuildsJSON(c, r) | 72 result, err := svc.GetBuildbotBuildsJSON(c, r) |
| 55 So(err, ShouldBeNil) | 73 So(err, ShouldBeNil) |
| 56 So(len(result.Builds), ShouldEqual, 5) | 74 So(len(result.Builds), ShouldEqual, 5) |
| 57 | 75 |
| 58 Convey(`Also get incomplete builds`, func() { | 76 Convey(`Also get incomplete builds`, func() { |
| 59 r := &milo.BuildbotBuildsRequest{ | 77 r := &milo.BuildbotBuildsRequest{ |
| 60 Master: name, | 78 Master: name, |
| 61 Builder: bname, | 79 Builder: bname, |
| 62 IncludeCurrent: true, | 80 IncludeCurrent: true, |
| 63 } | 81 } |
| 64 result, err := svc.GetBuildbotBuildsJSON(c, r) | 82 result, err := svc.GetBuildbotBuildsJSON(c, r) |
| 65 So(err, ShouldBeNil) | 83 So(err, ShouldBeNil) |
| 66 So(len(result.Builds), ShouldEqual, 6) | 84 So(len(result.Builds), ShouldEqual, 6) |
| 67 }) | 85 }) |
| 86 | |
| 87 Convey(`Good cursor`, func() { | |
| 88 r.Cursor = result.GetCursor() | |
| 89 _, err := svc.GetBuildbotBuildsJSON(c, r) | |
| 90 So(err, ShouldBeNil) | |
| 91 }) | |
| 92 Convey(`Bad cursor`, func() { | |
| 93 r.Cursor = "foobar" | |
| 94 _, err := svc.GetBuildbotBuildsJSON(c, r) | |
| 95 So(err, ShouldResemble, | |
| 96 grpc.Errorf(codes.InvalidArgument, | |
| 97 "Invalid cursor: Failed to Base6 4-decode cursor: illegal base64 data at input byte 4")) | |
| 98 }) | |
| 99 Convey(`Bad request`, func() { | |
| 100 _, err := svc.GetBuildbotBuildsJSON(c, &milo.Bui ldbotBuildsRequest{}) | |
| 101 So(err, ShouldResemble, grpc.Errorf(codes.Invali dArgument, "No master specified")) | |
| 102 _, err = svc.GetBuildbotBuildsJSON(c, &milo.Buil dbotBuildsRequest{Master: name}) | |
| 103 So(err, ShouldResemble, grpc.Errorf(codes.Invali dArgument, "No builder specified")) | |
| 104 }) | |
| 105 }) | |
| 106 | |
| 107 Convey(`Get Master`, func() { | |
| 108 Convey(`Bad request`, func() { | |
| 109 _, err := svc.GetCompressedMasterJSON(c, &milo.M asterRequest{}) | |
| 110 So(err, ShouldResemble, grpc.Errorf(codes.Invali dArgument, "No master specified")) | |
| 111 }) | |
| 112 _, err := svc.GetCompressedMasterJSON(c, &milo.MasterReq uest{Name: name}) | |
| 113 So(err, ShouldBeNil) | |
| 114 }) | |
| 115 | |
| 116 Convey(`Get Build`, func() { | |
| 117 Convey(`Invalid input`, func() { | |
| 118 _, err := svc.GetBuildbotBuildJSON(c, &milo.Buil dbotBuildRequest{}) | |
| 119 So(err, ShouldResemble, grpc.Errorf(codes.Invali dArgument, "No master specified")) | |
| 120 _, err = svc.GetBuildbotBuildJSON(c, &milo.Build botBuildRequest{ | |
| 121 Master: "foo", | |
| 122 }) | |
| 123 So(err, ShouldResemble, grpc.Errorf(codes.Invali dArgument, "No builder specified")) | |
| 124 }) | |
| 125 Convey(`Basic`, func() { | |
| 126 _, err := svc.GetBuildbotBuildJSON(c, &milo.Buil dbotBuildRequest{ | |
| 127 Master: name, | |
| 128 Builder: "fake", | |
| 129 BuildNum: 1, | |
| 130 }) | |
| 131 So(err, ShouldBeNil) | |
| 132 }) | |
| 133 Convey(`Basic Not found`, func() { | |
| 134 _, err := svc.GetBuildbotBuildJSON(c, &milo.Buil dbotBuildRequest{ | |
| 135 Master: name, | |
| 136 Builder: "fake", | |
| 137 BuildNum: 2, | |
| 138 }) | |
| 139 So(err, ShouldResemble, grpc.Errorf(codes.Unauth enticated, "Unauthenticated request")) | |
|
nodir
2017/05/18 03:17:15
why not NotFound?
i think you meant Forbidden. Ot
Ryan Tseng
2017/05/26 18:10:52
This is WAI. buildbot has a global namespace for
nodir
2017/05/26 18:33:04
I see. It's good
| |
| 140 }) | |
| 68 }) | 141 }) |
| 69 }) | 142 }) |
| 70 } | 143 } |
| OLD | NEW |