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

Side by Side Diff: milo/appengine/buildbot/grpc_test.go

Issue 2944983003: [milo] {buildbucket,buildbot,swarming,logdog} -> backends/*. (Closed)
Patch Set: fix the tests Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « milo/appengine/buildbot/grpc.go ('k') | milo/appengine/buildbot/html.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package buildbot
6
7 import (
8 "testing"
9
10 "google.golang.org/grpc"
11 "google.golang.org/grpc/codes"
12
13 "github.com/luci/gae/impl/memory"
14 ds "github.com/luci/gae/service/datastore"
15 "github.com/luci/luci-go/common/clock/testclock"
16 milo "github.com/luci/luci-go/milo/api/proto"
17 . "github.com/smartystreets/goconvey/convey"
18 "golang.org/x/net/context"
19 )
20
21 func TestGRPC(t *testing.T) {
22 c := memory.Use(context.Background())
23 c, _ = testclock.UseTime(c, testclock.TestTimeUTC)
24
25 Convey(`A test environment`, t, func() {
26 name := "testmaster"
27 bname := "testbuilder"
28 master := &buildbotMaster{
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)
46 ds.GetTestable(c).Consistent(true)
47 ds.GetTestable(c).AutoIndex(true)
48 svc := Service{}
49
50 Convey(`Get finished builds`, func() {
51 // Add in some builds.
52 for i := 0; i < 5; i++ {
53 ds.Put(c, &buildbotBuild{
54 Master: name,
55 Buildername: bname,
56 Number: i,
57 Finished: true,
58 })
59 }
60 ds.Put(c, &buildbotBuild{
61 Master: name,
62 Buildername: bname,
63 Number: 6,
64 Finished: false,
65 })
66 ds.GetTestable(c).CatchupIndexes()
67
68 r := &milo.BuildbotBuildsRequest{
69 Master: name,
70 Builder: bname,
71 }
72 result, err := svc.GetBuildbotBuildsJSON(c, r)
73 So(err, ShouldBeNil)
74 So(len(result.Builds), ShouldEqual, 5)
75
76 Convey(`Also get incomplete builds`, func() {
77 r := &milo.BuildbotBuildsRequest{
78 Master: name,
79 Builder: bname,
80 IncludeCurrent: true,
81 }
82 result, err := svc.GetBuildbotBuildsJSON(c, r)
83 So(err, ShouldBeNil)
84 So(len(result.Builds), ShouldEqual, 6)
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"))
140 })
141 })
142 })
143 }
OLDNEW
« no previous file with comments | « milo/appengine/buildbot/grpc.go ('k') | milo/appengine/buildbot/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698