go.uber.org/yarpc@v1.72.1/yarpctest/fake_peer_list_updater.go (about) 1 // Copyright (c) 2022 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package yarpctest 22 23 import ( 24 "go.uber.org/yarpc/api/transport" 25 "go.uber.org/yarpc/pkg/lifecycletest" 26 ) 27 28 // FakePeerListUpdaterOption is an option for NewFakePeerListUpdater. 29 type FakePeerListUpdaterOption func(*FakePeerListUpdater) 30 31 // Watch is a fake option for NewFakePeerListUpdater that enables "watch". It's fake. 32 func Watch(u *FakePeerListUpdater) { 33 u.watch = true 34 } 35 36 // UpdaterNop is a fake option for NewFakePeerListUpdater that sets a nop var. It's fake. 37 func UpdaterNop(nop string) func(*FakePeerListUpdater) { 38 return func(u *FakePeerListUpdater) { 39 u.nop = nop 40 } 41 } 42 43 // FakePeerListUpdater is a fake peer list updater. It doesn't actually update 44 // a peer list. 45 type FakePeerListUpdater struct { 46 transport.Lifecycle 47 watch bool 48 nop string 49 } 50 51 // NewFakePeerListUpdater returns a new FakePeerListUpdater, applying any 52 // passed options. 53 func NewFakePeerListUpdater(opts ...FakePeerListUpdaterOption) *FakePeerListUpdater { 54 u := &FakePeerListUpdater{ 55 Lifecycle: lifecycletest.NewNop(), 56 } 57 for _, opt := range opts { 58 opt(u) 59 } 60 return u 61 } 62 63 // Watch returns whether the peer list updater was configured to "watch". It is 64 // fake. 65 func (u *FakePeerListUpdater) Watch() bool { 66 return u.watch 67 } 68 69 // Nop returns the nop variable. 70 func (u *FakePeerListUpdater) Nop() string { 71 return u.nop 72 }