go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gae/impl/dummy/dummy_test.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package dummy 16 17 import ( 18 "context" 19 "testing" 20 21 dsS "go.chromium.org/luci/gae/service/datastore" 22 infoS "go.chromium.org/luci/gae/service/info" 23 mailS "go.chromium.org/luci/gae/service/mail" 24 mcS "go.chromium.org/luci/gae/service/memcache" 25 modS "go.chromium.org/luci/gae/service/module" 26 tqS "go.chromium.org/luci/gae/service/taskqueue" 27 userS "go.chromium.org/luci/gae/service/user" 28 29 . "github.com/smartystreets/goconvey/convey" 30 ) 31 32 func TestContextAccess(t *testing.T) { 33 t.Parallel() 34 35 // p is a function which recovers an error and then immediately panics with 36 // the contained string. It's defer'd in each test so that we can use the 37 // ShouldPanicWith assertion (which does an == comparison and not 38 // a reflect.DeepEquals comparison). 39 p := func() { panic(recover().(error).Error()) } 40 41 Convey("Context Access", t, func() { 42 c := context.Background() 43 44 Convey("blank", func() { 45 So(dsS.Raw(c), ShouldBeNil) 46 So(mcS.Raw(c), ShouldBeNil) 47 So(tqS.Raw(c), ShouldBeNil) 48 So(infoS.Raw(c), ShouldBeNil) 49 }) 50 51 // needed for everything else 52 c = infoS.Set(c, Info()) 53 54 Convey("Info", func() { 55 So(infoS.Raw(c), ShouldNotBeNil) 56 So(func() { 57 defer p() 58 infoS.Raw(c).Datacenter() 59 }, ShouldPanicWith, "dummy: method Info.Datacenter is not implemented") 60 61 Convey("ModuleHostname", func() { 62 host, err := infoS.ModuleHostname(c, "", "", "") 63 So(err, ShouldBeNil) 64 So(host, ShouldEqual, "version.module.dummy-appid.example.com") 65 66 host, err = infoS.ModuleHostname(c, "wut", "10", "") 67 So(err, ShouldBeNil) 68 So(host, ShouldEqual, "10.wut.dummy-appid.example.com") 69 }) 70 }) 71 72 Convey("Datastore", func() { 73 c = dsS.SetRaw(c, Datastore()) 74 So(dsS.Raw(c), ShouldNotBeNil) 75 So(func() { 76 defer p() 77 _, _ = dsS.Raw(c).DecodeCursor("wut") 78 }, ShouldPanicWith, "dummy: method Datastore.DecodeCursor is not implemented") 79 }) 80 81 Convey("Memcache", func() { 82 c = mcS.SetRaw(c, Memcache()) 83 So(mcS.Raw(c), ShouldNotBeNil) 84 So(func() { 85 defer p() 86 _ = mcS.Add(c, nil) 87 }, ShouldPanicWith, "dummy: method Memcache.AddMulti is not implemented") 88 }) 89 90 Convey("TaskQueue", func() { 91 c = tqS.SetRaw(c, TaskQueue()) 92 So(tqS.Raw(c), ShouldNotBeNil) 93 So(func() { 94 defer p() 95 _ = tqS.Purge(c, "") 96 }, ShouldPanicWith, "dummy: method TaskQueue.Purge is not implemented") 97 }) 98 99 Convey("User", func() { 100 c = userS.Set(c, User()) 101 So(userS.Raw(c), ShouldNotBeNil) 102 So(func() { 103 defer p() 104 _ = userS.IsAdmin(c) 105 }, ShouldPanicWith, "dummy: method User.IsAdmin is not implemented") 106 }) 107 108 Convey("Mail", func() { 109 c = mailS.Set(c, Mail()) 110 So(mailS.Raw(c), ShouldNotBeNil) 111 So(func() { 112 defer p() 113 _ = mailS.Send(c, nil) 114 }, ShouldPanicWith, "dummy: method Mail.Send is not implemented") 115 }) 116 117 Convey("Module", func() { 118 c = modS.Set(c, Module()) 119 So(modS.Raw(c), ShouldNotBeNil) 120 So(func() { 121 defer p() 122 modS.List(c) 123 }, ShouldPanicWith, "dummy: method Module.List is not implemented") 124 }) 125 }) 126 }