gen.go 520 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130
  1. /*
  2. Copyright 2018 Google LLC
  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. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // This file was generated by "go run gen/main.go > gen.go". Do not edit
  14. // directly.
  15. package cloud
  16. import (
  17. "context"
  18. "fmt"
  19. "net/http"
  20. "sync"
  21. "google.golang.org/api/googleapi"
  22. "k8s.io/klog"
  23. "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
  24. "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
  25. alpha "google.golang.org/api/compute/v0.alpha"
  26. beta "google.golang.org/api/compute/v0.beta"
  27. ga "google.golang.org/api/compute/v1"
  28. )
  29. // Cloud is an interface for the GCE compute API.
  30. type Cloud interface {
  31. Addresses() Addresses
  32. AlphaAddresses() AlphaAddresses
  33. BetaAddresses() BetaAddresses
  34. GlobalAddresses() GlobalAddresses
  35. BackendServices() BackendServices
  36. BetaBackendServices() BetaBackendServices
  37. AlphaBackendServices() AlphaBackendServices
  38. RegionBackendServices() RegionBackendServices
  39. AlphaRegionBackendServices() AlphaRegionBackendServices
  40. Disks() Disks
  41. RegionDisks() RegionDisks
  42. Firewalls() Firewalls
  43. ForwardingRules() ForwardingRules
  44. AlphaForwardingRules() AlphaForwardingRules
  45. GlobalForwardingRules() GlobalForwardingRules
  46. HealthChecks() HealthChecks
  47. AlphaHealthChecks() AlphaHealthChecks
  48. BetaHealthChecks() BetaHealthChecks
  49. HttpHealthChecks() HttpHealthChecks
  50. HttpsHealthChecks() HttpsHealthChecks
  51. InstanceGroups() InstanceGroups
  52. Instances() Instances
  53. BetaInstances() BetaInstances
  54. AlphaInstances() AlphaInstances
  55. AlphaNetworkEndpointGroups() AlphaNetworkEndpointGroups
  56. BetaNetworkEndpointGroups() BetaNetworkEndpointGroups
  57. Projects() Projects
  58. Regions() Regions
  59. Routes() Routes
  60. BetaSecurityPolicies() BetaSecurityPolicies
  61. SslCertificates() SslCertificates
  62. TargetHttpProxies() TargetHttpProxies
  63. TargetHttpsProxies() TargetHttpsProxies
  64. TargetPools() TargetPools
  65. UrlMaps() UrlMaps
  66. Zones() Zones
  67. }
  68. // NewGCE returns a GCE.
  69. func NewGCE(s *Service) *GCE {
  70. g := &GCE{
  71. gceAddresses: &GCEAddresses{s},
  72. gceAlphaAddresses: &GCEAlphaAddresses{s},
  73. gceBetaAddresses: &GCEBetaAddresses{s},
  74. gceGlobalAddresses: &GCEGlobalAddresses{s},
  75. gceBackendServices: &GCEBackendServices{s},
  76. gceBetaBackendServices: &GCEBetaBackendServices{s},
  77. gceAlphaBackendServices: &GCEAlphaBackendServices{s},
  78. gceRegionBackendServices: &GCERegionBackendServices{s},
  79. gceAlphaRegionBackendServices: &GCEAlphaRegionBackendServices{s},
  80. gceDisks: &GCEDisks{s},
  81. gceRegionDisks: &GCERegionDisks{s},
  82. gceFirewalls: &GCEFirewalls{s},
  83. gceForwardingRules: &GCEForwardingRules{s},
  84. gceAlphaForwardingRules: &GCEAlphaForwardingRules{s},
  85. gceGlobalForwardingRules: &GCEGlobalForwardingRules{s},
  86. gceHealthChecks: &GCEHealthChecks{s},
  87. gceAlphaHealthChecks: &GCEAlphaHealthChecks{s},
  88. gceBetaHealthChecks: &GCEBetaHealthChecks{s},
  89. gceHttpHealthChecks: &GCEHttpHealthChecks{s},
  90. gceHttpsHealthChecks: &GCEHttpsHealthChecks{s},
  91. gceInstanceGroups: &GCEInstanceGroups{s},
  92. gceInstances: &GCEInstances{s},
  93. gceBetaInstances: &GCEBetaInstances{s},
  94. gceAlphaInstances: &GCEAlphaInstances{s},
  95. gceAlphaNetworkEndpointGroups: &GCEAlphaNetworkEndpointGroups{s},
  96. gceBetaNetworkEndpointGroups: &GCEBetaNetworkEndpointGroups{s},
  97. gceProjects: &GCEProjects{s},
  98. gceRegions: &GCERegions{s},
  99. gceRoutes: &GCERoutes{s},
  100. gceBetaSecurityPolicies: &GCEBetaSecurityPolicies{s},
  101. gceSslCertificates: &GCESslCertificates{s},
  102. gceTargetHttpProxies: &GCETargetHttpProxies{s},
  103. gceTargetHttpsProxies: &GCETargetHttpsProxies{s},
  104. gceTargetPools: &GCETargetPools{s},
  105. gceUrlMaps: &GCEUrlMaps{s},
  106. gceZones: &GCEZones{s},
  107. }
  108. return g
  109. }
  110. // GCE implements Cloud.
  111. var _ Cloud = (*GCE)(nil)
  112. // GCE is the golang adapter for the compute APIs.
  113. type GCE struct {
  114. gceAddresses *GCEAddresses
  115. gceAlphaAddresses *GCEAlphaAddresses
  116. gceBetaAddresses *GCEBetaAddresses
  117. gceGlobalAddresses *GCEGlobalAddresses
  118. gceBackendServices *GCEBackendServices
  119. gceBetaBackendServices *GCEBetaBackendServices
  120. gceAlphaBackendServices *GCEAlphaBackendServices
  121. gceRegionBackendServices *GCERegionBackendServices
  122. gceAlphaRegionBackendServices *GCEAlphaRegionBackendServices
  123. gceDisks *GCEDisks
  124. gceRegionDisks *GCERegionDisks
  125. gceFirewalls *GCEFirewalls
  126. gceForwardingRules *GCEForwardingRules
  127. gceAlphaForwardingRules *GCEAlphaForwardingRules
  128. gceGlobalForwardingRules *GCEGlobalForwardingRules
  129. gceHealthChecks *GCEHealthChecks
  130. gceAlphaHealthChecks *GCEAlphaHealthChecks
  131. gceBetaHealthChecks *GCEBetaHealthChecks
  132. gceHttpHealthChecks *GCEHttpHealthChecks
  133. gceHttpsHealthChecks *GCEHttpsHealthChecks
  134. gceInstanceGroups *GCEInstanceGroups
  135. gceInstances *GCEInstances
  136. gceBetaInstances *GCEBetaInstances
  137. gceAlphaInstances *GCEAlphaInstances
  138. gceAlphaNetworkEndpointGroups *GCEAlphaNetworkEndpointGroups
  139. gceBetaNetworkEndpointGroups *GCEBetaNetworkEndpointGroups
  140. gceProjects *GCEProjects
  141. gceRegions *GCERegions
  142. gceRoutes *GCERoutes
  143. gceBetaSecurityPolicies *GCEBetaSecurityPolicies
  144. gceSslCertificates *GCESslCertificates
  145. gceTargetHttpProxies *GCETargetHttpProxies
  146. gceTargetHttpsProxies *GCETargetHttpsProxies
  147. gceTargetPools *GCETargetPools
  148. gceUrlMaps *GCEUrlMaps
  149. gceZones *GCEZones
  150. }
  151. // Addresses returns the interface for the ga Addresses.
  152. func (gce *GCE) Addresses() Addresses {
  153. return gce.gceAddresses
  154. }
  155. // AlphaAddresses returns the interface for the alpha Addresses.
  156. func (gce *GCE) AlphaAddresses() AlphaAddresses {
  157. return gce.gceAlphaAddresses
  158. }
  159. // BetaAddresses returns the interface for the beta Addresses.
  160. func (gce *GCE) BetaAddresses() BetaAddresses {
  161. return gce.gceBetaAddresses
  162. }
  163. // GlobalAddresses returns the interface for the ga GlobalAddresses.
  164. func (gce *GCE) GlobalAddresses() GlobalAddresses {
  165. return gce.gceGlobalAddresses
  166. }
  167. // BackendServices returns the interface for the ga BackendServices.
  168. func (gce *GCE) BackendServices() BackendServices {
  169. return gce.gceBackendServices
  170. }
  171. // BetaBackendServices returns the interface for the beta BackendServices.
  172. func (gce *GCE) BetaBackendServices() BetaBackendServices {
  173. return gce.gceBetaBackendServices
  174. }
  175. // AlphaBackendServices returns the interface for the alpha BackendServices.
  176. func (gce *GCE) AlphaBackendServices() AlphaBackendServices {
  177. return gce.gceAlphaBackendServices
  178. }
  179. // RegionBackendServices returns the interface for the ga RegionBackendServices.
  180. func (gce *GCE) RegionBackendServices() RegionBackendServices {
  181. return gce.gceRegionBackendServices
  182. }
  183. // AlphaRegionBackendServices returns the interface for the alpha RegionBackendServices.
  184. func (gce *GCE) AlphaRegionBackendServices() AlphaRegionBackendServices {
  185. return gce.gceAlphaRegionBackendServices
  186. }
  187. // Disks returns the interface for the ga Disks.
  188. func (gce *GCE) Disks() Disks {
  189. return gce.gceDisks
  190. }
  191. // RegionDisks returns the interface for the ga RegionDisks.
  192. func (gce *GCE) RegionDisks() RegionDisks {
  193. return gce.gceRegionDisks
  194. }
  195. // Firewalls returns the interface for the ga Firewalls.
  196. func (gce *GCE) Firewalls() Firewalls {
  197. return gce.gceFirewalls
  198. }
  199. // ForwardingRules returns the interface for the ga ForwardingRules.
  200. func (gce *GCE) ForwardingRules() ForwardingRules {
  201. return gce.gceForwardingRules
  202. }
  203. // AlphaForwardingRules returns the interface for the alpha ForwardingRules.
  204. func (gce *GCE) AlphaForwardingRules() AlphaForwardingRules {
  205. return gce.gceAlphaForwardingRules
  206. }
  207. // GlobalForwardingRules returns the interface for the ga GlobalForwardingRules.
  208. func (gce *GCE) GlobalForwardingRules() GlobalForwardingRules {
  209. return gce.gceGlobalForwardingRules
  210. }
  211. // HealthChecks returns the interface for the ga HealthChecks.
  212. func (gce *GCE) HealthChecks() HealthChecks {
  213. return gce.gceHealthChecks
  214. }
  215. // AlphaHealthChecks returns the interface for the alpha HealthChecks.
  216. func (gce *GCE) AlphaHealthChecks() AlphaHealthChecks {
  217. return gce.gceAlphaHealthChecks
  218. }
  219. // BetaHealthChecks returns the interface for the beta HealthChecks.
  220. func (gce *GCE) BetaHealthChecks() BetaHealthChecks {
  221. return gce.gceBetaHealthChecks
  222. }
  223. // HttpHealthChecks returns the interface for the ga HttpHealthChecks.
  224. func (gce *GCE) HttpHealthChecks() HttpHealthChecks {
  225. return gce.gceHttpHealthChecks
  226. }
  227. // HttpsHealthChecks returns the interface for the ga HttpsHealthChecks.
  228. func (gce *GCE) HttpsHealthChecks() HttpsHealthChecks {
  229. return gce.gceHttpsHealthChecks
  230. }
  231. // InstanceGroups returns the interface for the ga InstanceGroups.
  232. func (gce *GCE) InstanceGroups() InstanceGroups {
  233. return gce.gceInstanceGroups
  234. }
  235. // Instances returns the interface for the ga Instances.
  236. func (gce *GCE) Instances() Instances {
  237. return gce.gceInstances
  238. }
  239. // BetaInstances returns the interface for the beta Instances.
  240. func (gce *GCE) BetaInstances() BetaInstances {
  241. return gce.gceBetaInstances
  242. }
  243. // AlphaInstances returns the interface for the alpha Instances.
  244. func (gce *GCE) AlphaInstances() AlphaInstances {
  245. return gce.gceAlphaInstances
  246. }
  247. // AlphaNetworkEndpointGroups returns the interface for the alpha NetworkEndpointGroups.
  248. func (gce *GCE) AlphaNetworkEndpointGroups() AlphaNetworkEndpointGroups {
  249. return gce.gceAlphaNetworkEndpointGroups
  250. }
  251. // BetaNetworkEndpointGroups returns the interface for the beta NetworkEndpointGroups.
  252. func (gce *GCE) BetaNetworkEndpointGroups() BetaNetworkEndpointGroups {
  253. return gce.gceBetaNetworkEndpointGroups
  254. }
  255. // Projects returns the interface for the ga Projects.
  256. func (gce *GCE) Projects() Projects {
  257. return gce.gceProjects
  258. }
  259. // Regions returns the interface for the ga Regions.
  260. func (gce *GCE) Regions() Regions {
  261. return gce.gceRegions
  262. }
  263. // Routes returns the interface for the ga Routes.
  264. func (gce *GCE) Routes() Routes {
  265. return gce.gceRoutes
  266. }
  267. // BetaSecurityPolicies returns the interface for the beta SecurityPolicies.
  268. func (gce *GCE) BetaSecurityPolicies() BetaSecurityPolicies {
  269. return gce.gceBetaSecurityPolicies
  270. }
  271. // SslCertificates returns the interface for the ga SslCertificates.
  272. func (gce *GCE) SslCertificates() SslCertificates {
  273. return gce.gceSslCertificates
  274. }
  275. // TargetHttpProxies returns the interface for the ga TargetHttpProxies.
  276. func (gce *GCE) TargetHttpProxies() TargetHttpProxies {
  277. return gce.gceTargetHttpProxies
  278. }
  279. // TargetHttpsProxies returns the interface for the ga TargetHttpsProxies.
  280. func (gce *GCE) TargetHttpsProxies() TargetHttpsProxies {
  281. return gce.gceTargetHttpsProxies
  282. }
  283. // TargetPools returns the interface for the ga TargetPools.
  284. func (gce *GCE) TargetPools() TargetPools {
  285. return gce.gceTargetPools
  286. }
  287. // UrlMaps returns the interface for the ga UrlMaps.
  288. func (gce *GCE) UrlMaps() UrlMaps {
  289. return gce.gceUrlMaps
  290. }
  291. // Zones returns the interface for the ga Zones.
  292. func (gce *GCE) Zones() Zones {
  293. return gce.gceZones
  294. }
  295. // NewMockGCE returns a new mock for GCE.
  296. func NewMockGCE(projectRouter ProjectRouter) *MockGCE {
  297. mockAddressesObjs := map[meta.Key]*MockAddressesObj{}
  298. mockBackendServicesObjs := map[meta.Key]*MockBackendServicesObj{}
  299. mockDisksObjs := map[meta.Key]*MockDisksObj{}
  300. mockFirewallsObjs := map[meta.Key]*MockFirewallsObj{}
  301. mockForwardingRulesObjs := map[meta.Key]*MockForwardingRulesObj{}
  302. mockGlobalAddressesObjs := map[meta.Key]*MockGlobalAddressesObj{}
  303. mockGlobalForwardingRulesObjs := map[meta.Key]*MockGlobalForwardingRulesObj{}
  304. mockHealthChecksObjs := map[meta.Key]*MockHealthChecksObj{}
  305. mockHttpHealthChecksObjs := map[meta.Key]*MockHttpHealthChecksObj{}
  306. mockHttpsHealthChecksObjs := map[meta.Key]*MockHttpsHealthChecksObj{}
  307. mockInstanceGroupsObjs := map[meta.Key]*MockInstanceGroupsObj{}
  308. mockInstancesObjs := map[meta.Key]*MockInstancesObj{}
  309. mockNetworkEndpointGroupsObjs := map[meta.Key]*MockNetworkEndpointGroupsObj{}
  310. mockProjectsObjs := map[meta.Key]*MockProjectsObj{}
  311. mockRegionBackendServicesObjs := map[meta.Key]*MockRegionBackendServicesObj{}
  312. mockRegionDisksObjs := map[meta.Key]*MockRegionDisksObj{}
  313. mockRegionsObjs := map[meta.Key]*MockRegionsObj{}
  314. mockRoutesObjs := map[meta.Key]*MockRoutesObj{}
  315. mockSecurityPoliciesObjs := map[meta.Key]*MockSecurityPoliciesObj{}
  316. mockSslCertificatesObjs := map[meta.Key]*MockSslCertificatesObj{}
  317. mockTargetHttpProxiesObjs := map[meta.Key]*MockTargetHttpProxiesObj{}
  318. mockTargetHttpsProxiesObjs := map[meta.Key]*MockTargetHttpsProxiesObj{}
  319. mockTargetPoolsObjs := map[meta.Key]*MockTargetPoolsObj{}
  320. mockUrlMapsObjs := map[meta.Key]*MockUrlMapsObj{}
  321. mockZonesObjs := map[meta.Key]*MockZonesObj{}
  322. mock := &MockGCE{
  323. MockAddresses: NewMockAddresses(projectRouter, mockAddressesObjs),
  324. MockAlphaAddresses: NewMockAlphaAddresses(projectRouter, mockAddressesObjs),
  325. MockBetaAddresses: NewMockBetaAddresses(projectRouter, mockAddressesObjs),
  326. MockGlobalAddresses: NewMockGlobalAddresses(projectRouter, mockGlobalAddressesObjs),
  327. MockBackendServices: NewMockBackendServices(projectRouter, mockBackendServicesObjs),
  328. MockBetaBackendServices: NewMockBetaBackendServices(projectRouter, mockBackendServicesObjs),
  329. MockAlphaBackendServices: NewMockAlphaBackendServices(projectRouter, mockBackendServicesObjs),
  330. MockRegionBackendServices: NewMockRegionBackendServices(projectRouter, mockRegionBackendServicesObjs),
  331. MockAlphaRegionBackendServices: NewMockAlphaRegionBackendServices(projectRouter, mockRegionBackendServicesObjs),
  332. MockDisks: NewMockDisks(projectRouter, mockDisksObjs),
  333. MockRegionDisks: NewMockRegionDisks(projectRouter, mockRegionDisksObjs),
  334. MockFirewalls: NewMockFirewalls(projectRouter, mockFirewallsObjs),
  335. MockForwardingRules: NewMockForwardingRules(projectRouter, mockForwardingRulesObjs),
  336. MockAlphaForwardingRules: NewMockAlphaForwardingRules(projectRouter, mockForwardingRulesObjs),
  337. MockGlobalForwardingRules: NewMockGlobalForwardingRules(projectRouter, mockGlobalForwardingRulesObjs),
  338. MockHealthChecks: NewMockHealthChecks(projectRouter, mockHealthChecksObjs),
  339. MockAlphaHealthChecks: NewMockAlphaHealthChecks(projectRouter, mockHealthChecksObjs),
  340. MockBetaHealthChecks: NewMockBetaHealthChecks(projectRouter, mockHealthChecksObjs),
  341. MockHttpHealthChecks: NewMockHttpHealthChecks(projectRouter, mockHttpHealthChecksObjs),
  342. MockHttpsHealthChecks: NewMockHttpsHealthChecks(projectRouter, mockHttpsHealthChecksObjs),
  343. MockInstanceGroups: NewMockInstanceGroups(projectRouter, mockInstanceGroupsObjs),
  344. MockInstances: NewMockInstances(projectRouter, mockInstancesObjs),
  345. MockBetaInstances: NewMockBetaInstances(projectRouter, mockInstancesObjs),
  346. MockAlphaInstances: NewMockAlphaInstances(projectRouter, mockInstancesObjs),
  347. MockAlphaNetworkEndpointGroups: NewMockAlphaNetworkEndpointGroups(projectRouter, mockNetworkEndpointGroupsObjs),
  348. MockBetaNetworkEndpointGroups: NewMockBetaNetworkEndpointGroups(projectRouter, mockNetworkEndpointGroupsObjs),
  349. MockProjects: NewMockProjects(projectRouter, mockProjectsObjs),
  350. MockRegions: NewMockRegions(projectRouter, mockRegionsObjs),
  351. MockRoutes: NewMockRoutes(projectRouter, mockRoutesObjs),
  352. MockBetaSecurityPolicies: NewMockBetaSecurityPolicies(projectRouter, mockSecurityPoliciesObjs),
  353. MockSslCertificates: NewMockSslCertificates(projectRouter, mockSslCertificatesObjs),
  354. MockTargetHttpProxies: NewMockTargetHttpProxies(projectRouter, mockTargetHttpProxiesObjs),
  355. MockTargetHttpsProxies: NewMockTargetHttpsProxies(projectRouter, mockTargetHttpsProxiesObjs),
  356. MockTargetPools: NewMockTargetPools(projectRouter, mockTargetPoolsObjs),
  357. MockUrlMaps: NewMockUrlMaps(projectRouter, mockUrlMapsObjs),
  358. MockZones: NewMockZones(projectRouter, mockZonesObjs),
  359. }
  360. return mock
  361. }
  362. // MockGCE implements Cloud.
  363. var _ Cloud = (*MockGCE)(nil)
  364. // MockGCE is the mock for the compute API.
  365. type MockGCE struct {
  366. MockAddresses *MockAddresses
  367. MockAlphaAddresses *MockAlphaAddresses
  368. MockBetaAddresses *MockBetaAddresses
  369. MockGlobalAddresses *MockGlobalAddresses
  370. MockBackendServices *MockBackendServices
  371. MockBetaBackendServices *MockBetaBackendServices
  372. MockAlphaBackendServices *MockAlphaBackendServices
  373. MockRegionBackendServices *MockRegionBackendServices
  374. MockAlphaRegionBackendServices *MockAlphaRegionBackendServices
  375. MockDisks *MockDisks
  376. MockRegionDisks *MockRegionDisks
  377. MockFirewalls *MockFirewalls
  378. MockForwardingRules *MockForwardingRules
  379. MockAlphaForwardingRules *MockAlphaForwardingRules
  380. MockGlobalForwardingRules *MockGlobalForwardingRules
  381. MockHealthChecks *MockHealthChecks
  382. MockAlphaHealthChecks *MockAlphaHealthChecks
  383. MockBetaHealthChecks *MockBetaHealthChecks
  384. MockHttpHealthChecks *MockHttpHealthChecks
  385. MockHttpsHealthChecks *MockHttpsHealthChecks
  386. MockInstanceGroups *MockInstanceGroups
  387. MockInstances *MockInstances
  388. MockBetaInstances *MockBetaInstances
  389. MockAlphaInstances *MockAlphaInstances
  390. MockAlphaNetworkEndpointGroups *MockAlphaNetworkEndpointGroups
  391. MockBetaNetworkEndpointGroups *MockBetaNetworkEndpointGroups
  392. MockProjects *MockProjects
  393. MockRegions *MockRegions
  394. MockRoutes *MockRoutes
  395. MockBetaSecurityPolicies *MockBetaSecurityPolicies
  396. MockSslCertificates *MockSslCertificates
  397. MockTargetHttpProxies *MockTargetHttpProxies
  398. MockTargetHttpsProxies *MockTargetHttpsProxies
  399. MockTargetPools *MockTargetPools
  400. MockUrlMaps *MockUrlMaps
  401. MockZones *MockZones
  402. }
  403. // Addresses returns the interface for the ga Addresses.
  404. func (mock *MockGCE) Addresses() Addresses {
  405. return mock.MockAddresses
  406. }
  407. // AlphaAddresses returns the interface for the alpha Addresses.
  408. func (mock *MockGCE) AlphaAddresses() AlphaAddresses {
  409. return mock.MockAlphaAddresses
  410. }
  411. // BetaAddresses returns the interface for the beta Addresses.
  412. func (mock *MockGCE) BetaAddresses() BetaAddresses {
  413. return mock.MockBetaAddresses
  414. }
  415. // GlobalAddresses returns the interface for the ga GlobalAddresses.
  416. func (mock *MockGCE) GlobalAddresses() GlobalAddresses {
  417. return mock.MockGlobalAddresses
  418. }
  419. // BackendServices returns the interface for the ga BackendServices.
  420. func (mock *MockGCE) BackendServices() BackendServices {
  421. return mock.MockBackendServices
  422. }
  423. // BetaBackendServices returns the interface for the beta BackendServices.
  424. func (mock *MockGCE) BetaBackendServices() BetaBackendServices {
  425. return mock.MockBetaBackendServices
  426. }
  427. // AlphaBackendServices returns the interface for the alpha BackendServices.
  428. func (mock *MockGCE) AlphaBackendServices() AlphaBackendServices {
  429. return mock.MockAlphaBackendServices
  430. }
  431. // RegionBackendServices returns the interface for the ga RegionBackendServices.
  432. func (mock *MockGCE) RegionBackendServices() RegionBackendServices {
  433. return mock.MockRegionBackendServices
  434. }
  435. // AlphaRegionBackendServices returns the interface for the alpha RegionBackendServices.
  436. func (mock *MockGCE) AlphaRegionBackendServices() AlphaRegionBackendServices {
  437. return mock.MockAlphaRegionBackendServices
  438. }
  439. // Disks returns the interface for the ga Disks.
  440. func (mock *MockGCE) Disks() Disks {
  441. return mock.MockDisks
  442. }
  443. // RegionDisks returns the interface for the ga RegionDisks.
  444. func (mock *MockGCE) RegionDisks() RegionDisks {
  445. return mock.MockRegionDisks
  446. }
  447. // Firewalls returns the interface for the ga Firewalls.
  448. func (mock *MockGCE) Firewalls() Firewalls {
  449. return mock.MockFirewalls
  450. }
  451. // ForwardingRules returns the interface for the ga ForwardingRules.
  452. func (mock *MockGCE) ForwardingRules() ForwardingRules {
  453. return mock.MockForwardingRules
  454. }
  455. // AlphaForwardingRules returns the interface for the alpha ForwardingRules.
  456. func (mock *MockGCE) AlphaForwardingRules() AlphaForwardingRules {
  457. return mock.MockAlphaForwardingRules
  458. }
  459. // GlobalForwardingRules returns the interface for the ga GlobalForwardingRules.
  460. func (mock *MockGCE) GlobalForwardingRules() GlobalForwardingRules {
  461. return mock.MockGlobalForwardingRules
  462. }
  463. // HealthChecks returns the interface for the ga HealthChecks.
  464. func (mock *MockGCE) HealthChecks() HealthChecks {
  465. return mock.MockHealthChecks
  466. }
  467. // AlphaHealthChecks returns the interface for the alpha HealthChecks.
  468. func (mock *MockGCE) AlphaHealthChecks() AlphaHealthChecks {
  469. return mock.MockAlphaHealthChecks
  470. }
  471. // BetaHealthChecks returns the interface for the beta HealthChecks.
  472. func (mock *MockGCE) BetaHealthChecks() BetaHealthChecks {
  473. return mock.MockBetaHealthChecks
  474. }
  475. // HttpHealthChecks returns the interface for the ga HttpHealthChecks.
  476. func (mock *MockGCE) HttpHealthChecks() HttpHealthChecks {
  477. return mock.MockHttpHealthChecks
  478. }
  479. // HttpsHealthChecks returns the interface for the ga HttpsHealthChecks.
  480. func (mock *MockGCE) HttpsHealthChecks() HttpsHealthChecks {
  481. return mock.MockHttpsHealthChecks
  482. }
  483. // InstanceGroups returns the interface for the ga InstanceGroups.
  484. func (mock *MockGCE) InstanceGroups() InstanceGroups {
  485. return mock.MockInstanceGroups
  486. }
  487. // Instances returns the interface for the ga Instances.
  488. func (mock *MockGCE) Instances() Instances {
  489. return mock.MockInstances
  490. }
  491. // BetaInstances returns the interface for the beta Instances.
  492. func (mock *MockGCE) BetaInstances() BetaInstances {
  493. return mock.MockBetaInstances
  494. }
  495. // AlphaInstances returns the interface for the alpha Instances.
  496. func (mock *MockGCE) AlphaInstances() AlphaInstances {
  497. return mock.MockAlphaInstances
  498. }
  499. // AlphaNetworkEndpointGroups returns the interface for the alpha NetworkEndpointGroups.
  500. func (mock *MockGCE) AlphaNetworkEndpointGroups() AlphaNetworkEndpointGroups {
  501. return mock.MockAlphaNetworkEndpointGroups
  502. }
  503. // BetaNetworkEndpointGroups returns the interface for the beta NetworkEndpointGroups.
  504. func (mock *MockGCE) BetaNetworkEndpointGroups() BetaNetworkEndpointGroups {
  505. return mock.MockBetaNetworkEndpointGroups
  506. }
  507. // Projects returns the interface for the ga Projects.
  508. func (mock *MockGCE) Projects() Projects {
  509. return mock.MockProjects
  510. }
  511. // Regions returns the interface for the ga Regions.
  512. func (mock *MockGCE) Regions() Regions {
  513. return mock.MockRegions
  514. }
  515. // Routes returns the interface for the ga Routes.
  516. func (mock *MockGCE) Routes() Routes {
  517. return mock.MockRoutes
  518. }
  519. // BetaSecurityPolicies returns the interface for the beta SecurityPolicies.
  520. func (mock *MockGCE) BetaSecurityPolicies() BetaSecurityPolicies {
  521. return mock.MockBetaSecurityPolicies
  522. }
  523. // SslCertificates returns the interface for the ga SslCertificates.
  524. func (mock *MockGCE) SslCertificates() SslCertificates {
  525. return mock.MockSslCertificates
  526. }
  527. // TargetHttpProxies returns the interface for the ga TargetHttpProxies.
  528. func (mock *MockGCE) TargetHttpProxies() TargetHttpProxies {
  529. return mock.MockTargetHttpProxies
  530. }
  531. // TargetHttpsProxies returns the interface for the ga TargetHttpsProxies.
  532. func (mock *MockGCE) TargetHttpsProxies() TargetHttpsProxies {
  533. return mock.MockTargetHttpsProxies
  534. }
  535. // TargetPools returns the interface for the ga TargetPools.
  536. func (mock *MockGCE) TargetPools() TargetPools {
  537. return mock.MockTargetPools
  538. }
  539. // UrlMaps returns the interface for the ga UrlMaps.
  540. func (mock *MockGCE) UrlMaps() UrlMaps {
  541. return mock.MockUrlMaps
  542. }
  543. // Zones returns the interface for the ga Zones.
  544. func (mock *MockGCE) Zones() Zones {
  545. return mock.MockZones
  546. }
  547. // MockAddressesObj is used to store the various object versions in the shared
  548. // map of mocked objects. This allows for multiple API versions to co-exist and
  549. // share the same "view" of the objects in the backend.
  550. type MockAddressesObj struct {
  551. Obj interface{}
  552. }
  553. // ToAlpha retrieves the given version of the object.
  554. func (m *MockAddressesObj) ToAlpha() *alpha.Address {
  555. if ret, ok := m.Obj.(*alpha.Address); ok {
  556. return ret
  557. }
  558. // Convert the object via JSON copying to the type that was requested.
  559. ret := &alpha.Address{}
  560. if err := copyViaJSON(ret, m.Obj); err != nil {
  561. klog.Errorf("Could not convert %T to *alpha.Address via JSON: %v", m.Obj, err)
  562. }
  563. return ret
  564. }
  565. // ToBeta retrieves the given version of the object.
  566. func (m *MockAddressesObj) ToBeta() *beta.Address {
  567. if ret, ok := m.Obj.(*beta.Address); ok {
  568. return ret
  569. }
  570. // Convert the object via JSON copying to the type that was requested.
  571. ret := &beta.Address{}
  572. if err := copyViaJSON(ret, m.Obj); err != nil {
  573. klog.Errorf("Could not convert %T to *beta.Address via JSON: %v", m.Obj, err)
  574. }
  575. return ret
  576. }
  577. // ToGA retrieves the given version of the object.
  578. func (m *MockAddressesObj) ToGA() *ga.Address {
  579. if ret, ok := m.Obj.(*ga.Address); ok {
  580. return ret
  581. }
  582. // Convert the object via JSON copying to the type that was requested.
  583. ret := &ga.Address{}
  584. if err := copyViaJSON(ret, m.Obj); err != nil {
  585. klog.Errorf("Could not convert %T to *ga.Address via JSON: %v", m.Obj, err)
  586. }
  587. return ret
  588. }
  589. // MockBackendServicesObj is used to store the various object versions in the shared
  590. // map of mocked objects. This allows for multiple API versions to co-exist and
  591. // share the same "view" of the objects in the backend.
  592. type MockBackendServicesObj struct {
  593. Obj interface{}
  594. }
  595. // ToAlpha retrieves the given version of the object.
  596. func (m *MockBackendServicesObj) ToAlpha() *alpha.BackendService {
  597. if ret, ok := m.Obj.(*alpha.BackendService); ok {
  598. return ret
  599. }
  600. // Convert the object via JSON copying to the type that was requested.
  601. ret := &alpha.BackendService{}
  602. if err := copyViaJSON(ret, m.Obj); err != nil {
  603. klog.Errorf("Could not convert %T to *alpha.BackendService via JSON: %v", m.Obj, err)
  604. }
  605. return ret
  606. }
  607. // ToBeta retrieves the given version of the object.
  608. func (m *MockBackendServicesObj) ToBeta() *beta.BackendService {
  609. if ret, ok := m.Obj.(*beta.BackendService); ok {
  610. return ret
  611. }
  612. // Convert the object via JSON copying to the type that was requested.
  613. ret := &beta.BackendService{}
  614. if err := copyViaJSON(ret, m.Obj); err != nil {
  615. klog.Errorf("Could not convert %T to *beta.BackendService via JSON: %v", m.Obj, err)
  616. }
  617. return ret
  618. }
  619. // ToGA retrieves the given version of the object.
  620. func (m *MockBackendServicesObj) ToGA() *ga.BackendService {
  621. if ret, ok := m.Obj.(*ga.BackendService); ok {
  622. return ret
  623. }
  624. // Convert the object via JSON copying to the type that was requested.
  625. ret := &ga.BackendService{}
  626. if err := copyViaJSON(ret, m.Obj); err != nil {
  627. klog.Errorf("Could not convert %T to *ga.BackendService via JSON: %v", m.Obj, err)
  628. }
  629. return ret
  630. }
  631. // MockDisksObj is used to store the various object versions in the shared
  632. // map of mocked objects. This allows for multiple API versions to co-exist and
  633. // share the same "view" of the objects in the backend.
  634. type MockDisksObj struct {
  635. Obj interface{}
  636. }
  637. // ToGA retrieves the given version of the object.
  638. func (m *MockDisksObj) ToGA() *ga.Disk {
  639. if ret, ok := m.Obj.(*ga.Disk); ok {
  640. return ret
  641. }
  642. // Convert the object via JSON copying to the type that was requested.
  643. ret := &ga.Disk{}
  644. if err := copyViaJSON(ret, m.Obj); err != nil {
  645. klog.Errorf("Could not convert %T to *ga.Disk via JSON: %v", m.Obj, err)
  646. }
  647. return ret
  648. }
  649. // MockFirewallsObj is used to store the various object versions in the shared
  650. // map of mocked objects. This allows for multiple API versions to co-exist and
  651. // share the same "view" of the objects in the backend.
  652. type MockFirewallsObj struct {
  653. Obj interface{}
  654. }
  655. // ToGA retrieves the given version of the object.
  656. func (m *MockFirewallsObj) ToGA() *ga.Firewall {
  657. if ret, ok := m.Obj.(*ga.Firewall); ok {
  658. return ret
  659. }
  660. // Convert the object via JSON copying to the type that was requested.
  661. ret := &ga.Firewall{}
  662. if err := copyViaJSON(ret, m.Obj); err != nil {
  663. klog.Errorf("Could not convert %T to *ga.Firewall via JSON: %v", m.Obj, err)
  664. }
  665. return ret
  666. }
  667. // MockForwardingRulesObj is used to store the various object versions in the shared
  668. // map of mocked objects. This allows for multiple API versions to co-exist and
  669. // share the same "view" of the objects in the backend.
  670. type MockForwardingRulesObj struct {
  671. Obj interface{}
  672. }
  673. // ToAlpha retrieves the given version of the object.
  674. func (m *MockForwardingRulesObj) ToAlpha() *alpha.ForwardingRule {
  675. if ret, ok := m.Obj.(*alpha.ForwardingRule); ok {
  676. return ret
  677. }
  678. // Convert the object via JSON copying to the type that was requested.
  679. ret := &alpha.ForwardingRule{}
  680. if err := copyViaJSON(ret, m.Obj); err != nil {
  681. klog.Errorf("Could not convert %T to *alpha.ForwardingRule via JSON: %v", m.Obj, err)
  682. }
  683. return ret
  684. }
  685. // ToGA retrieves the given version of the object.
  686. func (m *MockForwardingRulesObj) ToGA() *ga.ForwardingRule {
  687. if ret, ok := m.Obj.(*ga.ForwardingRule); ok {
  688. return ret
  689. }
  690. // Convert the object via JSON copying to the type that was requested.
  691. ret := &ga.ForwardingRule{}
  692. if err := copyViaJSON(ret, m.Obj); err != nil {
  693. klog.Errorf("Could not convert %T to *ga.ForwardingRule via JSON: %v", m.Obj, err)
  694. }
  695. return ret
  696. }
  697. // MockGlobalAddressesObj is used to store the various object versions in the shared
  698. // map of mocked objects. This allows for multiple API versions to co-exist and
  699. // share the same "view" of the objects in the backend.
  700. type MockGlobalAddressesObj struct {
  701. Obj interface{}
  702. }
  703. // ToGA retrieves the given version of the object.
  704. func (m *MockGlobalAddressesObj) ToGA() *ga.Address {
  705. if ret, ok := m.Obj.(*ga.Address); ok {
  706. return ret
  707. }
  708. // Convert the object via JSON copying to the type that was requested.
  709. ret := &ga.Address{}
  710. if err := copyViaJSON(ret, m.Obj); err != nil {
  711. klog.Errorf("Could not convert %T to *ga.Address via JSON: %v", m.Obj, err)
  712. }
  713. return ret
  714. }
  715. // MockGlobalForwardingRulesObj is used to store the various object versions in the shared
  716. // map of mocked objects. This allows for multiple API versions to co-exist and
  717. // share the same "view" of the objects in the backend.
  718. type MockGlobalForwardingRulesObj struct {
  719. Obj interface{}
  720. }
  721. // ToGA retrieves the given version of the object.
  722. func (m *MockGlobalForwardingRulesObj) ToGA() *ga.ForwardingRule {
  723. if ret, ok := m.Obj.(*ga.ForwardingRule); ok {
  724. return ret
  725. }
  726. // Convert the object via JSON copying to the type that was requested.
  727. ret := &ga.ForwardingRule{}
  728. if err := copyViaJSON(ret, m.Obj); err != nil {
  729. klog.Errorf("Could not convert %T to *ga.ForwardingRule via JSON: %v", m.Obj, err)
  730. }
  731. return ret
  732. }
  733. // MockHealthChecksObj is used to store the various object versions in the shared
  734. // map of mocked objects. This allows for multiple API versions to co-exist and
  735. // share the same "view" of the objects in the backend.
  736. type MockHealthChecksObj struct {
  737. Obj interface{}
  738. }
  739. // ToAlpha retrieves the given version of the object.
  740. func (m *MockHealthChecksObj) ToAlpha() *alpha.HealthCheck {
  741. if ret, ok := m.Obj.(*alpha.HealthCheck); ok {
  742. return ret
  743. }
  744. // Convert the object via JSON copying to the type that was requested.
  745. ret := &alpha.HealthCheck{}
  746. if err := copyViaJSON(ret, m.Obj); err != nil {
  747. klog.Errorf("Could not convert %T to *alpha.HealthCheck via JSON: %v", m.Obj, err)
  748. }
  749. return ret
  750. }
  751. // ToBeta retrieves the given version of the object.
  752. func (m *MockHealthChecksObj) ToBeta() *beta.HealthCheck {
  753. if ret, ok := m.Obj.(*beta.HealthCheck); ok {
  754. return ret
  755. }
  756. // Convert the object via JSON copying to the type that was requested.
  757. ret := &beta.HealthCheck{}
  758. if err := copyViaJSON(ret, m.Obj); err != nil {
  759. klog.Errorf("Could not convert %T to *beta.HealthCheck via JSON: %v", m.Obj, err)
  760. }
  761. return ret
  762. }
  763. // ToGA retrieves the given version of the object.
  764. func (m *MockHealthChecksObj) ToGA() *ga.HealthCheck {
  765. if ret, ok := m.Obj.(*ga.HealthCheck); ok {
  766. return ret
  767. }
  768. // Convert the object via JSON copying to the type that was requested.
  769. ret := &ga.HealthCheck{}
  770. if err := copyViaJSON(ret, m.Obj); err != nil {
  771. klog.Errorf("Could not convert %T to *ga.HealthCheck via JSON: %v", m.Obj, err)
  772. }
  773. return ret
  774. }
  775. // MockHttpHealthChecksObj is used to store the various object versions in the shared
  776. // map of mocked objects. This allows for multiple API versions to co-exist and
  777. // share the same "view" of the objects in the backend.
  778. type MockHttpHealthChecksObj struct {
  779. Obj interface{}
  780. }
  781. // ToGA retrieves the given version of the object.
  782. func (m *MockHttpHealthChecksObj) ToGA() *ga.HttpHealthCheck {
  783. if ret, ok := m.Obj.(*ga.HttpHealthCheck); ok {
  784. return ret
  785. }
  786. // Convert the object via JSON copying to the type that was requested.
  787. ret := &ga.HttpHealthCheck{}
  788. if err := copyViaJSON(ret, m.Obj); err != nil {
  789. klog.Errorf("Could not convert %T to *ga.HttpHealthCheck via JSON: %v", m.Obj, err)
  790. }
  791. return ret
  792. }
  793. // MockHttpsHealthChecksObj is used to store the various object versions in the shared
  794. // map of mocked objects. This allows for multiple API versions to co-exist and
  795. // share the same "view" of the objects in the backend.
  796. type MockHttpsHealthChecksObj struct {
  797. Obj interface{}
  798. }
  799. // ToGA retrieves the given version of the object.
  800. func (m *MockHttpsHealthChecksObj) ToGA() *ga.HttpsHealthCheck {
  801. if ret, ok := m.Obj.(*ga.HttpsHealthCheck); ok {
  802. return ret
  803. }
  804. // Convert the object via JSON copying to the type that was requested.
  805. ret := &ga.HttpsHealthCheck{}
  806. if err := copyViaJSON(ret, m.Obj); err != nil {
  807. klog.Errorf("Could not convert %T to *ga.HttpsHealthCheck via JSON: %v", m.Obj, err)
  808. }
  809. return ret
  810. }
  811. // MockInstanceGroupsObj is used to store the various object versions in the shared
  812. // map of mocked objects. This allows for multiple API versions to co-exist and
  813. // share the same "view" of the objects in the backend.
  814. type MockInstanceGroupsObj struct {
  815. Obj interface{}
  816. }
  817. // ToGA retrieves the given version of the object.
  818. func (m *MockInstanceGroupsObj) ToGA() *ga.InstanceGroup {
  819. if ret, ok := m.Obj.(*ga.InstanceGroup); ok {
  820. return ret
  821. }
  822. // Convert the object via JSON copying to the type that was requested.
  823. ret := &ga.InstanceGroup{}
  824. if err := copyViaJSON(ret, m.Obj); err != nil {
  825. klog.Errorf("Could not convert %T to *ga.InstanceGroup via JSON: %v", m.Obj, err)
  826. }
  827. return ret
  828. }
  829. // MockInstancesObj is used to store the various object versions in the shared
  830. // map of mocked objects. This allows for multiple API versions to co-exist and
  831. // share the same "view" of the objects in the backend.
  832. type MockInstancesObj struct {
  833. Obj interface{}
  834. }
  835. // ToAlpha retrieves the given version of the object.
  836. func (m *MockInstancesObj) ToAlpha() *alpha.Instance {
  837. if ret, ok := m.Obj.(*alpha.Instance); ok {
  838. return ret
  839. }
  840. // Convert the object via JSON copying to the type that was requested.
  841. ret := &alpha.Instance{}
  842. if err := copyViaJSON(ret, m.Obj); err != nil {
  843. klog.Errorf("Could not convert %T to *alpha.Instance via JSON: %v", m.Obj, err)
  844. }
  845. return ret
  846. }
  847. // ToBeta retrieves the given version of the object.
  848. func (m *MockInstancesObj) ToBeta() *beta.Instance {
  849. if ret, ok := m.Obj.(*beta.Instance); ok {
  850. return ret
  851. }
  852. // Convert the object via JSON copying to the type that was requested.
  853. ret := &beta.Instance{}
  854. if err := copyViaJSON(ret, m.Obj); err != nil {
  855. klog.Errorf("Could not convert %T to *beta.Instance via JSON: %v", m.Obj, err)
  856. }
  857. return ret
  858. }
  859. // ToGA retrieves the given version of the object.
  860. func (m *MockInstancesObj) ToGA() *ga.Instance {
  861. if ret, ok := m.Obj.(*ga.Instance); ok {
  862. return ret
  863. }
  864. // Convert the object via JSON copying to the type that was requested.
  865. ret := &ga.Instance{}
  866. if err := copyViaJSON(ret, m.Obj); err != nil {
  867. klog.Errorf("Could not convert %T to *ga.Instance via JSON: %v", m.Obj, err)
  868. }
  869. return ret
  870. }
  871. // MockNetworkEndpointGroupsObj is used to store the various object versions in the shared
  872. // map of mocked objects. This allows for multiple API versions to co-exist and
  873. // share the same "view" of the objects in the backend.
  874. type MockNetworkEndpointGroupsObj struct {
  875. Obj interface{}
  876. }
  877. // ToAlpha retrieves the given version of the object.
  878. func (m *MockNetworkEndpointGroupsObj) ToAlpha() *alpha.NetworkEndpointGroup {
  879. if ret, ok := m.Obj.(*alpha.NetworkEndpointGroup); ok {
  880. return ret
  881. }
  882. // Convert the object via JSON copying to the type that was requested.
  883. ret := &alpha.NetworkEndpointGroup{}
  884. if err := copyViaJSON(ret, m.Obj); err != nil {
  885. klog.Errorf("Could not convert %T to *alpha.NetworkEndpointGroup via JSON: %v", m.Obj, err)
  886. }
  887. return ret
  888. }
  889. // ToBeta retrieves the given version of the object.
  890. func (m *MockNetworkEndpointGroupsObj) ToBeta() *beta.NetworkEndpointGroup {
  891. if ret, ok := m.Obj.(*beta.NetworkEndpointGroup); ok {
  892. return ret
  893. }
  894. // Convert the object via JSON copying to the type that was requested.
  895. ret := &beta.NetworkEndpointGroup{}
  896. if err := copyViaJSON(ret, m.Obj); err != nil {
  897. klog.Errorf("Could not convert %T to *beta.NetworkEndpointGroup via JSON: %v", m.Obj, err)
  898. }
  899. return ret
  900. }
  901. // MockProjectsObj is used to store the various object versions in the shared
  902. // map of mocked objects. This allows for multiple API versions to co-exist and
  903. // share the same "view" of the objects in the backend.
  904. type MockProjectsObj struct {
  905. Obj interface{}
  906. }
  907. // ToGA retrieves the given version of the object.
  908. func (m *MockProjectsObj) ToGA() *ga.Project {
  909. if ret, ok := m.Obj.(*ga.Project); ok {
  910. return ret
  911. }
  912. // Convert the object via JSON copying to the type that was requested.
  913. ret := &ga.Project{}
  914. if err := copyViaJSON(ret, m.Obj); err != nil {
  915. klog.Errorf("Could not convert %T to *ga.Project via JSON: %v", m.Obj, err)
  916. }
  917. return ret
  918. }
  919. // MockRegionBackendServicesObj is used to store the various object versions in the shared
  920. // map of mocked objects. This allows for multiple API versions to co-exist and
  921. // share the same "view" of the objects in the backend.
  922. type MockRegionBackendServicesObj struct {
  923. Obj interface{}
  924. }
  925. // ToAlpha retrieves the given version of the object.
  926. func (m *MockRegionBackendServicesObj) ToAlpha() *alpha.BackendService {
  927. if ret, ok := m.Obj.(*alpha.BackendService); ok {
  928. return ret
  929. }
  930. // Convert the object via JSON copying to the type that was requested.
  931. ret := &alpha.BackendService{}
  932. if err := copyViaJSON(ret, m.Obj); err != nil {
  933. klog.Errorf("Could not convert %T to *alpha.BackendService via JSON: %v", m.Obj, err)
  934. }
  935. return ret
  936. }
  937. // ToGA retrieves the given version of the object.
  938. func (m *MockRegionBackendServicesObj) ToGA() *ga.BackendService {
  939. if ret, ok := m.Obj.(*ga.BackendService); ok {
  940. return ret
  941. }
  942. // Convert the object via JSON copying to the type that was requested.
  943. ret := &ga.BackendService{}
  944. if err := copyViaJSON(ret, m.Obj); err != nil {
  945. klog.Errorf("Could not convert %T to *ga.BackendService via JSON: %v", m.Obj, err)
  946. }
  947. return ret
  948. }
  949. // MockRegionDisksObj is used to store the various object versions in the shared
  950. // map of mocked objects. This allows for multiple API versions to co-exist and
  951. // share the same "view" of the objects in the backend.
  952. type MockRegionDisksObj struct {
  953. Obj interface{}
  954. }
  955. // ToGA retrieves the given version of the object.
  956. func (m *MockRegionDisksObj) ToGA() *ga.Disk {
  957. if ret, ok := m.Obj.(*ga.Disk); ok {
  958. return ret
  959. }
  960. // Convert the object via JSON copying to the type that was requested.
  961. ret := &ga.Disk{}
  962. if err := copyViaJSON(ret, m.Obj); err != nil {
  963. klog.Errorf("Could not convert %T to *ga.Disk via JSON: %v", m.Obj, err)
  964. }
  965. return ret
  966. }
  967. // MockRegionsObj is used to store the various object versions in the shared
  968. // map of mocked objects. This allows for multiple API versions to co-exist and
  969. // share the same "view" of the objects in the backend.
  970. type MockRegionsObj struct {
  971. Obj interface{}
  972. }
  973. // ToGA retrieves the given version of the object.
  974. func (m *MockRegionsObj) ToGA() *ga.Region {
  975. if ret, ok := m.Obj.(*ga.Region); ok {
  976. return ret
  977. }
  978. // Convert the object via JSON copying to the type that was requested.
  979. ret := &ga.Region{}
  980. if err := copyViaJSON(ret, m.Obj); err != nil {
  981. klog.Errorf("Could not convert %T to *ga.Region via JSON: %v", m.Obj, err)
  982. }
  983. return ret
  984. }
  985. // MockRoutesObj is used to store the various object versions in the shared
  986. // map of mocked objects. This allows for multiple API versions to co-exist and
  987. // share the same "view" of the objects in the backend.
  988. type MockRoutesObj struct {
  989. Obj interface{}
  990. }
  991. // ToGA retrieves the given version of the object.
  992. func (m *MockRoutesObj) ToGA() *ga.Route {
  993. if ret, ok := m.Obj.(*ga.Route); ok {
  994. return ret
  995. }
  996. // Convert the object via JSON copying to the type that was requested.
  997. ret := &ga.Route{}
  998. if err := copyViaJSON(ret, m.Obj); err != nil {
  999. klog.Errorf("Could not convert %T to *ga.Route via JSON: %v", m.Obj, err)
  1000. }
  1001. return ret
  1002. }
  1003. // MockSecurityPoliciesObj is used to store the various object versions in the shared
  1004. // map of mocked objects. This allows for multiple API versions to co-exist and
  1005. // share the same "view" of the objects in the backend.
  1006. type MockSecurityPoliciesObj struct {
  1007. Obj interface{}
  1008. }
  1009. // ToBeta retrieves the given version of the object.
  1010. func (m *MockSecurityPoliciesObj) ToBeta() *beta.SecurityPolicy {
  1011. if ret, ok := m.Obj.(*beta.SecurityPolicy); ok {
  1012. return ret
  1013. }
  1014. // Convert the object via JSON copying to the type that was requested.
  1015. ret := &beta.SecurityPolicy{}
  1016. if err := copyViaJSON(ret, m.Obj); err != nil {
  1017. klog.Errorf("Could not convert %T to *beta.SecurityPolicy via JSON: %v", m.Obj, err)
  1018. }
  1019. return ret
  1020. }
  1021. // MockSslCertificatesObj is used to store the various object versions in the shared
  1022. // map of mocked objects. This allows for multiple API versions to co-exist and
  1023. // share the same "view" of the objects in the backend.
  1024. type MockSslCertificatesObj struct {
  1025. Obj interface{}
  1026. }
  1027. // ToGA retrieves the given version of the object.
  1028. func (m *MockSslCertificatesObj) ToGA() *ga.SslCertificate {
  1029. if ret, ok := m.Obj.(*ga.SslCertificate); ok {
  1030. return ret
  1031. }
  1032. // Convert the object via JSON copying to the type that was requested.
  1033. ret := &ga.SslCertificate{}
  1034. if err := copyViaJSON(ret, m.Obj); err != nil {
  1035. klog.Errorf("Could not convert %T to *ga.SslCertificate via JSON: %v", m.Obj, err)
  1036. }
  1037. return ret
  1038. }
  1039. // MockTargetHttpProxiesObj is used to store the various object versions in the shared
  1040. // map of mocked objects. This allows for multiple API versions to co-exist and
  1041. // share the same "view" of the objects in the backend.
  1042. type MockTargetHttpProxiesObj struct {
  1043. Obj interface{}
  1044. }
  1045. // ToGA retrieves the given version of the object.
  1046. func (m *MockTargetHttpProxiesObj) ToGA() *ga.TargetHttpProxy {
  1047. if ret, ok := m.Obj.(*ga.TargetHttpProxy); ok {
  1048. return ret
  1049. }
  1050. // Convert the object via JSON copying to the type that was requested.
  1051. ret := &ga.TargetHttpProxy{}
  1052. if err := copyViaJSON(ret, m.Obj); err != nil {
  1053. klog.Errorf("Could not convert %T to *ga.TargetHttpProxy via JSON: %v", m.Obj, err)
  1054. }
  1055. return ret
  1056. }
  1057. // MockTargetHttpsProxiesObj is used to store the various object versions in the shared
  1058. // map of mocked objects. This allows for multiple API versions to co-exist and
  1059. // share the same "view" of the objects in the backend.
  1060. type MockTargetHttpsProxiesObj struct {
  1061. Obj interface{}
  1062. }
  1063. // ToGA retrieves the given version of the object.
  1064. func (m *MockTargetHttpsProxiesObj) ToGA() *ga.TargetHttpsProxy {
  1065. if ret, ok := m.Obj.(*ga.TargetHttpsProxy); ok {
  1066. return ret
  1067. }
  1068. // Convert the object via JSON copying to the type that was requested.
  1069. ret := &ga.TargetHttpsProxy{}
  1070. if err := copyViaJSON(ret, m.Obj); err != nil {
  1071. klog.Errorf("Could not convert %T to *ga.TargetHttpsProxy via JSON: %v", m.Obj, err)
  1072. }
  1073. return ret
  1074. }
  1075. // MockTargetPoolsObj is used to store the various object versions in the shared
  1076. // map of mocked objects. This allows for multiple API versions to co-exist and
  1077. // share the same "view" of the objects in the backend.
  1078. type MockTargetPoolsObj struct {
  1079. Obj interface{}
  1080. }
  1081. // ToGA retrieves the given version of the object.
  1082. func (m *MockTargetPoolsObj) ToGA() *ga.TargetPool {
  1083. if ret, ok := m.Obj.(*ga.TargetPool); ok {
  1084. return ret
  1085. }
  1086. // Convert the object via JSON copying to the type that was requested.
  1087. ret := &ga.TargetPool{}
  1088. if err := copyViaJSON(ret, m.Obj); err != nil {
  1089. klog.Errorf("Could not convert %T to *ga.TargetPool via JSON: %v", m.Obj, err)
  1090. }
  1091. return ret
  1092. }
  1093. // MockUrlMapsObj is used to store the various object versions in the shared
  1094. // map of mocked objects. This allows for multiple API versions to co-exist and
  1095. // share the same "view" of the objects in the backend.
  1096. type MockUrlMapsObj struct {
  1097. Obj interface{}
  1098. }
  1099. // ToGA retrieves the given version of the object.
  1100. func (m *MockUrlMapsObj) ToGA() *ga.UrlMap {
  1101. if ret, ok := m.Obj.(*ga.UrlMap); ok {
  1102. return ret
  1103. }
  1104. // Convert the object via JSON copying to the type that was requested.
  1105. ret := &ga.UrlMap{}
  1106. if err := copyViaJSON(ret, m.Obj); err != nil {
  1107. klog.Errorf("Could not convert %T to *ga.UrlMap via JSON: %v", m.Obj, err)
  1108. }
  1109. return ret
  1110. }
  1111. // MockZonesObj is used to store the various object versions in the shared
  1112. // map of mocked objects. This allows for multiple API versions to co-exist and
  1113. // share the same "view" of the objects in the backend.
  1114. type MockZonesObj struct {
  1115. Obj interface{}
  1116. }
  1117. // ToGA retrieves the given version of the object.
  1118. func (m *MockZonesObj) ToGA() *ga.Zone {
  1119. if ret, ok := m.Obj.(*ga.Zone); ok {
  1120. return ret
  1121. }
  1122. // Convert the object via JSON copying to the type that was requested.
  1123. ret := &ga.Zone{}
  1124. if err := copyViaJSON(ret, m.Obj); err != nil {
  1125. klog.Errorf("Could not convert %T to *ga.Zone via JSON: %v", m.Obj, err)
  1126. }
  1127. return ret
  1128. }
  1129. // Addresses is an interface that allows for mocking of Addresses.
  1130. type Addresses interface {
  1131. Get(ctx context.Context, key *meta.Key) (*ga.Address, error)
  1132. List(ctx context.Context, region string, fl *filter.F) ([]*ga.Address, error)
  1133. Insert(ctx context.Context, key *meta.Key, obj *ga.Address) error
  1134. Delete(ctx context.Context, key *meta.Key) error
  1135. }
  1136. // NewMockAddresses returns a new mock for Addresses.
  1137. func NewMockAddresses(pr ProjectRouter, objs map[meta.Key]*MockAddressesObj) *MockAddresses {
  1138. mock := &MockAddresses{
  1139. ProjectRouter: pr,
  1140. Objects: objs,
  1141. GetError: map[meta.Key]error{},
  1142. InsertError: map[meta.Key]error{},
  1143. DeleteError: map[meta.Key]error{},
  1144. }
  1145. return mock
  1146. }
  1147. // MockAddresses is the mock for Addresses.
  1148. type MockAddresses struct {
  1149. Lock sync.Mutex
  1150. ProjectRouter ProjectRouter
  1151. // Objects maintained by the mock.
  1152. Objects map[meta.Key]*MockAddressesObj
  1153. // If an entry exists for the given key and operation, then the error
  1154. // will be returned instead of the operation.
  1155. GetError map[meta.Key]error
  1156. ListError *error
  1157. InsertError map[meta.Key]error
  1158. DeleteError map[meta.Key]error
  1159. // xxxHook allow you to intercept the standard processing of the mock in
  1160. // order to add your own logic. Return (true, _, _) to prevent the normal
  1161. // execution flow of the mock. Return (false, nil, nil) to continue with
  1162. // normal mock behavior/ after the hook function executes.
  1163. GetHook func(ctx context.Context, key *meta.Key, m *MockAddresses) (bool, *ga.Address, error)
  1164. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockAddresses) (bool, []*ga.Address, error)
  1165. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.Address, m *MockAddresses) (bool, error)
  1166. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAddresses) (bool, error)
  1167. // X is extra state that can be used as part of the mock. Generated code
  1168. // will not use this field.
  1169. X interface{}
  1170. }
  1171. // Get returns the object from the mock.
  1172. func (m *MockAddresses) Get(ctx context.Context, key *meta.Key) (*ga.Address, error) {
  1173. if m.GetHook != nil {
  1174. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  1175. klog.V(5).Infof("MockAddresses.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  1176. return obj, err
  1177. }
  1178. }
  1179. if !key.Valid() {
  1180. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  1181. }
  1182. m.Lock.Lock()
  1183. defer m.Lock.Unlock()
  1184. if err, ok := m.GetError[*key]; ok {
  1185. klog.V(5).Infof("MockAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  1186. return nil, err
  1187. }
  1188. if obj, ok := m.Objects[*key]; ok {
  1189. typedObj := obj.ToGA()
  1190. klog.V(5).Infof("MockAddresses.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  1191. return typedObj, nil
  1192. }
  1193. err := &googleapi.Error{
  1194. Code: http.StatusNotFound,
  1195. Message: fmt.Sprintf("MockAddresses %v not found", key),
  1196. }
  1197. klog.V(5).Infof("MockAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  1198. return nil, err
  1199. }
  1200. // List all of the objects in the mock in the given region.
  1201. func (m *MockAddresses) List(ctx context.Context, region string, fl *filter.F) ([]*ga.Address, error) {
  1202. if m.ListHook != nil {
  1203. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  1204. klog.V(5).Infof("MockAddresses.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  1205. return objs, err
  1206. }
  1207. }
  1208. m.Lock.Lock()
  1209. defer m.Lock.Unlock()
  1210. if m.ListError != nil {
  1211. err := *m.ListError
  1212. klog.V(5).Infof("MockAddresses.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  1213. return nil, *m.ListError
  1214. }
  1215. var objs []*ga.Address
  1216. for key, obj := range m.Objects {
  1217. if key.Region != region {
  1218. continue
  1219. }
  1220. if !fl.Match(obj.ToGA()) {
  1221. continue
  1222. }
  1223. objs = append(objs, obj.ToGA())
  1224. }
  1225. klog.V(5).Infof("MockAddresses.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  1226. return objs, nil
  1227. }
  1228. // Insert is a mock for inserting/creating a new object.
  1229. func (m *MockAddresses) Insert(ctx context.Context, key *meta.Key, obj *ga.Address) error {
  1230. if m.InsertHook != nil {
  1231. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  1232. klog.V(5).Infof("MockAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1233. return err
  1234. }
  1235. }
  1236. if !key.Valid() {
  1237. return fmt.Errorf("invalid GCE key (%+v)", key)
  1238. }
  1239. m.Lock.Lock()
  1240. defer m.Lock.Unlock()
  1241. if err, ok := m.InsertError[*key]; ok {
  1242. klog.V(5).Infof("MockAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1243. return err
  1244. }
  1245. if _, ok := m.Objects[*key]; ok {
  1246. err := &googleapi.Error{
  1247. Code: http.StatusConflict,
  1248. Message: fmt.Sprintf("MockAddresses %v exists", key),
  1249. }
  1250. klog.V(5).Infof("MockAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1251. return err
  1252. }
  1253. obj.Name = key.Name
  1254. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "addresses")
  1255. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "addresses", key)
  1256. m.Objects[*key] = &MockAddressesObj{obj}
  1257. klog.V(5).Infof("MockAddresses.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  1258. return nil
  1259. }
  1260. // Delete is a mock for deleting the object.
  1261. func (m *MockAddresses) Delete(ctx context.Context, key *meta.Key) error {
  1262. if m.DeleteHook != nil {
  1263. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  1264. klog.V(5).Infof("MockAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1265. return err
  1266. }
  1267. }
  1268. if !key.Valid() {
  1269. return fmt.Errorf("invalid GCE key (%+v)", key)
  1270. }
  1271. m.Lock.Lock()
  1272. defer m.Lock.Unlock()
  1273. if err, ok := m.DeleteError[*key]; ok {
  1274. klog.V(5).Infof("MockAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1275. return err
  1276. }
  1277. if _, ok := m.Objects[*key]; !ok {
  1278. err := &googleapi.Error{
  1279. Code: http.StatusNotFound,
  1280. Message: fmt.Sprintf("MockAddresses %v not found", key),
  1281. }
  1282. klog.V(5).Infof("MockAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1283. return err
  1284. }
  1285. delete(m.Objects, *key)
  1286. klog.V(5).Infof("MockAddresses.Delete(%v, %v) = nil", ctx, key)
  1287. return nil
  1288. }
  1289. // Obj wraps the object for use in the mock.
  1290. func (m *MockAddresses) Obj(o *ga.Address) *MockAddressesObj {
  1291. return &MockAddressesObj{o}
  1292. }
  1293. // GCEAddresses is a simplifying adapter for the GCE Addresses.
  1294. type GCEAddresses struct {
  1295. s *Service
  1296. }
  1297. // Get the Address named by key.
  1298. func (g *GCEAddresses) Get(ctx context.Context, key *meta.Key) (*ga.Address, error) {
  1299. klog.V(5).Infof("GCEAddresses.Get(%v, %v): called", ctx, key)
  1300. if !key.Valid() {
  1301. klog.V(2).Infof("GCEAddresses.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  1302. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  1303. }
  1304. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Addresses")
  1305. rk := &RateLimitKey{
  1306. ProjectID: projectID,
  1307. Operation: "Get",
  1308. Version: meta.Version("ga"),
  1309. Service: "Addresses",
  1310. }
  1311. klog.V(5).Infof("GCEAddresses.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1312. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1313. klog.V(4).Infof("GCEAddresses.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  1314. return nil, err
  1315. }
  1316. call := g.s.GA.Addresses.Get(projectID, key.Region, key.Name)
  1317. call.Context(ctx)
  1318. v, err := call.Do()
  1319. klog.V(4).Infof("GCEAddresses.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  1320. return v, err
  1321. }
  1322. // List all Address objects.
  1323. func (g *GCEAddresses) List(ctx context.Context, region string, fl *filter.F) ([]*ga.Address, error) {
  1324. klog.V(5).Infof("GCEAddresses.List(%v, %v, %v) called", ctx, region, fl)
  1325. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Addresses")
  1326. rk := &RateLimitKey{
  1327. ProjectID: projectID,
  1328. Operation: "List",
  1329. Version: meta.Version("ga"),
  1330. Service: "Addresses",
  1331. }
  1332. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1333. return nil, err
  1334. }
  1335. klog.V(5).Infof("GCEAddresses.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  1336. call := g.s.GA.Addresses.List(projectID, region)
  1337. if fl != filter.None {
  1338. call.Filter(fl.String())
  1339. }
  1340. var all []*ga.Address
  1341. f := func(l *ga.AddressList) error {
  1342. klog.V(5).Infof("GCEAddresses.List(%v, ..., %v): page %+v", ctx, fl, l)
  1343. all = append(all, l.Items...)
  1344. return nil
  1345. }
  1346. if err := call.Pages(ctx, f); err != nil {
  1347. klog.V(4).Infof("GCEAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  1348. return nil, err
  1349. }
  1350. if klog.V(4) {
  1351. klog.V(4).Infof("GCEAddresses.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  1352. } else if klog.V(5) {
  1353. var asStr []string
  1354. for _, o := range all {
  1355. asStr = append(asStr, fmt.Sprintf("%+v", o))
  1356. }
  1357. klog.V(5).Infof("GCEAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  1358. }
  1359. return all, nil
  1360. }
  1361. // Insert Address with key of value obj.
  1362. func (g *GCEAddresses) Insert(ctx context.Context, key *meta.Key, obj *ga.Address) error {
  1363. klog.V(5).Infof("GCEAddresses.Insert(%v, %v, %+v): called", ctx, key, obj)
  1364. if !key.Valid() {
  1365. klog.V(2).Infof("GCEAddresses.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  1366. return fmt.Errorf("invalid GCE key (%+v)", key)
  1367. }
  1368. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Addresses")
  1369. rk := &RateLimitKey{
  1370. ProjectID: projectID,
  1371. Operation: "Insert",
  1372. Version: meta.Version("ga"),
  1373. Service: "Addresses",
  1374. }
  1375. klog.V(5).Infof("GCEAddresses.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1376. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1377. klog.V(4).Infof("GCEAddresses.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  1378. return err
  1379. }
  1380. obj.Name = key.Name
  1381. call := g.s.GA.Addresses.Insert(projectID, key.Region, obj)
  1382. call.Context(ctx)
  1383. op, err := call.Do()
  1384. if err != nil {
  1385. klog.V(4).Infof("GCEAddresses.Insert(%v, %v, ...) = %+v", ctx, key, err)
  1386. return err
  1387. }
  1388. err = g.s.WaitForCompletion(ctx, op)
  1389. klog.V(4).Infof("GCEAddresses.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  1390. return err
  1391. }
  1392. // Delete the Address referenced by key.
  1393. func (g *GCEAddresses) Delete(ctx context.Context, key *meta.Key) error {
  1394. klog.V(5).Infof("GCEAddresses.Delete(%v, %v): called", ctx, key)
  1395. if !key.Valid() {
  1396. klog.V(2).Infof("GCEAddresses.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  1397. return fmt.Errorf("invalid GCE key (%+v)", key)
  1398. }
  1399. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Addresses")
  1400. rk := &RateLimitKey{
  1401. ProjectID: projectID,
  1402. Operation: "Delete",
  1403. Version: meta.Version("ga"),
  1404. Service: "Addresses",
  1405. }
  1406. klog.V(5).Infof("GCEAddresses.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1407. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1408. klog.V(4).Infof("GCEAddresses.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  1409. return err
  1410. }
  1411. call := g.s.GA.Addresses.Delete(projectID, key.Region, key.Name)
  1412. call.Context(ctx)
  1413. op, err := call.Do()
  1414. if err != nil {
  1415. klog.V(4).Infof("GCEAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1416. return err
  1417. }
  1418. err = g.s.WaitForCompletion(ctx, op)
  1419. klog.V(4).Infof("GCEAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1420. return err
  1421. }
  1422. // AlphaAddresses is an interface that allows for mocking of Addresses.
  1423. type AlphaAddresses interface {
  1424. Get(ctx context.Context, key *meta.Key) (*alpha.Address, error)
  1425. List(ctx context.Context, region string, fl *filter.F) ([]*alpha.Address, error)
  1426. Insert(ctx context.Context, key *meta.Key, obj *alpha.Address) error
  1427. Delete(ctx context.Context, key *meta.Key) error
  1428. }
  1429. // NewMockAlphaAddresses returns a new mock for Addresses.
  1430. func NewMockAlphaAddresses(pr ProjectRouter, objs map[meta.Key]*MockAddressesObj) *MockAlphaAddresses {
  1431. mock := &MockAlphaAddresses{
  1432. ProjectRouter: pr,
  1433. Objects: objs,
  1434. GetError: map[meta.Key]error{},
  1435. InsertError: map[meta.Key]error{},
  1436. DeleteError: map[meta.Key]error{},
  1437. }
  1438. return mock
  1439. }
  1440. // MockAlphaAddresses is the mock for Addresses.
  1441. type MockAlphaAddresses struct {
  1442. Lock sync.Mutex
  1443. ProjectRouter ProjectRouter
  1444. // Objects maintained by the mock.
  1445. Objects map[meta.Key]*MockAddressesObj
  1446. // If an entry exists for the given key and operation, then the error
  1447. // will be returned instead of the operation.
  1448. GetError map[meta.Key]error
  1449. ListError *error
  1450. InsertError map[meta.Key]error
  1451. DeleteError map[meta.Key]error
  1452. // xxxHook allow you to intercept the standard processing of the mock in
  1453. // order to add your own logic. Return (true, _, _) to prevent the normal
  1454. // execution flow of the mock. Return (false, nil, nil) to continue with
  1455. // normal mock behavior/ after the hook function executes.
  1456. GetHook func(ctx context.Context, key *meta.Key, m *MockAlphaAddresses) (bool, *alpha.Address, error)
  1457. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockAlphaAddresses) (bool, []*alpha.Address, error)
  1458. InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.Address, m *MockAlphaAddresses) (bool, error)
  1459. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaAddresses) (bool, error)
  1460. // X is extra state that can be used as part of the mock. Generated code
  1461. // will not use this field.
  1462. X interface{}
  1463. }
  1464. // Get returns the object from the mock.
  1465. func (m *MockAlphaAddresses) Get(ctx context.Context, key *meta.Key) (*alpha.Address, error) {
  1466. if m.GetHook != nil {
  1467. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  1468. klog.V(5).Infof("MockAlphaAddresses.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  1469. return obj, err
  1470. }
  1471. }
  1472. if !key.Valid() {
  1473. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  1474. }
  1475. m.Lock.Lock()
  1476. defer m.Lock.Unlock()
  1477. if err, ok := m.GetError[*key]; ok {
  1478. klog.V(5).Infof("MockAlphaAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  1479. return nil, err
  1480. }
  1481. if obj, ok := m.Objects[*key]; ok {
  1482. typedObj := obj.ToAlpha()
  1483. klog.V(5).Infof("MockAlphaAddresses.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  1484. return typedObj, nil
  1485. }
  1486. err := &googleapi.Error{
  1487. Code: http.StatusNotFound,
  1488. Message: fmt.Sprintf("MockAlphaAddresses %v not found", key),
  1489. }
  1490. klog.V(5).Infof("MockAlphaAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  1491. return nil, err
  1492. }
  1493. // List all of the objects in the mock in the given region.
  1494. func (m *MockAlphaAddresses) List(ctx context.Context, region string, fl *filter.F) ([]*alpha.Address, error) {
  1495. if m.ListHook != nil {
  1496. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  1497. klog.V(5).Infof("MockAlphaAddresses.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  1498. return objs, err
  1499. }
  1500. }
  1501. m.Lock.Lock()
  1502. defer m.Lock.Unlock()
  1503. if m.ListError != nil {
  1504. err := *m.ListError
  1505. klog.V(5).Infof("MockAlphaAddresses.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  1506. return nil, *m.ListError
  1507. }
  1508. var objs []*alpha.Address
  1509. for key, obj := range m.Objects {
  1510. if key.Region != region {
  1511. continue
  1512. }
  1513. if !fl.Match(obj.ToAlpha()) {
  1514. continue
  1515. }
  1516. objs = append(objs, obj.ToAlpha())
  1517. }
  1518. klog.V(5).Infof("MockAlphaAddresses.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  1519. return objs, nil
  1520. }
  1521. // Insert is a mock for inserting/creating a new object.
  1522. func (m *MockAlphaAddresses) Insert(ctx context.Context, key *meta.Key, obj *alpha.Address) error {
  1523. if m.InsertHook != nil {
  1524. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  1525. klog.V(5).Infof("MockAlphaAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1526. return err
  1527. }
  1528. }
  1529. if !key.Valid() {
  1530. return fmt.Errorf("invalid GCE key (%+v)", key)
  1531. }
  1532. m.Lock.Lock()
  1533. defer m.Lock.Unlock()
  1534. if err, ok := m.InsertError[*key]; ok {
  1535. klog.V(5).Infof("MockAlphaAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1536. return err
  1537. }
  1538. if _, ok := m.Objects[*key]; ok {
  1539. err := &googleapi.Error{
  1540. Code: http.StatusConflict,
  1541. Message: fmt.Sprintf("MockAlphaAddresses %v exists", key),
  1542. }
  1543. klog.V(5).Infof("MockAlphaAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1544. return err
  1545. }
  1546. obj.Name = key.Name
  1547. projectID := m.ProjectRouter.ProjectID(ctx, "alpha", "addresses")
  1548. obj.SelfLink = SelfLink(meta.VersionAlpha, projectID, "addresses", key)
  1549. m.Objects[*key] = &MockAddressesObj{obj}
  1550. klog.V(5).Infof("MockAlphaAddresses.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  1551. return nil
  1552. }
  1553. // Delete is a mock for deleting the object.
  1554. func (m *MockAlphaAddresses) Delete(ctx context.Context, key *meta.Key) error {
  1555. if m.DeleteHook != nil {
  1556. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  1557. klog.V(5).Infof("MockAlphaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1558. return err
  1559. }
  1560. }
  1561. if !key.Valid() {
  1562. return fmt.Errorf("invalid GCE key (%+v)", key)
  1563. }
  1564. m.Lock.Lock()
  1565. defer m.Lock.Unlock()
  1566. if err, ok := m.DeleteError[*key]; ok {
  1567. klog.V(5).Infof("MockAlphaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1568. return err
  1569. }
  1570. if _, ok := m.Objects[*key]; !ok {
  1571. err := &googleapi.Error{
  1572. Code: http.StatusNotFound,
  1573. Message: fmt.Sprintf("MockAlphaAddresses %v not found", key),
  1574. }
  1575. klog.V(5).Infof("MockAlphaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1576. return err
  1577. }
  1578. delete(m.Objects, *key)
  1579. klog.V(5).Infof("MockAlphaAddresses.Delete(%v, %v) = nil", ctx, key)
  1580. return nil
  1581. }
  1582. // Obj wraps the object for use in the mock.
  1583. func (m *MockAlphaAddresses) Obj(o *alpha.Address) *MockAddressesObj {
  1584. return &MockAddressesObj{o}
  1585. }
  1586. // GCEAlphaAddresses is a simplifying adapter for the GCE Addresses.
  1587. type GCEAlphaAddresses struct {
  1588. s *Service
  1589. }
  1590. // Get the Address named by key.
  1591. func (g *GCEAlphaAddresses) Get(ctx context.Context, key *meta.Key) (*alpha.Address, error) {
  1592. klog.V(5).Infof("GCEAlphaAddresses.Get(%v, %v): called", ctx, key)
  1593. if !key.Valid() {
  1594. klog.V(2).Infof("GCEAlphaAddresses.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  1595. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  1596. }
  1597. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Addresses")
  1598. rk := &RateLimitKey{
  1599. ProjectID: projectID,
  1600. Operation: "Get",
  1601. Version: meta.Version("alpha"),
  1602. Service: "Addresses",
  1603. }
  1604. klog.V(5).Infof("GCEAlphaAddresses.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1605. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1606. klog.V(4).Infof("GCEAlphaAddresses.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  1607. return nil, err
  1608. }
  1609. call := g.s.Alpha.Addresses.Get(projectID, key.Region, key.Name)
  1610. call.Context(ctx)
  1611. v, err := call.Do()
  1612. klog.V(4).Infof("GCEAlphaAddresses.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  1613. return v, err
  1614. }
  1615. // List all Address objects.
  1616. func (g *GCEAlphaAddresses) List(ctx context.Context, region string, fl *filter.F) ([]*alpha.Address, error) {
  1617. klog.V(5).Infof("GCEAlphaAddresses.List(%v, %v, %v) called", ctx, region, fl)
  1618. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Addresses")
  1619. rk := &RateLimitKey{
  1620. ProjectID: projectID,
  1621. Operation: "List",
  1622. Version: meta.Version("alpha"),
  1623. Service: "Addresses",
  1624. }
  1625. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1626. return nil, err
  1627. }
  1628. klog.V(5).Infof("GCEAlphaAddresses.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  1629. call := g.s.Alpha.Addresses.List(projectID, region)
  1630. if fl != filter.None {
  1631. call.Filter(fl.String())
  1632. }
  1633. var all []*alpha.Address
  1634. f := func(l *alpha.AddressList) error {
  1635. klog.V(5).Infof("GCEAlphaAddresses.List(%v, ..., %v): page %+v", ctx, fl, l)
  1636. all = append(all, l.Items...)
  1637. return nil
  1638. }
  1639. if err := call.Pages(ctx, f); err != nil {
  1640. klog.V(4).Infof("GCEAlphaAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  1641. return nil, err
  1642. }
  1643. if klog.V(4) {
  1644. klog.V(4).Infof("GCEAlphaAddresses.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  1645. } else if klog.V(5) {
  1646. var asStr []string
  1647. for _, o := range all {
  1648. asStr = append(asStr, fmt.Sprintf("%+v", o))
  1649. }
  1650. klog.V(5).Infof("GCEAlphaAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  1651. }
  1652. return all, nil
  1653. }
  1654. // Insert Address with key of value obj.
  1655. func (g *GCEAlphaAddresses) Insert(ctx context.Context, key *meta.Key, obj *alpha.Address) error {
  1656. klog.V(5).Infof("GCEAlphaAddresses.Insert(%v, %v, %+v): called", ctx, key, obj)
  1657. if !key.Valid() {
  1658. klog.V(2).Infof("GCEAlphaAddresses.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  1659. return fmt.Errorf("invalid GCE key (%+v)", key)
  1660. }
  1661. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Addresses")
  1662. rk := &RateLimitKey{
  1663. ProjectID: projectID,
  1664. Operation: "Insert",
  1665. Version: meta.Version("alpha"),
  1666. Service: "Addresses",
  1667. }
  1668. klog.V(5).Infof("GCEAlphaAddresses.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1669. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1670. klog.V(4).Infof("GCEAlphaAddresses.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  1671. return err
  1672. }
  1673. obj.Name = key.Name
  1674. call := g.s.Alpha.Addresses.Insert(projectID, key.Region, obj)
  1675. call.Context(ctx)
  1676. op, err := call.Do()
  1677. if err != nil {
  1678. klog.V(4).Infof("GCEAlphaAddresses.Insert(%v, %v, ...) = %+v", ctx, key, err)
  1679. return err
  1680. }
  1681. err = g.s.WaitForCompletion(ctx, op)
  1682. klog.V(4).Infof("GCEAlphaAddresses.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  1683. return err
  1684. }
  1685. // Delete the Address referenced by key.
  1686. func (g *GCEAlphaAddresses) Delete(ctx context.Context, key *meta.Key) error {
  1687. klog.V(5).Infof("GCEAlphaAddresses.Delete(%v, %v): called", ctx, key)
  1688. if !key.Valid() {
  1689. klog.V(2).Infof("GCEAlphaAddresses.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  1690. return fmt.Errorf("invalid GCE key (%+v)", key)
  1691. }
  1692. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Addresses")
  1693. rk := &RateLimitKey{
  1694. ProjectID: projectID,
  1695. Operation: "Delete",
  1696. Version: meta.Version("alpha"),
  1697. Service: "Addresses",
  1698. }
  1699. klog.V(5).Infof("GCEAlphaAddresses.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1700. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1701. klog.V(4).Infof("GCEAlphaAddresses.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  1702. return err
  1703. }
  1704. call := g.s.Alpha.Addresses.Delete(projectID, key.Region, key.Name)
  1705. call.Context(ctx)
  1706. op, err := call.Do()
  1707. if err != nil {
  1708. klog.V(4).Infof("GCEAlphaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1709. return err
  1710. }
  1711. err = g.s.WaitForCompletion(ctx, op)
  1712. klog.V(4).Infof("GCEAlphaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1713. return err
  1714. }
  1715. // BetaAddresses is an interface that allows for mocking of Addresses.
  1716. type BetaAddresses interface {
  1717. Get(ctx context.Context, key *meta.Key) (*beta.Address, error)
  1718. List(ctx context.Context, region string, fl *filter.F) ([]*beta.Address, error)
  1719. Insert(ctx context.Context, key *meta.Key, obj *beta.Address) error
  1720. Delete(ctx context.Context, key *meta.Key) error
  1721. }
  1722. // NewMockBetaAddresses returns a new mock for Addresses.
  1723. func NewMockBetaAddresses(pr ProjectRouter, objs map[meta.Key]*MockAddressesObj) *MockBetaAddresses {
  1724. mock := &MockBetaAddresses{
  1725. ProjectRouter: pr,
  1726. Objects: objs,
  1727. GetError: map[meta.Key]error{},
  1728. InsertError: map[meta.Key]error{},
  1729. DeleteError: map[meta.Key]error{},
  1730. }
  1731. return mock
  1732. }
  1733. // MockBetaAddresses is the mock for Addresses.
  1734. type MockBetaAddresses struct {
  1735. Lock sync.Mutex
  1736. ProjectRouter ProjectRouter
  1737. // Objects maintained by the mock.
  1738. Objects map[meta.Key]*MockAddressesObj
  1739. // If an entry exists for the given key and operation, then the error
  1740. // will be returned instead of the operation.
  1741. GetError map[meta.Key]error
  1742. ListError *error
  1743. InsertError map[meta.Key]error
  1744. DeleteError map[meta.Key]error
  1745. // xxxHook allow you to intercept the standard processing of the mock in
  1746. // order to add your own logic. Return (true, _, _) to prevent the normal
  1747. // execution flow of the mock. Return (false, nil, nil) to continue with
  1748. // normal mock behavior/ after the hook function executes.
  1749. GetHook func(ctx context.Context, key *meta.Key, m *MockBetaAddresses) (bool, *beta.Address, error)
  1750. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockBetaAddresses) (bool, []*beta.Address, error)
  1751. InsertHook func(ctx context.Context, key *meta.Key, obj *beta.Address, m *MockBetaAddresses) (bool, error)
  1752. DeleteHook func(ctx context.Context, key *meta.Key, m *MockBetaAddresses) (bool, error)
  1753. // X is extra state that can be used as part of the mock. Generated code
  1754. // will not use this field.
  1755. X interface{}
  1756. }
  1757. // Get returns the object from the mock.
  1758. func (m *MockBetaAddresses) Get(ctx context.Context, key *meta.Key) (*beta.Address, error) {
  1759. if m.GetHook != nil {
  1760. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  1761. klog.V(5).Infof("MockBetaAddresses.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  1762. return obj, err
  1763. }
  1764. }
  1765. if !key.Valid() {
  1766. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  1767. }
  1768. m.Lock.Lock()
  1769. defer m.Lock.Unlock()
  1770. if err, ok := m.GetError[*key]; ok {
  1771. klog.V(5).Infof("MockBetaAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  1772. return nil, err
  1773. }
  1774. if obj, ok := m.Objects[*key]; ok {
  1775. typedObj := obj.ToBeta()
  1776. klog.V(5).Infof("MockBetaAddresses.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  1777. return typedObj, nil
  1778. }
  1779. err := &googleapi.Error{
  1780. Code: http.StatusNotFound,
  1781. Message: fmt.Sprintf("MockBetaAddresses %v not found", key),
  1782. }
  1783. klog.V(5).Infof("MockBetaAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  1784. return nil, err
  1785. }
  1786. // List all of the objects in the mock in the given region.
  1787. func (m *MockBetaAddresses) List(ctx context.Context, region string, fl *filter.F) ([]*beta.Address, error) {
  1788. if m.ListHook != nil {
  1789. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  1790. klog.V(5).Infof("MockBetaAddresses.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  1791. return objs, err
  1792. }
  1793. }
  1794. m.Lock.Lock()
  1795. defer m.Lock.Unlock()
  1796. if m.ListError != nil {
  1797. err := *m.ListError
  1798. klog.V(5).Infof("MockBetaAddresses.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  1799. return nil, *m.ListError
  1800. }
  1801. var objs []*beta.Address
  1802. for key, obj := range m.Objects {
  1803. if key.Region != region {
  1804. continue
  1805. }
  1806. if !fl.Match(obj.ToBeta()) {
  1807. continue
  1808. }
  1809. objs = append(objs, obj.ToBeta())
  1810. }
  1811. klog.V(5).Infof("MockBetaAddresses.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  1812. return objs, nil
  1813. }
  1814. // Insert is a mock for inserting/creating a new object.
  1815. func (m *MockBetaAddresses) Insert(ctx context.Context, key *meta.Key, obj *beta.Address) error {
  1816. if m.InsertHook != nil {
  1817. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  1818. klog.V(5).Infof("MockBetaAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1819. return err
  1820. }
  1821. }
  1822. if !key.Valid() {
  1823. return fmt.Errorf("invalid GCE key (%+v)", key)
  1824. }
  1825. m.Lock.Lock()
  1826. defer m.Lock.Unlock()
  1827. if err, ok := m.InsertError[*key]; ok {
  1828. klog.V(5).Infof("MockBetaAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1829. return err
  1830. }
  1831. if _, ok := m.Objects[*key]; ok {
  1832. err := &googleapi.Error{
  1833. Code: http.StatusConflict,
  1834. Message: fmt.Sprintf("MockBetaAddresses %v exists", key),
  1835. }
  1836. klog.V(5).Infof("MockBetaAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  1837. return err
  1838. }
  1839. obj.Name = key.Name
  1840. projectID := m.ProjectRouter.ProjectID(ctx, "beta", "addresses")
  1841. obj.SelfLink = SelfLink(meta.VersionBeta, projectID, "addresses", key)
  1842. m.Objects[*key] = &MockAddressesObj{obj}
  1843. klog.V(5).Infof("MockBetaAddresses.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  1844. return nil
  1845. }
  1846. // Delete is a mock for deleting the object.
  1847. func (m *MockBetaAddresses) Delete(ctx context.Context, key *meta.Key) error {
  1848. if m.DeleteHook != nil {
  1849. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  1850. klog.V(5).Infof("MockBetaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1851. return err
  1852. }
  1853. }
  1854. if !key.Valid() {
  1855. return fmt.Errorf("invalid GCE key (%+v)", key)
  1856. }
  1857. m.Lock.Lock()
  1858. defer m.Lock.Unlock()
  1859. if err, ok := m.DeleteError[*key]; ok {
  1860. klog.V(5).Infof("MockBetaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1861. return err
  1862. }
  1863. if _, ok := m.Objects[*key]; !ok {
  1864. err := &googleapi.Error{
  1865. Code: http.StatusNotFound,
  1866. Message: fmt.Sprintf("MockBetaAddresses %v not found", key),
  1867. }
  1868. klog.V(5).Infof("MockBetaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  1869. return err
  1870. }
  1871. delete(m.Objects, *key)
  1872. klog.V(5).Infof("MockBetaAddresses.Delete(%v, %v) = nil", ctx, key)
  1873. return nil
  1874. }
  1875. // Obj wraps the object for use in the mock.
  1876. func (m *MockBetaAddresses) Obj(o *beta.Address) *MockAddressesObj {
  1877. return &MockAddressesObj{o}
  1878. }
  1879. // GCEBetaAddresses is a simplifying adapter for the GCE Addresses.
  1880. type GCEBetaAddresses struct {
  1881. s *Service
  1882. }
  1883. // Get the Address named by key.
  1884. func (g *GCEBetaAddresses) Get(ctx context.Context, key *meta.Key) (*beta.Address, error) {
  1885. klog.V(5).Infof("GCEBetaAddresses.Get(%v, %v): called", ctx, key)
  1886. if !key.Valid() {
  1887. klog.V(2).Infof("GCEBetaAddresses.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  1888. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  1889. }
  1890. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Addresses")
  1891. rk := &RateLimitKey{
  1892. ProjectID: projectID,
  1893. Operation: "Get",
  1894. Version: meta.Version("beta"),
  1895. Service: "Addresses",
  1896. }
  1897. klog.V(5).Infof("GCEBetaAddresses.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1898. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1899. klog.V(4).Infof("GCEBetaAddresses.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  1900. return nil, err
  1901. }
  1902. call := g.s.Beta.Addresses.Get(projectID, key.Region, key.Name)
  1903. call.Context(ctx)
  1904. v, err := call.Do()
  1905. klog.V(4).Infof("GCEBetaAddresses.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  1906. return v, err
  1907. }
  1908. // List all Address objects.
  1909. func (g *GCEBetaAddresses) List(ctx context.Context, region string, fl *filter.F) ([]*beta.Address, error) {
  1910. klog.V(5).Infof("GCEBetaAddresses.List(%v, %v, %v) called", ctx, region, fl)
  1911. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Addresses")
  1912. rk := &RateLimitKey{
  1913. ProjectID: projectID,
  1914. Operation: "List",
  1915. Version: meta.Version("beta"),
  1916. Service: "Addresses",
  1917. }
  1918. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1919. return nil, err
  1920. }
  1921. klog.V(5).Infof("GCEBetaAddresses.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  1922. call := g.s.Beta.Addresses.List(projectID, region)
  1923. if fl != filter.None {
  1924. call.Filter(fl.String())
  1925. }
  1926. var all []*beta.Address
  1927. f := func(l *beta.AddressList) error {
  1928. klog.V(5).Infof("GCEBetaAddresses.List(%v, ..., %v): page %+v", ctx, fl, l)
  1929. all = append(all, l.Items...)
  1930. return nil
  1931. }
  1932. if err := call.Pages(ctx, f); err != nil {
  1933. klog.V(4).Infof("GCEBetaAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  1934. return nil, err
  1935. }
  1936. if klog.V(4) {
  1937. klog.V(4).Infof("GCEBetaAddresses.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  1938. } else if klog.V(5) {
  1939. var asStr []string
  1940. for _, o := range all {
  1941. asStr = append(asStr, fmt.Sprintf("%+v", o))
  1942. }
  1943. klog.V(5).Infof("GCEBetaAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  1944. }
  1945. return all, nil
  1946. }
  1947. // Insert Address with key of value obj.
  1948. func (g *GCEBetaAddresses) Insert(ctx context.Context, key *meta.Key, obj *beta.Address) error {
  1949. klog.V(5).Infof("GCEBetaAddresses.Insert(%v, %v, %+v): called", ctx, key, obj)
  1950. if !key.Valid() {
  1951. klog.V(2).Infof("GCEBetaAddresses.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  1952. return fmt.Errorf("invalid GCE key (%+v)", key)
  1953. }
  1954. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Addresses")
  1955. rk := &RateLimitKey{
  1956. ProjectID: projectID,
  1957. Operation: "Insert",
  1958. Version: meta.Version("beta"),
  1959. Service: "Addresses",
  1960. }
  1961. klog.V(5).Infof("GCEBetaAddresses.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1962. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1963. klog.V(4).Infof("GCEBetaAddresses.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  1964. return err
  1965. }
  1966. obj.Name = key.Name
  1967. call := g.s.Beta.Addresses.Insert(projectID, key.Region, obj)
  1968. call.Context(ctx)
  1969. op, err := call.Do()
  1970. if err != nil {
  1971. klog.V(4).Infof("GCEBetaAddresses.Insert(%v, %v, ...) = %+v", ctx, key, err)
  1972. return err
  1973. }
  1974. err = g.s.WaitForCompletion(ctx, op)
  1975. klog.V(4).Infof("GCEBetaAddresses.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  1976. return err
  1977. }
  1978. // Delete the Address referenced by key.
  1979. func (g *GCEBetaAddresses) Delete(ctx context.Context, key *meta.Key) error {
  1980. klog.V(5).Infof("GCEBetaAddresses.Delete(%v, %v): called", ctx, key)
  1981. if !key.Valid() {
  1982. klog.V(2).Infof("GCEBetaAddresses.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  1983. return fmt.Errorf("invalid GCE key (%+v)", key)
  1984. }
  1985. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Addresses")
  1986. rk := &RateLimitKey{
  1987. ProjectID: projectID,
  1988. Operation: "Delete",
  1989. Version: meta.Version("beta"),
  1990. Service: "Addresses",
  1991. }
  1992. klog.V(5).Infof("GCEBetaAddresses.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  1993. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  1994. klog.V(4).Infof("GCEBetaAddresses.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  1995. return err
  1996. }
  1997. call := g.s.Beta.Addresses.Delete(projectID, key.Region, key.Name)
  1998. call.Context(ctx)
  1999. op, err := call.Do()
  2000. if err != nil {
  2001. klog.V(4).Infof("GCEBetaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  2002. return err
  2003. }
  2004. err = g.s.WaitForCompletion(ctx, op)
  2005. klog.V(4).Infof("GCEBetaAddresses.Delete(%v, %v) = %v", ctx, key, err)
  2006. return err
  2007. }
  2008. // GlobalAddresses is an interface that allows for mocking of GlobalAddresses.
  2009. type GlobalAddresses interface {
  2010. Get(ctx context.Context, key *meta.Key) (*ga.Address, error)
  2011. List(ctx context.Context, fl *filter.F) ([]*ga.Address, error)
  2012. Insert(ctx context.Context, key *meta.Key, obj *ga.Address) error
  2013. Delete(ctx context.Context, key *meta.Key) error
  2014. }
  2015. // NewMockGlobalAddresses returns a new mock for GlobalAddresses.
  2016. func NewMockGlobalAddresses(pr ProjectRouter, objs map[meta.Key]*MockGlobalAddressesObj) *MockGlobalAddresses {
  2017. mock := &MockGlobalAddresses{
  2018. ProjectRouter: pr,
  2019. Objects: objs,
  2020. GetError: map[meta.Key]error{},
  2021. InsertError: map[meta.Key]error{},
  2022. DeleteError: map[meta.Key]error{},
  2023. }
  2024. return mock
  2025. }
  2026. // MockGlobalAddresses is the mock for GlobalAddresses.
  2027. type MockGlobalAddresses struct {
  2028. Lock sync.Mutex
  2029. ProjectRouter ProjectRouter
  2030. // Objects maintained by the mock.
  2031. Objects map[meta.Key]*MockGlobalAddressesObj
  2032. // If an entry exists for the given key and operation, then the error
  2033. // will be returned instead of the operation.
  2034. GetError map[meta.Key]error
  2035. ListError *error
  2036. InsertError map[meta.Key]error
  2037. DeleteError map[meta.Key]error
  2038. // xxxHook allow you to intercept the standard processing of the mock in
  2039. // order to add your own logic. Return (true, _, _) to prevent the normal
  2040. // execution flow of the mock. Return (false, nil, nil) to continue with
  2041. // normal mock behavior/ after the hook function executes.
  2042. GetHook func(ctx context.Context, key *meta.Key, m *MockGlobalAddresses) (bool, *ga.Address, error)
  2043. ListHook func(ctx context.Context, fl *filter.F, m *MockGlobalAddresses) (bool, []*ga.Address, error)
  2044. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.Address, m *MockGlobalAddresses) (bool, error)
  2045. DeleteHook func(ctx context.Context, key *meta.Key, m *MockGlobalAddresses) (bool, error)
  2046. // X is extra state that can be used as part of the mock. Generated code
  2047. // will not use this field.
  2048. X interface{}
  2049. }
  2050. // Get returns the object from the mock.
  2051. func (m *MockGlobalAddresses) Get(ctx context.Context, key *meta.Key) (*ga.Address, error) {
  2052. if m.GetHook != nil {
  2053. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  2054. klog.V(5).Infof("MockGlobalAddresses.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  2055. return obj, err
  2056. }
  2057. }
  2058. if !key.Valid() {
  2059. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  2060. }
  2061. m.Lock.Lock()
  2062. defer m.Lock.Unlock()
  2063. if err, ok := m.GetError[*key]; ok {
  2064. klog.V(5).Infof("MockGlobalAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  2065. return nil, err
  2066. }
  2067. if obj, ok := m.Objects[*key]; ok {
  2068. typedObj := obj.ToGA()
  2069. klog.V(5).Infof("MockGlobalAddresses.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  2070. return typedObj, nil
  2071. }
  2072. err := &googleapi.Error{
  2073. Code: http.StatusNotFound,
  2074. Message: fmt.Sprintf("MockGlobalAddresses %v not found", key),
  2075. }
  2076. klog.V(5).Infof("MockGlobalAddresses.Get(%v, %s) = nil, %v", ctx, key, err)
  2077. return nil, err
  2078. }
  2079. // List all of the objects in the mock.
  2080. func (m *MockGlobalAddresses) List(ctx context.Context, fl *filter.F) ([]*ga.Address, error) {
  2081. if m.ListHook != nil {
  2082. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  2083. klog.V(5).Infof("MockGlobalAddresses.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  2084. return objs, err
  2085. }
  2086. }
  2087. m.Lock.Lock()
  2088. defer m.Lock.Unlock()
  2089. if m.ListError != nil {
  2090. err := *m.ListError
  2091. klog.V(5).Infof("MockGlobalAddresses.List(%v, %v) = nil, %v", ctx, fl, err)
  2092. return nil, *m.ListError
  2093. }
  2094. var objs []*ga.Address
  2095. for _, obj := range m.Objects {
  2096. if !fl.Match(obj.ToGA()) {
  2097. continue
  2098. }
  2099. objs = append(objs, obj.ToGA())
  2100. }
  2101. klog.V(5).Infof("MockGlobalAddresses.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  2102. return objs, nil
  2103. }
  2104. // Insert is a mock for inserting/creating a new object.
  2105. func (m *MockGlobalAddresses) Insert(ctx context.Context, key *meta.Key, obj *ga.Address) error {
  2106. if m.InsertHook != nil {
  2107. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  2108. klog.V(5).Infof("MockGlobalAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2109. return err
  2110. }
  2111. }
  2112. if !key.Valid() {
  2113. return fmt.Errorf("invalid GCE key (%+v)", key)
  2114. }
  2115. m.Lock.Lock()
  2116. defer m.Lock.Unlock()
  2117. if err, ok := m.InsertError[*key]; ok {
  2118. klog.V(5).Infof("MockGlobalAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2119. return err
  2120. }
  2121. if _, ok := m.Objects[*key]; ok {
  2122. err := &googleapi.Error{
  2123. Code: http.StatusConflict,
  2124. Message: fmt.Sprintf("MockGlobalAddresses %v exists", key),
  2125. }
  2126. klog.V(5).Infof("MockGlobalAddresses.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2127. return err
  2128. }
  2129. obj.Name = key.Name
  2130. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "addresses")
  2131. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "addresses", key)
  2132. m.Objects[*key] = &MockGlobalAddressesObj{obj}
  2133. klog.V(5).Infof("MockGlobalAddresses.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  2134. return nil
  2135. }
  2136. // Delete is a mock for deleting the object.
  2137. func (m *MockGlobalAddresses) Delete(ctx context.Context, key *meta.Key) error {
  2138. if m.DeleteHook != nil {
  2139. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  2140. klog.V(5).Infof("MockGlobalAddresses.Delete(%v, %v) = %v", ctx, key, err)
  2141. return err
  2142. }
  2143. }
  2144. if !key.Valid() {
  2145. return fmt.Errorf("invalid GCE key (%+v)", key)
  2146. }
  2147. m.Lock.Lock()
  2148. defer m.Lock.Unlock()
  2149. if err, ok := m.DeleteError[*key]; ok {
  2150. klog.V(5).Infof("MockGlobalAddresses.Delete(%v, %v) = %v", ctx, key, err)
  2151. return err
  2152. }
  2153. if _, ok := m.Objects[*key]; !ok {
  2154. err := &googleapi.Error{
  2155. Code: http.StatusNotFound,
  2156. Message: fmt.Sprintf("MockGlobalAddresses %v not found", key),
  2157. }
  2158. klog.V(5).Infof("MockGlobalAddresses.Delete(%v, %v) = %v", ctx, key, err)
  2159. return err
  2160. }
  2161. delete(m.Objects, *key)
  2162. klog.V(5).Infof("MockGlobalAddresses.Delete(%v, %v) = nil", ctx, key)
  2163. return nil
  2164. }
  2165. // Obj wraps the object for use in the mock.
  2166. func (m *MockGlobalAddresses) Obj(o *ga.Address) *MockGlobalAddressesObj {
  2167. return &MockGlobalAddressesObj{o}
  2168. }
  2169. // GCEGlobalAddresses is a simplifying adapter for the GCE GlobalAddresses.
  2170. type GCEGlobalAddresses struct {
  2171. s *Service
  2172. }
  2173. // Get the Address named by key.
  2174. func (g *GCEGlobalAddresses) Get(ctx context.Context, key *meta.Key) (*ga.Address, error) {
  2175. klog.V(5).Infof("GCEGlobalAddresses.Get(%v, %v): called", ctx, key)
  2176. if !key.Valid() {
  2177. klog.V(2).Infof("GCEGlobalAddresses.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  2178. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  2179. }
  2180. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalAddresses")
  2181. rk := &RateLimitKey{
  2182. ProjectID: projectID,
  2183. Operation: "Get",
  2184. Version: meta.Version("ga"),
  2185. Service: "GlobalAddresses",
  2186. }
  2187. klog.V(5).Infof("GCEGlobalAddresses.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2188. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2189. klog.V(4).Infof("GCEGlobalAddresses.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  2190. return nil, err
  2191. }
  2192. call := g.s.GA.GlobalAddresses.Get(projectID, key.Name)
  2193. call.Context(ctx)
  2194. v, err := call.Do()
  2195. klog.V(4).Infof("GCEGlobalAddresses.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  2196. return v, err
  2197. }
  2198. // List all Address objects.
  2199. func (g *GCEGlobalAddresses) List(ctx context.Context, fl *filter.F) ([]*ga.Address, error) {
  2200. klog.V(5).Infof("GCEGlobalAddresses.List(%v, %v) called", ctx, fl)
  2201. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalAddresses")
  2202. rk := &RateLimitKey{
  2203. ProjectID: projectID,
  2204. Operation: "List",
  2205. Version: meta.Version("ga"),
  2206. Service: "GlobalAddresses",
  2207. }
  2208. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2209. return nil, err
  2210. }
  2211. klog.V(5).Infof("GCEGlobalAddresses.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  2212. call := g.s.GA.GlobalAddresses.List(projectID)
  2213. if fl != filter.None {
  2214. call.Filter(fl.String())
  2215. }
  2216. var all []*ga.Address
  2217. f := func(l *ga.AddressList) error {
  2218. klog.V(5).Infof("GCEGlobalAddresses.List(%v, ..., %v): page %+v", ctx, fl, l)
  2219. all = append(all, l.Items...)
  2220. return nil
  2221. }
  2222. if err := call.Pages(ctx, f); err != nil {
  2223. klog.V(4).Infof("GCEGlobalAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  2224. return nil, err
  2225. }
  2226. if klog.V(4) {
  2227. klog.V(4).Infof("GCEGlobalAddresses.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  2228. } else if klog.V(5) {
  2229. var asStr []string
  2230. for _, o := range all {
  2231. asStr = append(asStr, fmt.Sprintf("%+v", o))
  2232. }
  2233. klog.V(5).Infof("GCEGlobalAddresses.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  2234. }
  2235. return all, nil
  2236. }
  2237. // Insert Address with key of value obj.
  2238. func (g *GCEGlobalAddresses) Insert(ctx context.Context, key *meta.Key, obj *ga.Address) error {
  2239. klog.V(5).Infof("GCEGlobalAddresses.Insert(%v, %v, %+v): called", ctx, key, obj)
  2240. if !key.Valid() {
  2241. klog.V(2).Infof("GCEGlobalAddresses.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  2242. return fmt.Errorf("invalid GCE key (%+v)", key)
  2243. }
  2244. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalAddresses")
  2245. rk := &RateLimitKey{
  2246. ProjectID: projectID,
  2247. Operation: "Insert",
  2248. Version: meta.Version("ga"),
  2249. Service: "GlobalAddresses",
  2250. }
  2251. klog.V(5).Infof("GCEGlobalAddresses.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2252. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2253. klog.V(4).Infof("GCEGlobalAddresses.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  2254. return err
  2255. }
  2256. obj.Name = key.Name
  2257. call := g.s.GA.GlobalAddresses.Insert(projectID, obj)
  2258. call.Context(ctx)
  2259. op, err := call.Do()
  2260. if err != nil {
  2261. klog.V(4).Infof("GCEGlobalAddresses.Insert(%v, %v, ...) = %+v", ctx, key, err)
  2262. return err
  2263. }
  2264. err = g.s.WaitForCompletion(ctx, op)
  2265. klog.V(4).Infof("GCEGlobalAddresses.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  2266. return err
  2267. }
  2268. // Delete the Address referenced by key.
  2269. func (g *GCEGlobalAddresses) Delete(ctx context.Context, key *meta.Key) error {
  2270. klog.V(5).Infof("GCEGlobalAddresses.Delete(%v, %v): called", ctx, key)
  2271. if !key.Valid() {
  2272. klog.V(2).Infof("GCEGlobalAddresses.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  2273. return fmt.Errorf("invalid GCE key (%+v)", key)
  2274. }
  2275. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalAddresses")
  2276. rk := &RateLimitKey{
  2277. ProjectID: projectID,
  2278. Operation: "Delete",
  2279. Version: meta.Version("ga"),
  2280. Service: "GlobalAddresses",
  2281. }
  2282. klog.V(5).Infof("GCEGlobalAddresses.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2283. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2284. klog.V(4).Infof("GCEGlobalAddresses.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  2285. return err
  2286. }
  2287. call := g.s.GA.GlobalAddresses.Delete(projectID, key.Name)
  2288. call.Context(ctx)
  2289. op, err := call.Do()
  2290. if err != nil {
  2291. klog.V(4).Infof("GCEGlobalAddresses.Delete(%v, %v) = %v", ctx, key, err)
  2292. return err
  2293. }
  2294. err = g.s.WaitForCompletion(ctx, op)
  2295. klog.V(4).Infof("GCEGlobalAddresses.Delete(%v, %v) = %v", ctx, key, err)
  2296. return err
  2297. }
  2298. // BackendServices is an interface that allows for mocking of BackendServices.
  2299. type BackendServices interface {
  2300. Get(ctx context.Context, key *meta.Key) (*ga.BackendService, error)
  2301. List(ctx context.Context, fl *filter.F) ([]*ga.BackendService, error)
  2302. Insert(ctx context.Context, key *meta.Key, obj *ga.BackendService) error
  2303. Delete(ctx context.Context, key *meta.Key) error
  2304. GetHealth(context.Context, *meta.Key, *ga.ResourceGroupReference) (*ga.BackendServiceGroupHealth, error)
  2305. Patch(context.Context, *meta.Key, *ga.BackendService) error
  2306. Update(context.Context, *meta.Key, *ga.BackendService) error
  2307. }
  2308. // NewMockBackendServices returns a new mock for BackendServices.
  2309. func NewMockBackendServices(pr ProjectRouter, objs map[meta.Key]*MockBackendServicesObj) *MockBackendServices {
  2310. mock := &MockBackendServices{
  2311. ProjectRouter: pr,
  2312. Objects: objs,
  2313. GetError: map[meta.Key]error{},
  2314. InsertError: map[meta.Key]error{},
  2315. DeleteError: map[meta.Key]error{},
  2316. }
  2317. return mock
  2318. }
  2319. // MockBackendServices is the mock for BackendServices.
  2320. type MockBackendServices struct {
  2321. Lock sync.Mutex
  2322. ProjectRouter ProjectRouter
  2323. // Objects maintained by the mock.
  2324. Objects map[meta.Key]*MockBackendServicesObj
  2325. // If an entry exists for the given key and operation, then the error
  2326. // will be returned instead of the operation.
  2327. GetError map[meta.Key]error
  2328. ListError *error
  2329. InsertError map[meta.Key]error
  2330. DeleteError map[meta.Key]error
  2331. // xxxHook allow you to intercept the standard processing of the mock in
  2332. // order to add your own logic. Return (true, _, _) to prevent the normal
  2333. // execution flow of the mock. Return (false, nil, nil) to continue with
  2334. // normal mock behavior/ after the hook function executes.
  2335. GetHook func(ctx context.Context, key *meta.Key, m *MockBackendServices) (bool, *ga.BackendService, error)
  2336. ListHook func(ctx context.Context, fl *filter.F, m *MockBackendServices) (bool, []*ga.BackendService, error)
  2337. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.BackendService, m *MockBackendServices) (bool, error)
  2338. DeleteHook func(ctx context.Context, key *meta.Key, m *MockBackendServices) (bool, error)
  2339. GetHealthHook func(context.Context, *meta.Key, *ga.ResourceGroupReference, *MockBackendServices) (*ga.BackendServiceGroupHealth, error)
  2340. PatchHook func(context.Context, *meta.Key, *ga.BackendService, *MockBackendServices) error
  2341. UpdateHook func(context.Context, *meta.Key, *ga.BackendService, *MockBackendServices) error
  2342. // X is extra state that can be used as part of the mock. Generated code
  2343. // will not use this field.
  2344. X interface{}
  2345. }
  2346. // Get returns the object from the mock.
  2347. func (m *MockBackendServices) Get(ctx context.Context, key *meta.Key) (*ga.BackendService, error) {
  2348. if m.GetHook != nil {
  2349. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  2350. klog.V(5).Infof("MockBackendServices.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  2351. return obj, err
  2352. }
  2353. }
  2354. if !key.Valid() {
  2355. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  2356. }
  2357. m.Lock.Lock()
  2358. defer m.Lock.Unlock()
  2359. if err, ok := m.GetError[*key]; ok {
  2360. klog.V(5).Infof("MockBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  2361. return nil, err
  2362. }
  2363. if obj, ok := m.Objects[*key]; ok {
  2364. typedObj := obj.ToGA()
  2365. klog.V(5).Infof("MockBackendServices.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  2366. return typedObj, nil
  2367. }
  2368. err := &googleapi.Error{
  2369. Code: http.StatusNotFound,
  2370. Message: fmt.Sprintf("MockBackendServices %v not found", key),
  2371. }
  2372. klog.V(5).Infof("MockBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  2373. return nil, err
  2374. }
  2375. // List all of the objects in the mock.
  2376. func (m *MockBackendServices) List(ctx context.Context, fl *filter.F) ([]*ga.BackendService, error) {
  2377. if m.ListHook != nil {
  2378. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  2379. klog.V(5).Infof("MockBackendServices.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  2380. return objs, err
  2381. }
  2382. }
  2383. m.Lock.Lock()
  2384. defer m.Lock.Unlock()
  2385. if m.ListError != nil {
  2386. err := *m.ListError
  2387. klog.V(5).Infof("MockBackendServices.List(%v, %v) = nil, %v", ctx, fl, err)
  2388. return nil, *m.ListError
  2389. }
  2390. var objs []*ga.BackendService
  2391. for _, obj := range m.Objects {
  2392. if !fl.Match(obj.ToGA()) {
  2393. continue
  2394. }
  2395. objs = append(objs, obj.ToGA())
  2396. }
  2397. klog.V(5).Infof("MockBackendServices.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  2398. return objs, nil
  2399. }
  2400. // Insert is a mock for inserting/creating a new object.
  2401. func (m *MockBackendServices) Insert(ctx context.Context, key *meta.Key, obj *ga.BackendService) error {
  2402. if m.InsertHook != nil {
  2403. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  2404. klog.V(5).Infof("MockBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2405. return err
  2406. }
  2407. }
  2408. if !key.Valid() {
  2409. return fmt.Errorf("invalid GCE key (%+v)", key)
  2410. }
  2411. m.Lock.Lock()
  2412. defer m.Lock.Unlock()
  2413. if err, ok := m.InsertError[*key]; ok {
  2414. klog.V(5).Infof("MockBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2415. return err
  2416. }
  2417. if _, ok := m.Objects[*key]; ok {
  2418. err := &googleapi.Error{
  2419. Code: http.StatusConflict,
  2420. Message: fmt.Sprintf("MockBackendServices %v exists", key),
  2421. }
  2422. klog.V(5).Infof("MockBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2423. return err
  2424. }
  2425. obj.Name = key.Name
  2426. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "backendServices")
  2427. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "backendServices", key)
  2428. m.Objects[*key] = &MockBackendServicesObj{obj}
  2429. klog.V(5).Infof("MockBackendServices.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  2430. return nil
  2431. }
  2432. // Delete is a mock for deleting the object.
  2433. func (m *MockBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  2434. if m.DeleteHook != nil {
  2435. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  2436. klog.V(5).Infof("MockBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2437. return err
  2438. }
  2439. }
  2440. if !key.Valid() {
  2441. return fmt.Errorf("invalid GCE key (%+v)", key)
  2442. }
  2443. m.Lock.Lock()
  2444. defer m.Lock.Unlock()
  2445. if err, ok := m.DeleteError[*key]; ok {
  2446. klog.V(5).Infof("MockBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2447. return err
  2448. }
  2449. if _, ok := m.Objects[*key]; !ok {
  2450. err := &googleapi.Error{
  2451. Code: http.StatusNotFound,
  2452. Message: fmt.Sprintf("MockBackendServices %v not found", key),
  2453. }
  2454. klog.V(5).Infof("MockBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2455. return err
  2456. }
  2457. delete(m.Objects, *key)
  2458. klog.V(5).Infof("MockBackendServices.Delete(%v, %v) = nil", ctx, key)
  2459. return nil
  2460. }
  2461. // Obj wraps the object for use in the mock.
  2462. func (m *MockBackendServices) Obj(o *ga.BackendService) *MockBackendServicesObj {
  2463. return &MockBackendServicesObj{o}
  2464. }
  2465. // GetHealth is a mock for the corresponding method.
  2466. func (m *MockBackendServices) GetHealth(ctx context.Context, key *meta.Key, arg0 *ga.ResourceGroupReference) (*ga.BackendServiceGroupHealth, error) {
  2467. if m.GetHealthHook != nil {
  2468. return m.GetHealthHook(ctx, key, arg0, m)
  2469. }
  2470. return nil, fmt.Errorf("GetHealthHook must be set")
  2471. }
  2472. // Patch is a mock for the corresponding method.
  2473. func (m *MockBackendServices) Patch(ctx context.Context, key *meta.Key, arg0 *ga.BackendService) error {
  2474. if m.PatchHook != nil {
  2475. return m.PatchHook(ctx, key, arg0, m)
  2476. }
  2477. return nil
  2478. }
  2479. // Update is a mock for the corresponding method.
  2480. func (m *MockBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *ga.BackendService) error {
  2481. if m.UpdateHook != nil {
  2482. return m.UpdateHook(ctx, key, arg0, m)
  2483. }
  2484. return nil
  2485. }
  2486. // GCEBackendServices is a simplifying adapter for the GCE BackendServices.
  2487. type GCEBackendServices struct {
  2488. s *Service
  2489. }
  2490. // Get the BackendService named by key.
  2491. func (g *GCEBackendServices) Get(ctx context.Context, key *meta.Key) (*ga.BackendService, error) {
  2492. klog.V(5).Infof("GCEBackendServices.Get(%v, %v): called", ctx, key)
  2493. if !key.Valid() {
  2494. klog.V(2).Infof("GCEBackendServices.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  2495. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  2496. }
  2497. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "BackendServices")
  2498. rk := &RateLimitKey{
  2499. ProjectID: projectID,
  2500. Operation: "Get",
  2501. Version: meta.Version("ga"),
  2502. Service: "BackendServices",
  2503. }
  2504. klog.V(5).Infof("GCEBackendServices.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2505. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2506. klog.V(4).Infof("GCEBackendServices.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  2507. return nil, err
  2508. }
  2509. call := g.s.GA.BackendServices.Get(projectID, key.Name)
  2510. call.Context(ctx)
  2511. v, err := call.Do()
  2512. klog.V(4).Infof("GCEBackendServices.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  2513. return v, err
  2514. }
  2515. // List all BackendService objects.
  2516. func (g *GCEBackendServices) List(ctx context.Context, fl *filter.F) ([]*ga.BackendService, error) {
  2517. klog.V(5).Infof("GCEBackendServices.List(%v, %v) called", ctx, fl)
  2518. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "BackendServices")
  2519. rk := &RateLimitKey{
  2520. ProjectID: projectID,
  2521. Operation: "List",
  2522. Version: meta.Version("ga"),
  2523. Service: "BackendServices",
  2524. }
  2525. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2526. return nil, err
  2527. }
  2528. klog.V(5).Infof("GCEBackendServices.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  2529. call := g.s.GA.BackendServices.List(projectID)
  2530. if fl != filter.None {
  2531. call.Filter(fl.String())
  2532. }
  2533. var all []*ga.BackendService
  2534. f := func(l *ga.BackendServiceList) error {
  2535. klog.V(5).Infof("GCEBackendServices.List(%v, ..., %v): page %+v", ctx, fl, l)
  2536. all = append(all, l.Items...)
  2537. return nil
  2538. }
  2539. if err := call.Pages(ctx, f); err != nil {
  2540. klog.V(4).Infof("GCEBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  2541. return nil, err
  2542. }
  2543. if klog.V(4) {
  2544. klog.V(4).Infof("GCEBackendServices.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  2545. } else if klog.V(5) {
  2546. var asStr []string
  2547. for _, o := range all {
  2548. asStr = append(asStr, fmt.Sprintf("%+v", o))
  2549. }
  2550. klog.V(5).Infof("GCEBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  2551. }
  2552. return all, nil
  2553. }
  2554. // Insert BackendService with key of value obj.
  2555. func (g *GCEBackendServices) Insert(ctx context.Context, key *meta.Key, obj *ga.BackendService) error {
  2556. klog.V(5).Infof("GCEBackendServices.Insert(%v, %v, %+v): called", ctx, key, obj)
  2557. if !key.Valid() {
  2558. klog.V(2).Infof("GCEBackendServices.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  2559. return fmt.Errorf("invalid GCE key (%+v)", key)
  2560. }
  2561. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "BackendServices")
  2562. rk := &RateLimitKey{
  2563. ProjectID: projectID,
  2564. Operation: "Insert",
  2565. Version: meta.Version("ga"),
  2566. Service: "BackendServices",
  2567. }
  2568. klog.V(5).Infof("GCEBackendServices.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2569. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2570. klog.V(4).Infof("GCEBackendServices.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  2571. return err
  2572. }
  2573. obj.Name = key.Name
  2574. call := g.s.GA.BackendServices.Insert(projectID, obj)
  2575. call.Context(ctx)
  2576. op, err := call.Do()
  2577. if err != nil {
  2578. klog.V(4).Infof("GCEBackendServices.Insert(%v, %v, ...) = %+v", ctx, key, err)
  2579. return err
  2580. }
  2581. err = g.s.WaitForCompletion(ctx, op)
  2582. klog.V(4).Infof("GCEBackendServices.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  2583. return err
  2584. }
  2585. // Delete the BackendService referenced by key.
  2586. func (g *GCEBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  2587. klog.V(5).Infof("GCEBackendServices.Delete(%v, %v): called", ctx, key)
  2588. if !key.Valid() {
  2589. klog.V(2).Infof("GCEBackendServices.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  2590. return fmt.Errorf("invalid GCE key (%+v)", key)
  2591. }
  2592. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "BackendServices")
  2593. rk := &RateLimitKey{
  2594. ProjectID: projectID,
  2595. Operation: "Delete",
  2596. Version: meta.Version("ga"),
  2597. Service: "BackendServices",
  2598. }
  2599. klog.V(5).Infof("GCEBackendServices.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2600. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2601. klog.V(4).Infof("GCEBackendServices.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  2602. return err
  2603. }
  2604. call := g.s.GA.BackendServices.Delete(projectID, key.Name)
  2605. call.Context(ctx)
  2606. op, err := call.Do()
  2607. if err != nil {
  2608. klog.V(4).Infof("GCEBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2609. return err
  2610. }
  2611. err = g.s.WaitForCompletion(ctx, op)
  2612. klog.V(4).Infof("GCEBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2613. return err
  2614. }
  2615. // GetHealth is a method on GCEBackendServices.
  2616. func (g *GCEBackendServices) GetHealth(ctx context.Context, key *meta.Key, arg0 *ga.ResourceGroupReference) (*ga.BackendServiceGroupHealth, error) {
  2617. klog.V(5).Infof("GCEBackendServices.GetHealth(%v, %v, ...): called", ctx, key)
  2618. if !key.Valid() {
  2619. klog.V(2).Infof("GCEBackendServices.GetHealth(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  2620. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  2621. }
  2622. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "BackendServices")
  2623. rk := &RateLimitKey{
  2624. ProjectID: projectID,
  2625. Operation: "GetHealth",
  2626. Version: meta.Version("ga"),
  2627. Service: "BackendServices",
  2628. }
  2629. klog.V(5).Infof("GCEBackendServices.GetHealth(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2630. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2631. klog.V(4).Infof("GCEBackendServices.GetHealth(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  2632. return nil, err
  2633. }
  2634. call := g.s.GA.BackendServices.GetHealth(projectID, key.Name, arg0)
  2635. call.Context(ctx)
  2636. v, err := call.Do()
  2637. klog.V(4).Infof("GCEBackendServices.GetHealth(%v, %v, ...) = %+v, %v", ctx, key, v, err)
  2638. return v, err
  2639. }
  2640. // Patch is a method on GCEBackendServices.
  2641. func (g *GCEBackendServices) Patch(ctx context.Context, key *meta.Key, arg0 *ga.BackendService) error {
  2642. klog.V(5).Infof("GCEBackendServices.Patch(%v, %v, ...): called", ctx, key)
  2643. if !key.Valid() {
  2644. klog.V(2).Infof("GCEBackendServices.Patch(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  2645. return fmt.Errorf("invalid GCE key (%+v)", key)
  2646. }
  2647. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "BackendServices")
  2648. rk := &RateLimitKey{
  2649. ProjectID: projectID,
  2650. Operation: "Patch",
  2651. Version: meta.Version("ga"),
  2652. Service: "BackendServices",
  2653. }
  2654. klog.V(5).Infof("GCEBackendServices.Patch(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2655. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2656. klog.V(4).Infof("GCEBackendServices.Patch(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  2657. return err
  2658. }
  2659. call := g.s.GA.BackendServices.Patch(projectID, key.Name, arg0)
  2660. call.Context(ctx)
  2661. op, err := call.Do()
  2662. if err != nil {
  2663. klog.V(4).Infof("GCEBackendServices.Patch(%v, %v, ...) = %+v", ctx, key, err)
  2664. return err
  2665. }
  2666. err = g.s.WaitForCompletion(ctx, op)
  2667. klog.V(4).Infof("GCEBackendServices.Patch(%v, %v, ...) = %+v", ctx, key, err)
  2668. return err
  2669. }
  2670. // Update is a method on GCEBackendServices.
  2671. func (g *GCEBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *ga.BackendService) error {
  2672. klog.V(5).Infof("GCEBackendServices.Update(%v, %v, ...): called", ctx, key)
  2673. if !key.Valid() {
  2674. klog.V(2).Infof("GCEBackendServices.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  2675. return fmt.Errorf("invalid GCE key (%+v)", key)
  2676. }
  2677. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "BackendServices")
  2678. rk := &RateLimitKey{
  2679. ProjectID: projectID,
  2680. Operation: "Update",
  2681. Version: meta.Version("ga"),
  2682. Service: "BackendServices",
  2683. }
  2684. klog.V(5).Infof("GCEBackendServices.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2685. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2686. klog.V(4).Infof("GCEBackendServices.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  2687. return err
  2688. }
  2689. call := g.s.GA.BackendServices.Update(projectID, key.Name, arg0)
  2690. call.Context(ctx)
  2691. op, err := call.Do()
  2692. if err != nil {
  2693. klog.V(4).Infof("GCEBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  2694. return err
  2695. }
  2696. err = g.s.WaitForCompletion(ctx, op)
  2697. klog.V(4).Infof("GCEBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  2698. return err
  2699. }
  2700. // BetaBackendServices is an interface that allows for mocking of BackendServices.
  2701. type BetaBackendServices interface {
  2702. Get(ctx context.Context, key *meta.Key) (*beta.BackendService, error)
  2703. List(ctx context.Context, fl *filter.F) ([]*beta.BackendService, error)
  2704. Insert(ctx context.Context, key *meta.Key, obj *beta.BackendService) error
  2705. Delete(ctx context.Context, key *meta.Key) error
  2706. SetSecurityPolicy(context.Context, *meta.Key, *beta.SecurityPolicyReference) error
  2707. Update(context.Context, *meta.Key, *beta.BackendService) error
  2708. }
  2709. // NewMockBetaBackendServices returns a new mock for BackendServices.
  2710. func NewMockBetaBackendServices(pr ProjectRouter, objs map[meta.Key]*MockBackendServicesObj) *MockBetaBackendServices {
  2711. mock := &MockBetaBackendServices{
  2712. ProjectRouter: pr,
  2713. Objects: objs,
  2714. GetError: map[meta.Key]error{},
  2715. InsertError: map[meta.Key]error{},
  2716. DeleteError: map[meta.Key]error{},
  2717. }
  2718. return mock
  2719. }
  2720. // MockBetaBackendServices is the mock for BackendServices.
  2721. type MockBetaBackendServices struct {
  2722. Lock sync.Mutex
  2723. ProjectRouter ProjectRouter
  2724. // Objects maintained by the mock.
  2725. Objects map[meta.Key]*MockBackendServicesObj
  2726. // If an entry exists for the given key and operation, then the error
  2727. // will be returned instead of the operation.
  2728. GetError map[meta.Key]error
  2729. ListError *error
  2730. InsertError map[meta.Key]error
  2731. DeleteError map[meta.Key]error
  2732. // xxxHook allow you to intercept the standard processing of the mock in
  2733. // order to add your own logic. Return (true, _, _) to prevent the normal
  2734. // execution flow of the mock. Return (false, nil, nil) to continue with
  2735. // normal mock behavior/ after the hook function executes.
  2736. GetHook func(ctx context.Context, key *meta.Key, m *MockBetaBackendServices) (bool, *beta.BackendService, error)
  2737. ListHook func(ctx context.Context, fl *filter.F, m *MockBetaBackendServices) (bool, []*beta.BackendService, error)
  2738. InsertHook func(ctx context.Context, key *meta.Key, obj *beta.BackendService, m *MockBetaBackendServices) (bool, error)
  2739. DeleteHook func(ctx context.Context, key *meta.Key, m *MockBetaBackendServices) (bool, error)
  2740. SetSecurityPolicyHook func(context.Context, *meta.Key, *beta.SecurityPolicyReference, *MockBetaBackendServices) error
  2741. UpdateHook func(context.Context, *meta.Key, *beta.BackendService, *MockBetaBackendServices) error
  2742. // X is extra state that can be used as part of the mock. Generated code
  2743. // will not use this field.
  2744. X interface{}
  2745. }
  2746. // Get returns the object from the mock.
  2747. func (m *MockBetaBackendServices) Get(ctx context.Context, key *meta.Key) (*beta.BackendService, error) {
  2748. if m.GetHook != nil {
  2749. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  2750. klog.V(5).Infof("MockBetaBackendServices.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  2751. return obj, err
  2752. }
  2753. }
  2754. if !key.Valid() {
  2755. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  2756. }
  2757. m.Lock.Lock()
  2758. defer m.Lock.Unlock()
  2759. if err, ok := m.GetError[*key]; ok {
  2760. klog.V(5).Infof("MockBetaBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  2761. return nil, err
  2762. }
  2763. if obj, ok := m.Objects[*key]; ok {
  2764. typedObj := obj.ToBeta()
  2765. klog.V(5).Infof("MockBetaBackendServices.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  2766. return typedObj, nil
  2767. }
  2768. err := &googleapi.Error{
  2769. Code: http.StatusNotFound,
  2770. Message: fmt.Sprintf("MockBetaBackendServices %v not found", key),
  2771. }
  2772. klog.V(5).Infof("MockBetaBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  2773. return nil, err
  2774. }
  2775. // List all of the objects in the mock.
  2776. func (m *MockBetaBackendServices) List(ctx context.Context, fl *filter.F) ([]*beta.BackendService, error) {
  2777. if m.ListHook != nil {
  2778. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  2779. klog.V(5).Infof("MockBetaBackendServices.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  2780. return objs, err
  2781. }
  2782. }
  2783. m.Lock.Lock()
  2784. defer m.Lock.Unlock()
  2785. if m.ListError != nil {
  2786. err := *m.ListError
  2787. klog.V(5).Infof("MockBetaBackendServices.List(%v, %v) = nil, %v", ctx, fl, err)
  2788. return nil, *m.ListError
  2789. }
  2790. var objs []*beta.BackendService
  2791. for _, obj := range m.Objects {
  2792. if !fl.Match(obj.ToBeta()) {
  2793. continue
  2794. }
  2795. objs = append(objs, obj.ToBeta())
  2796. }
  2797. klog.V(5).Infof("MockBetaBackendServices.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  2798. return objs, nil
  2799. }
  2800. // Insert is a mock for inserting/creating a new object.
  2801. func (m *MockBetaBackendServices) Insert(ctx context.Context, key *meta.Key, obj *beta.BackendService) error {
  2802. if m.InsertHook != nil {
  2803. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  2804. klog.V(5).Infof("MockBetaBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2805. return err
  2806. }
  2807. }
  2808. if !key.Valid() {
  2809. return fmt.Errorf("invalid GCE key (%+v)", key)
  2810. }
  2811. m.Lock.Lock()
  2812. defer m.Lock.Unlock()
  2813. if err, ok := m.InsertError[*key]; ok {
  2814. klog.V(5).Infof("MockBetaBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2815. return err
  2816. }
  2817. if _, ok := m.Objects[*key]; ok {
  2818. err := &googleapi.Error{
  2819. Code: http.StatusConflict,
  2820. Message: fmt.Sprintf("MockBetaBackendServices %v exists", key),
  2821. }
  2822. klog.V(5).Infof("MockBetaBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  2823. return err
  2824. }
  2825. obj.Name = key.Name
  2826. projectID := m.ProjectRouter.ProjectID(ctx, "beta", "backendServices")
  2827. obj.SelfLink = SelfLink(meta.VersionBeta, projectID, "backendServices", key)
  2828. m.Objects[*key] = &MockBackendServicesObj{obj}
  2829. klog.V(5).Infof("MockBetaBackendServices.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  2830. return nil
  2831. }
  2832. // Delete is a mock for deleting the object.
  2833. func (m *MockBetaBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  2834. if m.DeleteHook != nil {
  2835. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  2836. klog.V(5).Infof("MockBetaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2837. return err
  2838. }
  2839. }
  2840. if !key.Valid() {
  2841. return fmt.Errorf("invalid GCE key (%+v)", key)
  2842. }
  2843. m.Lock.Lock()
  2844. defer m.Lock.Unlock()
  2845. if err, ok := m.DeleteError[*key]; ok {
  2846. klog.V(5).Infof("MockBetaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2847. return err
  2848. }
  2849. if _, ok := m.Objects[*key]; !ok {
  2850. err := &googleapi.Error{
  2851. Code: http.StatusNotFound,
  2852. Message: fmt.Sprintf("MockBetaBackendServices %v not found", key),
  2853. }
  2854. klog.V(5).Infof("MockBetaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  2855. return err
  2856. }
  2857. delete(m.Objects, *key)
  2858. klog.V(5).Infof("MockBetaBackendServices.Delete(%v, %v) = nil", ctx, key)
  2859. return nil
  2860. }
  2861. // Obj wraps the object for use in the mock.
  2862. func (m *MockBetaBackendServices) Obj(o *beta.BackendService) *MockBackendServicesObj {
  2863. return &MockBackendServicesObj{o}
  2864. }
  2865. // SetSecurityPolicy is a mock for the corresponding method.
  2866. func (m *MockBetaBackendServices) SetSecurityPolicy(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicyReference) error {
  2867. if m.SetSecurityPolicyHook != nil {
  2868. return m.SetSecurityPolicyHook(ctx, key, arg0, m)
  2869. }
  2870. return nil
  2871. }
  2872. // Update is a mock for the corresponding method.
  2873. func (m *MockBetaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *beta.BackendService) error {
  2874. if m.UpdateHook != nil {
  2875. return m.UpdateHook(ctx, key, arg0, m)
  2876. }
  2877. return nil
  2878. }
  2879. // GCEBetaBackendServices is a simplifying adapter for the GCE BackendServices.
  2880. type GCEBetaBackendServices struct {
  2881. s *Service
  2882. }
  2883. // Get the BackendService named by key.
  2884. func (g *GCEBetaBackendServices) Get(ctx context.Context, key *meta.Key) (*beta.BackendService, error) {
  2885. klog.V(5).Infof("GCEBetaBackendServices.Get(%v, %v): called", ctx, key)
  2886. if !key.Valid() {
  2887. klog.V(2).Infof("GCEBetaBackendServices.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  2888. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  2889. }
  2890. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "BackendServices")
  2891. rk := &RateLimitKey{
  2892. ProjectID: projectID,
  2893. Operation: "Get",
  2894. Version: meta.Version("beta"),
  2895. Service: "BackendServices",
  2896. }
  2897. klog.V(5).Infof("GCEBetaBackendServices.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2898. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2899. klog.V(4).Infof("GCEBetaBackendServices.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  2900. return nil, err
  2901. }
  2902. call := g.s.Beta.BackendServices.Get(projectID, key.Name)
  2903. call.Context(ctx)
  2904. v, err := call.Do()
  2905. klog.V(4).Infof("GCEBetaBackendServices.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  2906. return v, err
  2907. }
  2908. // List all BackendService objects.
  2909. func (g *GCEBetaBackendServices) List(ctx context.Context, fl *filter.F) ([]*beta.BackendService, error) {
  2910. klog.V(5).Infof("GCEBetaBackendServices.List(%v, %v) called", ctx, fl)
  2911. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "BackendServices")
  2912. rk := &RateLimitKey{
  2913. ProjectID: projectID,
  2914. Operation: "List",
  2915. Version: meta.Version("beta"),
  2916. Service: "BackendServices",
  2917. }
  2918. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2919. return nil, err
  2920. }
  2921. klog.V(5).Infof("GCEBetaBackendServices.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  2922. call := g.s.Beta.BackendServices.List(projectID)
  2923. if fl != filter.None {
  2924. call.Filter(fl.String())
  2925. }
  2926. var all []*beta.BackendService
  2927. f := func(l *beta.BackendServiceList) error {
  2928. klog.V(5).Infof("GCEBetaBackendServices.List(%v, ..., %v): page %+v", ctx, fl, l)
  2929. all = append(all, l.Items...)
  2930. return nil
  2931. }
  2932. if err := call.Pages(ctx, f); err != nil {
  2933. klog.V(4).Infof("GCEBetaBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  2934. return nil, err
  2935. }
  2936. if klog.V(4) {
  2937. klog.V(4).Infof("GCEBetaBackendServices.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  2938. } else if klog.V(5) {
  2939. var asStr []string
  2940. for _, o := range all {
  2941. asStr = append(asStr, fmt.Sprintf("%+v", o))
  2942. }
  2943. klog.V(5).Infof("GCEBetaBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  2944. }
  2945. return all, nil
  2946. }
  2947. // Insert BackendService with key of value obj.
  2948. func (g *GCEBetaBackendServices) Insert(ctx context.Context, key *meta.Key, obj *beta.BackendService) error {
  2949. klog.V(5).Infof("GCEBetaBackendServices.Insert(%v, %v, %+v): called", ctx, key, obj)
  2950. if !key.Valid() {
  2951. klog.V(2).Infof("GCEBetaBackendServices.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  2952. return fmt.Errorf("invalid GCE key (%+v)", key)
  2953. }
  2954. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "BackendServices")
  2955. rk := &RateLimitKey{
  2956. ProjectID: projectID,
  2957. Operation: "Insert",
  2958. Version: meta.Version("beta"),
  2959. Service: "BackendServices",
  2960. }
  2961. klog.V(5).Infof("GCEBetaBackendServices.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2962. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2963. klog.V(4).Infof("GCEBetaBackendServices.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  2964. return err
  2965. }
  2966. obj.Name = key.Name
  2967. call := g.s.Beta.BackendServices.Insert(projectID, obj)
  2968. call.Context(ctx)
  2969. op, err := call.Do()
  2970. if err != nil {
  2971. klog.V(4).Infof("GCEBetaBackendServices.Insert(%v, %v, ...) = %+v", ctx, key, err)
  2972. return err
  2973. }
  2974. err = g.s.WaitForCompletion(ctx, op)
  2975. klog.V(4).Infof("GCEBetaBackendServices.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  2976. return err
  2977. }
  2978. // Delete the BackendService referenced by key.
  2979. func (g *GCEBetaBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  2980. klog.V(5).Infof("GCEBetaBackendServices.Delete(%v, %v): called", ctx, key)
  2981. if !key.Valid() {
  2982. klog.V(2).Infof("GCEBetaBackendServices.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  2983. return fmt.Errorf("invalid GCE key (%+v)", key)
  2984. }
  2985. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "BackendServices")
  2986. rk := &RateLimitKey{
  2987. ProjectID: projectID,
  2988. Operation: "Delete",
  2989. Version: meta.Version("beta"),
  2990. Service: "BackendServices",
  2991. }
  2992. klog.V(5).Infof("GCEBetaBackendServices.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  2993. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  2994. klog.V(4).Infof("GCEBetaBackendServices.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  2995. return err
  2996. }
  2997. call := g.s.Beta.BackendServices.Delete(projectID, key.Name)
  2998. call.Context(ctx)
  2999. op, err := call.Do()
  3000. if err != nil {
  3001. klog.V(4).Infof("GCEBetaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3002. return err
  3003. }
  3004. err = g.s.WaitForCompletion(ctx, op)
  3005. klog.V(4).Infof("GCEBetaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3006. return err
  3007. }
  3008. // SetSecurityPolicy is a method on GCEBetaBackendServices.
  3009. func (g *GCEBetaBackendServices) SetSecurityPolicy(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicyReference) error {
  3010. klog.V(5).Infof("GCEBetaBackendServices.SetSecurityPolicy(%v, %v, ...): called", ctx, key)
  3011. if !key.Valid() {
  3012. klog.V(2).Infof("GCEBetaBackendServices.SetSecurityPolicy(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3013. return fmt.Errorf("invalid GCE key (%+v)", key)
  3014. }
  3015. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "BackendServices")
  3016. rk := &RateLimitKey{
  3017. ProjectID: projectID,
  3018. Operation: "SetSecurityPolicy",
  3019. Version: meta.Version("beta"),
  3020. Service: "BackendServices",
  3021. }
  3022. klog.V(5).Infof("GCEBetaBackendServices.SetSecurityPolicy(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3023. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3024. klog.V(4).Infof("GCEBetaBackendServices.SetSecurityPolicy(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3025. return err
  3026. }
  3027. call := g.s.Beta.BackendServices.SetSecurityPolicy(projectID, key.Name, arg0)
  3028. call.Context(ctx)
  3029. op, err := call.Do()
  3030. if err != nil {
  3031. klog.V(4).Infof("GCEBetaBackendServices.SetSecurityPolicy(%v, %v, ...) = %+v", ctx, key, err)
  3032. return err
  3033. }
  3034. err = g.s.WaitForCompletion(ctx, op)
  3035. klog.V(4).Infof("GCEBetaBackendServices.SetSecurityPolicy(%v, %v, ...) = %+v", ctx, key, err)
  3036. return err
  3037. }
  3038. // Update is a method on GCEBetaBackendServices.
  3039. func (g *GCEBetaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *beta.BackendService) error {
  3040. klog.V(5).Infof("GCEBetaBackendServices.Update(%v, %v, ...): called", ctx, key)
  3041. if !key.Valid() {
  3042. klog.V(2).Infof("GCEBetaBackendServices.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3043. return fmt.Errorf("invalid GCE key (%+v)", key)
  3044. }
  3045. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "BackendServices")
  3046. rk := &RateLimitKey{
  3047. ProjectID: projectID,
  3048. Operation: "Update",
  3049. Version: meta.Version("beta"),
  3050. Service: "BackendServices",
  3051. }
  3052. klog.V(5).Infof("GCEBetaBackendServices.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3053. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3054. klog.V(4).Infof("GCEBetaBackendServices.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3055. return err
  3056. }
  3057. call := g.s.Beta.BackendServices.Update(projectID, key.Name, arg0)
  3058. call.Context(ctx)
  3059. op, err := call.Do()
  3060. if err != nil {
  3061. klog.V(4).Infof("GCEBetaBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  3062. return err
  3063. }
  3064. err = g.s.WaitForCompletion(ctx, op)
  3065. klog.V(4).Infof("GCEBetaBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  3066. return err
  3067. }
  3068. // AlphaBackendServices is an interface that allows for mocking of BackendServices.
  3069. type AlphaBackendServices interface {
  3070. Get(ctx context.Context, key *meta.Key) (*alpha.BackendService, error)
  3071. List(ctx context.Context, fl *filter.F) ([]*alpha.BackendService, error)
  3072. Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error
  3073. Delete(ctx context.Context, key *meta.Key) error
  3074. SetSecurityPolicy(context.Context, *meta.Key, *alpha.SecurityPolicyReference) error
  3075. Update(context.Context, *meta.Key, *alpha.BackendService) error
  3076. }
  3077. // NewMockAlphaBackendServices returns a new mock for BackendServices.
  3078. func NewMockAlphaBackendServices(pr ProjectRouter, objs map[meta.Key]*MockBackendServicesObj) *MockAlphaBackendServices {
  3079. mock := &MockAlphaBackendServices{
  3080. ProjectRouter: pr,
  3081. Objects: objs,
  3082. GetError: map[meta.Key]error{},
  3083. InsertError: map[meta.Key]error{},
  3084. DeleteError: map[meta.Key]error{},
  3085. }
  3086. return mock
  3087. }
  3088. // MockAlphaBackendServices is the mock for BackendServices.
  3089. type MockAlphaBackendServices struct {
  3090. Lock sync.Mutex
  3091. ProjectRouter ProjectRouter
  3092. // Objects maintained by the mock.
  3093. Objects map[meta.Key]*MockBackendServicesObj
  3094. // If an entry exists for the given key and operation, then the error
  3095. // will be returned instead of the operation.
  3096. GetError map[meta.Key]error
  3097. ListError *error
  3098. InsertError map[meta.Key]error
  3099. DeleteError map[meta.Key]error
  3100. // xxxHook allow you to intercept the standard processing of the mock in
  3101. // order to add your own logic. Return (true, _, _) to prevent the normal
  3102. // execution flow of the mock. Return (false, nil, nil) to continue with
  3103. // normal mock behavior/ after the hook function executes.
  3104. GetHook func(ctx context.Context, key *meta.Key, m *MockAlphaBackendServices) (bool, *alpha.BackendService, error)
  3105. ListHook func(ctx context.Context, fl *filter.F, m *MockAlphaBackendServices) (bool, []*alpha.BackendService, error)
  3106. InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.BackendService, m *MockAlphaBackendServices) (bool, error)
  3107. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaBackendServices) (bool, error)
  3108. SetSecurityPolicyHook func(context.Context, *meta.Key, *alpha.SecurityPolicyReference, *MockAlphaBackendServices) error
  3109. UpdateHook func(context.Context, *meta.Key, *alpha.BackendService, *MockAlphaBackendServices) error
  3110. // X is extra state that can be used as part of the mock. Generated code
  3111. // will not use this field.
  3112. X interface{}
  3113. }
  3114. // Get returns the object from the mock.
  3115. func (m *MockAlphaBackendServices) Get(ctx context.Context, key *meta.Key) (*alpha.BackendService, error) {
  3116. if m.GetHook != nil {
  3117. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  3118. klog.V(5).Infof("MockAlphaBackendServices.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  3119. return obj, err
  3120. }
  3121. }
  3122. if !key.Valid() {
  3123. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  3124. }
  3125. m.Lock.Lock()
  3126. defer m.Lock.Unlock()
  3127. if err, ok := m.GetError[*key]; ok {
  3128. klog.V(5).Infof("MockAlphaBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  3129. return nil, err
  3130. }
  3131. if obj, ok := m.Objects[*key]; ok {
  3132. typedObj := obj.ToAlpha()
  3133. klog.V(5).Infof("MockAlphaBackendServices.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  3134. return typedObj, nil
  3135. }
  3136. err := &googleapi.Error{
  3137. Code: http.StatusNotFound,
  3138. Message: fmt.Sprintf("MockAlphaBackendServices %v not found", key),
  3139. }
  3140. klog.V(5).Infof("MockAlphaBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  3141. return nil, err
  3142. }
  3143. // List all of the objects in the mock.
  3144. func (m *MockAlphaBackendServices) List(ctx context.Context, fl *filter.F) ([]*alpha.BackendService, error) {
  3145. if m.ListHook != nil {
  3146. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  3147. klog.V(5).Infof("MockAlphaBackendServices.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  3148. return objs, err
  3149. }
  3150. }
  3151. m.Lock.Lock()
  3152. defer m.Lock.Unlock()
  3153. if m.ListError != nil {
  3154. err := *m.ListError
  3155. klog.V(5).Infof("MockAlphaBackendServices.List(%v, %v) = nil, %v", ctx, fl, err)
  3156. return nil, *m.ListError
  3157. }
  3158. var objs []*alpha.BackendService
  3159. for _, obj := range m.Objects {
  3160. if !fl.Match(obj.ToAlpha()) {
  3161. continue
  3162. }
  3163. objs = append(objs, obj.ToAlpha())
  3164. }
  3165. klog.V(5).Infof("MockAlphaBackendServices.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  3166. return objs, nil
  3167. }
  3168. // Insert is a mock for inserting/creating a new object.
  3169. func (m *MockAlphaBackendServices) Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error {
  3170. if m.InsertHook != nil {
  3171. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  3172. klog.V(5).Infof("MockAlphaBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3173. return err
  3174. }
  3175. }
  3176. if !key.Valid() {
  3177. return fmt.Errorf("invalid GCE key (%+v)", key)
  3178. }
  3179. m.Lock.Lock()
  3180. defer m.Lock.Unlock()
  3181. if err, ok := m.InsertError[*key]; ok {
  3182. klog.V(5).Infof("MockAlphaBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3183. return err
  3184. }
  3185. if _, ok := m.Objects[*key]; ok {
  3186. err := &googleapi.Error{
  3187. Code: http.StatusConflict,
  3188. Message: fmt.Sprintf("MockAlphaBackendServices %v exists", key),
  3189. }
  3190. klog.V(5).Infof("MockAlphaBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3191. return err
  3192. }
  3193. obj.Name = key.Name
  3194. projectID := m.ProjectRouter.ProjectID(ctx, "alpha", "backendServices")
  3195. obj.SelfLink = SelfLink(meta.VersionAlpha, projectID, "backendServices", key)
  3196. m.Objects[*key] = &MockBackendServicesObj{obj}
  3197. klog.V(5).Infof("MockAlphaBackendServices.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  3198. return nil
  3199. }
  3200. // Delete is a mock for deleting the object.
  3201. func (m *MockAlphaBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  3202. if m.DeleteHook != nil {
  3203. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  3204. klog.V(5).Infof("MockAlphaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3205. return err
  3206. }
  3207. }
  3208. if !key.Valid() {
  3209. return fmt.Errorf("invalid GCE key (%+v)", key)
  3210. }
  3211. m.Lock.Lock()
  3212. defer m.Lock.Unlock()
  3213. if err, ok := m.DeleteError[*key]; ok {
  3214. klog.V(5).Infof("MockAlphaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3215. return err
  3216. }
  3217. if _, ok := m.Objects[*key]; !ok {
  3218. err := &googleapi.Error{
  3219. Code: http.StatusNotFound,
  3220. Message: fmt.Sprintf("MockAlphaBackendServices %v not found", key),
  3221. }
  3222. klog.V(5).Infof("MockAlphaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3223. return err
  3224. }
  3225. delete(m.Objects, *key)
  3226. klog.V(5).Infof("MockAlphaBackendServices.Delete(%v, %v) = nil", ctx, key)
  3227. return nil
  3228. }
  3229. // Obj wraps the object for use in the mock.
  3230. func (m *MockAlphaBackendServices) Obj(o *alpha.BackendService) *MockBackendServicesObj {
  3231. return &MockBackendServicesObj{o}
  3232. }
  3233. // SetSecurityPolicy is a mock for the corresponding method.
  3234. func (m *MockAlphaBackendServices) SetSecurityPolicy(ctx context.Context, key *meta.Key, arg0 *alpha.SecurityPolicyReference) error {
  3235. if m.SetSecurityPolicyHook != nil {
  3236. return m.SetSecurityPolicyHook(ctx, key, arg0, m)
  3237. }
  3238. return nil
  3239. }
  3240. // Update is a mock for the corresponding method.
  3241. func (m *MockAlphaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error {
  3242. if m.UpdateHook != nil {
  3243. return m.UpdateHook(ctx, key, arg0, m)
  3244. }
  3245. return nil
  3246. }
  3247. // GCEAlphaBackendServices is a simplifying adapter for the GCE BackendServices.
  3248. type GCEAlphaBackendServices struct {
  3249. s *Service
  3250. }
  3251. // Get the BackendService named by key.
  3252. func (g *GCEAlphaBackendServices) Get(ctx context.Context, key *meta.Key) (*alpha.BackendService, error) {
  3253. klog.V(5).Infof("GCEAlphaBackendServices.Get(%v, %v): called", ctx, key)
  3254. if !key.Valid() {
  3255. klog.V(2).Infof("GCEAlphaBackendServices.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  3256. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  3257. }
  3258. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "BackendServices")
  3259. rk := &RateLimitKey{
  3260. ProjectID: projectID,
  3261. Operation: "Get",
  3262. Version: meta.Version("alpha"),
  3263. Service: "BackendServices",
  3264. }
  3265. klog.V(5).Infof("GCEAlphaBackendServices.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3266. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3267. klog.V(4).Infof("GCEAlphaBackendServices.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  3268. return nil, err
  3269. }
  3270. call := g.s.Alpha.BackendServices.Get(projectID, key.Name)
  3271. call.Context(ctx)
  3272. v, err := call.Do()
  3273. klog.V(4).Infof("GCEAlphaBackendServices.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  3274. return v, err
  3275. }
  3276. // List all BackendService objects.
  3277. func (g *GCEAlphaBackendServices) List(ctx context.Context, fl *filter.F) ([]*alpha.BackendService, error) {
  3278. klog.V(5).Infof("GCEAlphaBackendServices.List(%v, %v) called", ctx, fl)
  3279. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "BackendServices")
  3280. rk := &RateLimitKey{
  3281. ProjectID: projectID,
  3282. Operation: "List",
  3283. Version: meta.Version("alpha"),
  3284. Service: "BackendServices",
  3285. }
  3286. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3287. return nil, err
  3288. }
  3289. klog.V(5).Infof("GCEAlphaBackendServices.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  3290. call := g.s.Alpha.BackendServices.List(projectID)
  3291. if fl != filter.None {
  3292. call.Filter(fl.String())
  3293. }
  3294. var all []*alpha.BackendService
  3295. f := func(l *alpha.BackendServiceList) error {
  3296. klog.V(5).Infof("GCEAlphaBackendServices.List(%v, ..., %v): page %+v", ctx, fl, l)
  3297. all = append(all, l.Items...)
  3298. return nil
  3299. }
  3300. if err := call.Pages(ctx, f); err != nil {
  3301. klog.V(4).Infof("GCEAlphaBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  3302. return nil, err
  3303. }
  3304. if klog.V(4) {
  3305. klog.V(4).Infof("GCEAlphaBackendServices.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  3306. } else if klog.V(5) {
  3307. var asStr []string
  3308. for _, o := range all {
  3309. asStr = append(asStr, fmt.Sprintf("%+v", o))
  3310. }
  3311. klog.V(5).Infof("GCEAlphaBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  3312. }
  3313. return all, nil
  3314. }
  3315. // Insert BackendService with key of value obj.
  3316. func (g *GCEAlphaBackendServices) Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error {
  3317. klog.V(5).Infof("GCEAlphaBackendServices.Insert(%v, %v, %+v): called", ctx, key, obj)
  3318. if !key.Valid() {
  3319. klog.V(2).Infof("GCEAlphaBackendServices.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3320. return fmt.Errorf("invalid GCE key (%+v)", key)
  3321. }
  3322. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "BackendServices")
  3323. rk := &RateLimitKey{
  3324. ProjectID: projectID,
  3325. Operation: "Insert",
  3326. Version: meta.Version("alpha"),
  3327. Service: "BackendServices",
  3328. }
  3329. klog.V(5).Infof("GCEAlphaBackendServices.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3330. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3331. klog.V(4).Infof("GCEAlphaBackendServices.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3332. return err
  3333. }
  3334. obj.Name = key.Name
  3335. call := g.s.Alpha.BackendServices.Insert(projectID, obj)
  3336. call.Context(ctx)
  3337. op, err := call.Do()
  3338. if err != nil {
  3339. klog.V(4).Infof("GCEAlphaBackendServices.Insert(%v, %v, ...) = %+v", ctx, key, err)
  3340. return err
  3341. }
  3342. err = g.s.WaitForCompletion(ctx, op)
  3343. klog.V(4).Infof("GCEAlphaBackendServices.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  3344. return err
  3345. }
  3346. // Delete the BackendService referenced by key.
  3347. func (g *GCEAlphaBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  3348. klog.V(5).Infof("GCEAlphaBackendServices.Delete(%v, %v): called", ctx, key)
  3349. if !key.Valid() {
  3350. klog.V(2).Infof("GCEAlphaBackendServices.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  3351. return fmt.Errorf("invalid GCE key (%+v)", key)
  3352. }
  3353. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "BackendServices")
  3354. rk := &RateLimitKey{
  3355. ProjectID: projectID,
  3356. Operation: "Delete",
  3357. Version: meta.Version("alpha"),
  3358. Service: "BackendServices",
  3359. }
  3360. klog.V(5).Infof("GCEAlphaBackendServices.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3361. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3362. klog.V(4).Infof("GCEAlphaBackendServices.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  3363. return err
  3364. }
  3365. call := g.s.Alpha.BackendServices.Delete(projectID, key.Name)
  3366. call.Context(ctx)
  3367. op, err := call.Do()
  3368. if err != nil {
  3369. klog.V(4).Infof("GCEAlphaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3370. return err
  3371. }
  3372. err = g.s.WaitForCompletion(ctx, op)
  3373. klog.V(4).Infof("GCEAlphaBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3374. return err
  3375. }
  3376. // SetSecurityPolicy is a method on GCEAlphaBackendServices.
  3377. func (g *GCEAlphaBackendServices) SetSecurityPolicy(ctx context.Context, key *meta.Key, arg0 *alpha.SecurityPolicyReference) error {
  3378. klog.V(5).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): called", ctx, key)
  3379. if !key.Valid() {
  3380. klog.V(2).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3381. return fmt.Errorf("invalid GCE key (%+v)", key)
  3382. }
  3383. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "BackendServices")
  3384. rk := &RateLimitKey{
  3385. ProjectID: projectID,
  3386. Operation: "SetSecurityPolicy",
  3387. Version: meta.Version("alpha"),
  3388. Service: "BackendServices",
  3389. }
  3390. klog.V(5).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3391. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3392. klog.V(4).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3393. return err
  3394. }
  3395. call := g.s.Alpha.BackendServices.SetSecurityPolicy(projectID, key.Name, arg0)
  3396. call.Context(ctx)
  3397. op, err := call.Do()
  3398. if err != nil {
  3399. klog.V(4).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...) = %+v", ctx, key, err)
  3400. return err
  3401. }
  3402. err = g.s.WaitForCompletion(ctx, op)
  3403. klog.V(4).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...) = %+v", ctx, key, err)
  3404. return err
  3405. }
  3406. // Update is a method on GCEAlphaBackendServices.
  3407. func (g *GCEAlphaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error {
  3408. klog.V(5).Infof("GCEAlphaBackendServices.Update(%v, %v, ...): called", ctx, key)
  3409. if !key.Valid() {
  3410. klog.V(2).Infof("GCEAlphaBackendServices.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3411. return fmt.Errorf("invalid GCE key (%+v)", key)
  3412. }
  3413. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "BackendServices")
  3414. rk := &RateLimitKey{
  3415. ProjectID: projectID,
  3416. Operation: "Update",
  3417. Version: meta.Version("alpha"),
  3418. Service: "BackendServices",
  3419. }
  3420. klog.V(5).Infof("GCEAlphaBackendServices.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3421. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3422. klog.V(4).Infof("GCEAlphaBackendServices.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3423. return err
  3424. }
  3425. call := g.s.Alpha.BackendServices.Update(projectID, key.Name, arg0)
  3426. call.Context(ctx)
  3427. op, err := call.Do()
  3428. if err != nil {
  3429. klog.V(4).Infof("GCEAlphaBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  3430. return err
  3431. }
  3432. err = g.s.WaitForCompletion(ctx, op)
  3433. klog.V(4).Infof("GCEAlphaBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  3434. return err
  3435. }
  3436. // RegionBackendServices is an interface that allows for mocking of RegionBackendServices.
  3437. type RegionBackendServices interface {
  3438. Get(ctx context.Context, key *meta.Key) (*ga.BackendService, error)
  3439. List(ctx context.Context, region string, fl *filter.F) ([]*ga.BackendService, error)
  3440. Insert(ctx context.Context, key *meta.Key, obj *ga.BackendService) error
  3441. Delete(ctx context.Context, key *meta.Key) error
  3442. GetHealth(context.Context, *meta.Key, *ga.ResourceGroupReference) (*ga.BackendServiceGroupHealth, error)
  3443. Update(context.Context, *meta.Key, *ga.BackendService) error
  3444. }
  3445. // NewMockRegionBackendServices returns a new mock for RegionBackendServices.
  3446. func NewMockRegionBackendServices(pr ProjectRouter, objs map[meta.Key]*MockRegionBackendServicesObj) *MockRegionBackendServices {
  3447. mock := &MockRegionBackendServices{
  3448. ProjectRouter: pr,
  3449. Objects: objs,
  3450. GetError: map[meta.Key]error{},
  3451. InsertError: map[meta.Key]error{},
  3452. DeleteError: map[meta.Key]error{},
  3453. }
  3454. return mock
  3455. }
  3456. // MockRegionBackendServices is the mock for RegionBackendServices.
  3457. type MockRegionBackendServices struct {
  3458. Lock sync.Mutex
  3459. ProjectRouter ProjectRouter
  3460. // Objects maintained by the mock.
  3461. Objects map[meta.Key]*MockRegionBackendServicesObj
  3462. // If an entry exists for the given key and operation, then the error
  3463. // will be returned instead of the operation.
  3464. GetError map[meta.Key]error
  3465. ListError *error
  3466. InsertError map[meta.Key]error
  3467. DeleteError map[meta.Key]error
  3468. // xxxHook allow you to intercept the standard processing of the mock in
  3469. // order to add your own logic. Return (true, _, _) to prevent the normal
  3470. // execution flow of the mock. Return (false, nil, nil) to continue with
  3471. // normal mock behavior/ after the hook function executes.
  3472. GetHook func(ctx context.Context, key *meta.Key, m *MockRegionBackendServices) (bool, *ga.BackendService, error)
  3473. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockRegionBackendServices) (bool, []*ga.BackendService, error)
  3474. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.BackendService, m *MockRegionBackendServices) (bool, error)
  3475. DeleteHook func(ctx context.Context, key *meta.Key, m *MockRegionBackendServices) (bool, error)
  3476. GetHealthHook func(context.Context, *meta.Key, *ga.ResourceGroupReference, *MockRegionBackendServices) (*ga.BackendServiceGroupHealth, error)
  3477. UpdateHook func(context.Context, *meta.Key, *ga.BackendService, *MockRegionBackendServices) error
  3478. // X is extra state that can be used as part of the mock. Generated code
  3479. // will not use this field.
  3480. X interface{}
  3481. }
  3482. // Get returns the object from the mock.
  3483. func (m *MockRegionBackendServices) Get(ctx context.Context, key *meta.Key) (*ga.BackendService, error) {
  3484. if m.GetHook != nil {
  3485. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  3486. klog.V(5).Infof("MockRegionBackendServices.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  3487. return obj, err
  3488. }
  3489. }
  3490. if !key.Valid() {
  3491. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  3492. }
  3493. m.Lock.Lock()
  3494. defer m.Lock.Unlock()
  3495. if err, ok := m.GetError[*key]; ok {
  3496. klog.V(5).Infof("MockRegionBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  3497. return nil, err
  3498. }
  3499. if obj, ok := m.Objects[*key]; ok {
  3500. typedObj := obj.ToGA()
  3501. klog.V(5).Infof("MockRegionBackendServices.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  3502. return typedObj, nil
  3503. }
  3504. err := &googleapi.Error{
  3505. Code: http.StatusNotFound,
  3506. Message: fmt.Sprintf("MockRegionBackendServices %v not found", key),
  3507. }
  3508. klog.V(5).Infof("MockRegionBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  3509. return nil, err
  3510. }
  3511. // List all of the objects in the mock in the given region.
  3512. func (m *MockRegionBackendServices) List(ctx context.Context, region string, fl *filter.F) ([]*ga.BackendService, error) {
  3513. if m.ListHook != nil {
  3514. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  3515. klog.V(5).Infof("MockRegionBackendServices.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  3516. return objs, err
  3517. }
  3518. }
  3519. m.Lock.Lock()
  3520. defer m.Lock.Unlock()
  3521. if m.ListError != nil {
  3522. err := *m.ListError
  3523. klog.V(5).Infof("MockRegionBackendServices.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  3524. return nil, *m.ListError
  3525. }
  3526. var objs []*ga.BackendService
  3527. for key, obj := range m.Objects {
  3528. if key.Region != region {
  3529. continue
  3530. }
  3531. if !fl.Match(obj.ToGA()) {
  3532. continue
  3533. }
  3534. objs = append(objs, obj.ToGA())
  3535. }
  3536. klog.V(5).Infof("MockRegionBackendServices.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  3537. return objs, nil
  3538. }
  3539. // Insert is a mock for inserting/creating a new object.
  3540. func (m *MockRegionBackendServices) Insert(ctx context.Context, key *meta.Key, obj *ga.BackendService) error {
  3541. if m.InsertHook != nil {
  3542. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  3543. klog.V(5).Infof("MockRegionBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3544. return err
  3545. }
  3546. }
  3547. if !key.Valid() {
  3548. return fmt.Errorf("invalid GCE key (%+v)", key)
  3549. }
  3550. m.Lock.Lock()
  3551. defer m.Lock.Unlock()
  3552. if err, ok := m.InsertError[*key]; ok {
  3553. klog.V(5).Infof("MockRegionBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3554. return err
  3555. }
  3556. if _, ok := m.Objects[*key]; ok {
  3557. err := &googleapi.Error{
  3558. Code: http.StatusConflict,
  3559. Message: fmt.Sprintf("MockRegionBackendServices %v exists", key),
  3560. }
  3561. klog.V(5).Infof("MockRegionBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3562. return err
  3563. }
  3564. obj.Name = key.Name
  3565. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "backendServices")
  3566. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "backendServices", key)
  3567. m.Objects[*key] = &MockRegionBackendServicesObj{obj}
  3568. klog.V(5).Infof("MockRegionBackendServices.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  3569. return nil
  3570. }
  3571. // Delete is a mock for deleting the object.
  3572. func (m *MockRegionBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  3573. if m.DeleteHook != nil {
  3574. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  3575. klog.V(5).Infof("MockRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3576. return err
  3577. }
  3578. }
  3579. if !key.Valid() {
  3580. return fmt.Errorf("invalid GCE key (%+v)", key)
  3581. }
  3582. m.Lock.Lock()
  3583. defer m.Lock.Unlock()
  3584. if err, ok := m.DeleteError[*key]; ok {
  3585. klog.V(5).Infof("MockRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3586. return err
  3587. }
  3588. if _, ok := m.Objects[*key]; !ok {
  3589. err := &googleapi.Error{
  3590. Code: http.StatusNotFound,
  3591. Message: fmt.Sprintf("MockRegionBackendServices %v not found", key),
  3592. }
  3593. klog.V(5).Infof("MockRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3594. return err
  3595. }
  3596. delete(m.Objects, *key)
  3597. klog.V(5).Infof("MockRegionBackendServices.Delete(%v, %v) = nil", ctx, key)
  3598. return nil
  3599. }
  3600. // Obj wraps the object for use in the mock.
  3601. func (m *MockRegionBackendServices) Obj(o *ga.BackendService) *MockRegionBackendServicesObj {
  3602. return &MockRegionBackendServicesObj{o}
  3603. }
  3604. // GetHealth is a mock for the corresponding method.
  3605. func (m *MockRegionBackendServices) GetHealth(ctx context.Context, key *meta.Key, arg0 *ga.ResourceGroupReference) (*ga.BackendServiceGroupHealth, error) {
  3606. if m.GetHealthHook != nil {
  3607. return m.GetHealthHook(ctx, key, arg0, m)
  3608. }
  3609. return nil, fmt.Errorf("GetHealthHook must be set")
  3610. }
  3611. // Update is a mock for the corresponding method.
  3612. func (m *MockRegionBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *ga.BackendService) error {
  3613. if m.UpdateHook != nil {
  3614. return m.UpdateHook(ctx, key, arg0, m)
  3615. }
  3616. return nil
  3617. }
  3618. // GCERegionBackendServices is a simplifying adapter for the GCE RegionBackendServices.
  3619. type GCERegionBackendServices struct {
  3620. s *Service
  3621. }
  3622. // Get the BackendService named by key.
  3623. func (g *GCERegionBackendServices) Get(ctx context.Context, key *meta.Key) (*ga.BackendService, error) {
  3624. klog.V(5).Infof("GCERegionBackendServices.Get(%v, %v): called", ctx, key)
  3625. if !key.Valid() {
  3626. klog.V(2).Infof("GCERegionBackendServices.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  3627. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  3628. }
  3629. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionBackendServices")
  3630. rk := &RateLimitKey{
  3631. ProjectID: projectID,
  3632. Operation: "Get",
  3633. Version: meta.Version("ga"),
  3634. Service: "RegionBackendServices",
  3635. }
  3636. klog.V(5).Infof("GCERegionBackendServices.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3637. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3638. klog.V(4).Infof("GCERegionBackendServices.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  3639. return nil, err
  3640. }
  3641. call := g.s.GA.RegionBackendServices.Get(projectID, key.Region, key.Name)
  3642. call.Context(ctx)
  3643. v, err := call.Do()
  3644. klog.V(4).Infof("GCERegionBackendServices.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  3645. return v, err
  3646. }
  3647. // List all BackendService objects.
  3648. func (g *GCERegionBackendServices) List(ctx context.Context, region string, fl *filter.F) ([]*ga.BackendService, error) {
  3649. klog.V(5).Infof("GCERegionBackendServices.List(%v, %v, %v) called", ctx, region, fl)
  3650. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionBackendServices")
  3651. rk := &RateLimitKey{
  3652. ProjectID: projectID,
  3653. Operation: "List",
  3654. Version: meta.Version("ga"),
  3655. Service: "RegionBackendServices",
  3656. }
  3657. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3658. return nil, err
  3659. }
  3660. klog.V(5).Infof("GCERegionBackendServices.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  3661. call := g.s.GA.RegionBackendServices.List(projectID, region)
  3662. if fl != filter.None {
  3663. call.Filter(fl.String())
  3664. }
  3665. var all []*ga.BackendService
  3666. f := func(l *ga.BackendServiceList) error {
  3667. klog.V(5).Infof("GCERegionBackendServices.List(%v, ..., %v): page %+v", ctx, fl, l)
  3668. all = append(all, l.Items...)
  3669. return nil
  3670. }
  3671. if err := call.Pages(ctx, f); err != nil {
  3672. klog.V(4).Infof("GCERegionBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  3673. return nil, err
  3674. }
  3675. if klog.V(4) {
  3676. klog.V(4).Infof("GCERegionBackendServices.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  3677. } else if klog.V(5) {
  3678. var asStr []string
  3679. for _, o := range all {
  3680. asStr = append(asStr, fmt.Sprintf("%+v", o))
  3681. }
  3682. klog.V(5).Infof("GCERegionBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  3683. }
  3684. return all, nil
  3685. }
  3686. // Insert BackendService with key of value obj.
  3687. func (g *GCERegionBackendServices) Insert(ctx context.Context, key *meta.Key, obj *ga.BackendService) error {
  3688. klog.V(5).Infof("GCERegionBackendServices.Insert(%v, %v, %+v): called", ctx, key, obj)
  3689. if !key.Valid() {
  3690. klog.V(2).Infof("GCERegionBackendServices.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3691. return fmt.Errorf("invalid GCE key (%+v)", key)
  3692. }
  3693. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionBackendServices")
  3694. rk := &RateLimitKey{
  3695. ProjectID: projectID,
  3696. Operation: "Insert",
  3697. Version: meta.Version("ga"),
  3698. Service: "RegionBackendServices",
  3699. }
  3700. klog.V(5).Infof("GCERegionBackendServices.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3701. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3702. klog.V(4).Infof("GCERegionBackendServices.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3703. return err
  3704. }
  3705. obj.Name = key.Name
  3706. call := g.s.GA.RegionBackendServices.Insert(projectID, key.Region, obj)
  3707. call.Context(ctx)
  3708. op, err := call.Do()
  3709. if err != nil {
  3710. klog.V(4).Infof("GCERegionBackendServices.Insert(%v, %v, ...) = %+v", ctx, key, err)
  3711. return err
  3712. }
  3713. err = g.s.WaitForCompletion(ctx, op)
  3714. klog.V(4).Infof("GCERegionBackendServices.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  3715. return err
  3716. }
  3717. // Delete the BackendService referenced by key.
  3718. func (g *GCERegionBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  3719. klog.V(5).Infof("GCERegionBackendServices.Delete(%v, %v): called", ctx, key)
  3720. if !key.Valid() {
  3721. klog.V(2).Infof("GCERegionBackendServices.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  3722. return fmt.Errorf("invalid GCE key (%+v)", key)
  3723. }
  3724. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionBackendServices")
  3725. rk := &RateLimitKey{
  3726. ProjectID: projectID,
  3727. Operation: "Delete",
  3728. Version: meta.Version("ga"),
  3729. Service: "RegionBackendServices",
  3730. }
  3731. klog.V(5).Infof("GCERegionBackendServices.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3732. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3733. klog.V(4).Infof("GCERegionBackendServices.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  3734. return err
  3735. }
  3736. call := g.s.GA.RegionBackendServices.Delete(projectID, key.Region, key.Name)
  3737. call.Context(ctx)
  3738. op, err := call.Do()
  3739. if err != nil {
  3740. klog.V(4).Infof("GCERegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3741. return err
  3742. }
  3743. err = g.s.WaitForCompletion(ctx, op)
  3744. klog.V(4).Infof("GCERegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3745. return err
  3746. }
  3747. // GetHealth is a method on GCERegionBackendServices.
  3748. func (g *GCERegionBackendServices) GetHealth(ctx context.Context, key *meta.Key, arg0 *ga.ResourceGroupReference) (*ga.BackendServiceGroupHealth, error) {
  3749. klog.V(5).Infof("GCERegionBackendServices.GetHealth(%v, %v, ...): called", ctx, key)
  3750. if !key.Valid() {
  3751. klog.V(2).Infof("GCERegionBackendServices.GetHealth(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3752. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  3753. }
  3754. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionBackendServices")
  3755. rk := &RateLimitKey{
  3756. ProjectID: projectID,
  3757. Operation: "GetHealth",
  3758. Version: meta.Version("ga"),
  3759. Service: "RegionBackendServices",
  3760. }
  3761. klog.V(5).Infof("GCERegionBackendServices.GetHealth(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3762. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3763. klog.V(4).Infof("GCERegionBackendServices.GetHealth(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3764. return nil, err
  3765. }
  3766. call := g.s.GA.RegionBackendServices.GetHealth(projectID, key.Region, key.Name, arg0)
  3767. call.Context(ctx)
  3768. v, err := call.Do()
  3769. klog.V(4).Infof("GCERegionBackendServices.GetHealth(%v, %v, ...) = %+v, %v", ctx, key, v, err)
  3770. return v, err
  3771. }
  3772. // Update is a method on GCERegionBackendServices.
  3773. func (g *GCERegionBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *ga.BackendService) error {
  3774. klog.V(5).Infof("GCERegionBackendServices.Update(%v, %v, ...): called", ctx, key)
  3775. if !key.Valid() {
  3776. klog.V(2).Infof("GCERegionBackendServices.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  3777. return fmt.Errorf("invalid GCE key (%+v)", key)
  3778. }
  3779. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionBackendServices")
  3780. rk := &RateLimitKey{
  3781. ProjectID: projectID,
  3782. Operation: "Update",
  3783. Version: meta.Version("ga"),
  3784. Service: "RegionBackendServices",
  3785. }
  3786. klog.V(5).Infof("GCERegionBackendServices.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  3787. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  3788. klog.V(4).Infof("GCERegionBackendServices.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  3789. return err
  3790. }
  3791. call := g.s.GA.RegionBackendServices.Update(projectID, key.Region, key.Name, arg0)
  3792. call.Context(ctx)
  3793. op, err := call.Do()
  3794. if err != nil {
  3795. klog.V(4).Infof("GCERegionBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  3796. return err
  3797. }
  3798. err = g.s.WaitForCompletion(ctx, op)
  3799. klog.V(4).Infof("GCERegionBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  3800. return err
  3801. }
  3802. // AlphaRegionBackendServices is an interface that allows for mocking of RegionBackendServices.
  3803. type AlphaRegionBackendServices interface {
  3804. Get(ctx context.Context, key *meta.Key) (*alpha.BackendService, error)
  3805. List(ctx context.Context, region string, fl *filter.F) ([]*alpha.BackendService, error)
  3806. Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error
  3807. Delete(ctx context.Context, key *meta.Key) error
  3808. GetHealth(context.Context, *meta.Key, *alpha.ResourceGroupReference) (*alpha.BackendServiceGroupHealth, error)
  3809. Update(context.Context, *meta.Key, *alpha.BackendService) error
  3810. }
  3811. // NewMockAlphaRegionBackendServices returns a new mock for RegionBackendServices.
  3812. func NewMockAlphaRegionBackendServices(pr ProjectRouter, objs map[meta.Key]*MockRegionBackendServicesObj) *MockAlphaRegionBackendServices {
  3813. mock := &MockAlphaRegionBackendServices{
  3814. ProjectRouter: pr,
  3815. Objects: objs,
  3816. GetError: map[meta.Key]error{},
  3817. InsertError: map[meta.Key]error{},
  3818. DeleteError: map[meta.Key]error{},
  3819. }
  3820. return mock
  3821. }
  3822. // MockAlphaRegionBackendServices is the mock for RegionBackendServices.
  3823. type MockAlphaRegionBackendServices struct {
  3824. Lock sync.Mutex
  3825. ProjectRouter ProjectRouter
  3826. // Objects maintained by the mock.
  3827. Objects map[meta.Key]*MockRegionBackendServicesObj
  3828. // If an entry exists for the given key and operation, then the error
  3829. // will be returned instead of the operation.
  3830. GetError map[meta.Key]error
  3831. ListError *error
  3832. InsertError map[meta.Key]error
  3833. DeleteError map[meta.Key]error
  3834. // xxxHook allow you to intercept the standard processing of the mock in
  3835. // order to add your own logic. Return (true, _, _) to prevent the normal
  3836. // execution flow of the mock. Return (false, nil, nil) to continue with
  3837. // normal mock behavior/ after the hook function executes.
  3838. GetHook func(ctx context.Context, key *meta.Key, m *MockAlphaRegionBackendServices) (bool, *alpha.BackendService, error)
  3839. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockAlphaRegionBackendServices) (bool, []*alpha.BackendService, error)
  3840. InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.BackendService, m *MockAlphaRegionBackendServices) (bool, error)
  3841. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaRegionBackendServices) (bool, error)
  3842. GetHealthHook func(context.Context, *meta.Key, *alpha.ResourceGroupReference, *MockAlphaRegionBackendServices) (*alpha.BackendServiceGroupHealth, error)
  3843. UpdateHook func(context.Context, *meta.Key, *alpha.BackendService, *MockAlphaRegionBackendServices) error
  3844. // X is extra state that can be used as part of the mock. Generated code
  3845. // will not use this field.
  3846. X interface{}
  3847. }
  3848. // Get returns the object from the mock.
  3849. func (m *MockAlphaRegionBackendServices) Get(ctx context.Context, key *meta.Key) (*alpha.BackendService, error) {
  3850. if m.GetHook != nil {
  3851. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  3852. klog.V(5).Infof("MockAlphaRegionBackendServices.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  3853. return obj, err
  3854. }
  3855. }
  3856. if !key.Valid() {
  3857. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  3858. }
  3859. m.Lock.Lock()
  3860. defer m.Lock.Unlock()
  3861. if err, ok := m.GetError[*key]; ok {
  3862. klog.V(5).Infof("MockAlphaRegionBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  3863. return nil, err
  3864. }
  3865. if obj, ok := m.Objects[*key]; ok {
  3866. typedObj := obj.ToAlpha()
  3867. klog.V(5).Infof("MockAlphaRegionBackendServices.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  3868. return typedObj, nil
  3869. }
  3870. err := &googleapi.Error{
  3871. Code: http.StatusNotFound,
  3872. Message: fmt.Sprintf("MockAlphaRegionBackendServices %v not found", key),
  3873. }
  3874. klog.V(5).Infof("MockAlphaRegionBackendServices.Get(%v, %s) = nil, %v", ctx, key, err)
  3875. return nil, err
  3876. }
  3877. // List all of the objects in the mock in the given region.
  3878. func (m *MockAlphaRegionBackendServices) List(ctx context.Context, region string, fl *filter.F) ([]*alpha.BackendService, error) {
  3879. if m.ListHook != nil {
  3880. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  3881. klog.V(5).Infof("MockAlphaRegionBackendServices.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  3882. return objs, err
  3883. }
  3884. }
  3885. m.Lock.Lock()
  3886. defer m.Lock.Unlock()
  3887. if m.ListError != nil {
  3888. err := *m.ListError
  3889. klog.V(5).Infof("MockAlphaRegionBackendServices.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  3890. return nil, *m.ListError
  3891. }
  3892. var objs []*alpha.BackendService
  3893. for key, obj := range m.Objects {
  3894. if key.Region != region {
  3895. continue
  3896. }
  3897. if !fl.Match(obj.ToAlpha()) {
  3898. continue
  3899. }
  3900. objs = append(objs, obj.ToAlpha())
  3901. }
  3902. klog.V(5).Infof("MockAlphaRegionBackendServices.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  3903. return objs, nil
  3904. }
  3905. // Insert is a mock for inserting/creating a new object.
  3906. func (m *MockAlphaRegionBackendServices) Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error {
  3907. if m.InsertHook != nil {
  3908. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  3909. klog.V(5).Infof("MockAlphaRegionBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3910. return err
  3911. }
  3912. }
  3913. if !key.Valid() {
  3914. return fmt.Errorf("invalid GCE key (%+v)", key)
  3915. }
  3916. m.Lock.Lock()
  3917. defer m.Lock.Unlock()
  3918. if err, ok := m.InsertError[*key]; ok {
  3919. klog.V(5).Infof("MockAlphaRegionBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3920. return err
  3921. }
  3922. if _, ok := m.Objects[*key]; ok {
  3923. err := &googleapi.Error{
  3924. Code: http.StatusConflict,
  3925. Message: fmt.Sprintf("MockAlphaRegionBackendServices %v exists", key),
  3926. }
  3927. klog.V(5).Infof("MockAlphaRegionBackendServices.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  3928. return err
  3929. }
  3930. obj.Name = key.Name
  3931. projectID := m.ProjectRouter.ProjectID(ctx, "alpha", "backendServices")
  3932. obj.SelfLink = SelfLink(meta.VersionAlpha, projectID, "backendServices", key)
  3933. m.Objects[*key] = &MockRegionBackendServicesObj{obj}
  3934. klog.V(5).Infof("MockAlphaRegionBackendServices.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  3935. return nil
  3936. }
  3937. // Delete is a mock for deleting the object.
  3938. func (m *MockAlphaRegionBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  3939. if m.DeleteHook != nil {
  3940. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  3941. klog.V(5).Infof("MockAlphaRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3942. return err
  3943. }
  3944. }
  3945. if !key.Valid() {
  3946. return fmt.Errorf("invalid GCE key (%+v)", key)
  3947. }
  3948. m.Lock.Lock()
  3949. defer m.Lock.Unlock()
  3950. if err, ok := m.DeleteError[*key]; ok {
  3951. klog.V(5).Infof("MockAlphaRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3952. return err
  3953. }
  3954. if _, ok := m.Objects[*key]; !ok {
  3955. err := &googleapi.Error{
  3956. Code: http.StatusNotFound,
  3957. Message: fmt.Sprintf("MockAlphaRegionBackendServices %v not found", key),
  3958. }
  3959. klog.V(5).Infof("MockAlphaRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  3960. return err
  3961. }
  3962. delete(m.Objects, *key)
  3963. klog.V(5).Infof("MockAlphaRegionBackendServices.Delete(%v, %v) = nil", ctx, key)
  3964. return nil
  3965. }
  3966. // Obj wraps the object for use in the mock.
  3967. func (m *MockAlphaRegionBackendServices) Obj(o *alpha.BackendService) *MockRegionBackendServicesObj {
  3968. return &MockRegionBackendServicesObj{o}
  3969. }
  3970. // GetHealth is a mock for the corresponding method.
  3971. func (m *MockAlphaRegionBackendServices) GetHealth(ctx context.Context, key *meta.Key, arg0 *alpha.ResourceGroupReference) (*alpha.BackendServiceGroupHealth, error) {
  3972. if m.GetHealthHook != nil {
  3973. return m.GetHealthHook(ctx, key, arg0, m)
  3974. }
  3975. return nil, fmt.Errorf("GetHealthHook must be set")
  3976. }
  3977. // Update is a mock for the corresponding method.
  3978. func (m *MockAlphaRegionBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error {
  3979. if m.UpdateHook != nil {
  3980. return m.UpdateHook(ctx, key, arg0, m)
  3981. }
  3982. return nil
  3983. }
  3984. // GCEAlphaRegionBackendServices is a simplifying adapter for the GCE RegionBackendServices.
  3985. type GCEAlphaRegionBackendServices struct {
  3986. s *Service
  3987. }
  3988. // Get the BackendService named by key.
  3989. func (g *GCEAlphaRegionBackendServices) Get(ctx context.Context, key *meta.Key) (*alpha.BackendService, error) {
  3990. klog.V(5).Infof("GCEAlphaRegionBackendServices.Get(%v, %v): called", ctx, key)
  3991. if !key.Valid() {
  3992. klog.V(2).Infof("GCEAlphaRegionBackendServices.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  3993. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  3994. }
  3995. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "RegionBackendServices")
  3996. rk := &RateLimitKey{
  3997. ProjectID: projectID,
  3998. Operation: "Get",
  3999. Version: meta.Version("alpha"),
  4000. Service: "RegionBackendServices",
  4001. }
  4002. klog.V(5).Infof("GCEAlphaRegionBackendServices.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4003. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4004. klog.V(4).Infof("GCEAlphaRegionBackendServices.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  4005. return nil, err
  4006. }
  4007. call := g.s.Alpha.RegionBackendServices.Get(projectID, key.Region, key.Name)
  4008. call.Context(ctx)
  4009. v, err := call.Do()
  4010. klog.V(4).Infof("GCEAlphaRegionBackendServices.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  4011. return v, err
  4012. }
  4013. // List all BackendService objects.
  4014. func (g *GCEAlphaRegionBackendServices) List(ctx context.Context, region string, fl *filter.F) ([]*alpha.BackendService, error) {
  4015. klog.V(5).Infof("GCEAlphaRegionBackendServices.List(%v, %v, %v) called", ctx, region, fl)
  4016. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "RegionBackendServices")
  4017. rk := &RateLimitKey{
  4018. ProjectID: projectID,
  4019. Operation: "List",
  4020. Version: meta.Version("alpha"),
  4021. Service: "RegionBackendServices",
  4022. }
  4023. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4024. return nil, err
  4025. }
  4026. klog.V(5).Infof("GCEAlphaRegionBackendServices.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  4027. call := g.s.Alpha.RegionBackendServices.List(projectID, region)
  4028. if fl != filter.None {
  4029. call.Filter(fl.String())
  4030. }
  4031. var all []*alpha.BackendService
  4032. f := func(l *alpha.BackendServiceList) error {
  4033. klog.V(5).Infof("GCEAlphaRegionBackendServices.List(%v, ..., %v): page %+v", ctx, fl, l)
  4034. all = append(all, l.Items...)
  4035. return nil
  4036. }
  4037. if err := call.Pages(ctx, f); err != nil {
  4038. klog.V(4).Infof("GCEAlphaRegionBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  4039. return nil, err
  4040. }
  4041. if klog.V(4) {
  4042. klog.V(4).Infof("GCEAlphaRegionBackendServices.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  4043. } else if klog.V(5) {
  4044. var asStr []string
  4045. for _, o := range all {
  4046. asStr = append(asStr, fmt.Sprintf("%+v", o))
  4047. }
  4048. klog.V(5).Infof("GCEAlphaRegionBackendServices.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  4049. }
  4050. return all, nil
  4051. }
  4052. // Insert BackendService with key of value obj.
  4053. func (g *GCEAlphaRegionBackendServices) Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error {
  4054. klog.V(5).Infof("GCEAlphaRegionBackendServices.Insert(%v, %v, %+v): called", ctx, key, obj)
  4055. if !key.Valid() {
  4056. klog.V(2).Infof("GCEAlphaRegionBackendServices.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  4057. return fmt.Errorf("invalid GCE key (%+v)", key)
  4058. }
  4059. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "RegionBackendServices")
  4060. rk := &RateLimitKey{
  4061. ProjectID: projectID,
  4062. Operation: "Insert",
  4063. Version: meta.Version("alpha"),
  4064. Service: "RegionBackendServices",
  4065. }
  4066. klog.V(5).Infof("GCEAlphaRegionBackendServices.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4067. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4068. klog.V(4).Infof("GCEAlphaRegionBackendServices.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  4069. return err
  4070. }
  4071. obj.Name = key.Name
  4072. call := g.s.Alpha.RegionBackendServices.Insert(projectID, key.Region, obj)
  4073. call.Context(ctx)
  4074. op, err := call.Do()
  4075. if err != nil {
  4076. klog.V(4).Infof("GCEAlphaRegionBackendServices.Insert(%v, %v, ...) = %+v", ctx, key, err)
  4077. return err
  4078. }
  4079. err = g.s.WaitForCompletion(ctx, op)
  4080. klog.V(4).Infof("GCEAlphaRegionBackendServices.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  4081. return err
  4082. }
  4083. // Delete the BackendService referenced by key.
  4084. func (g *GCEAlphaRegionBackendServices) Delete(ctx context.Context, key *meta.Key) error {
  4085. klog.V(5).Infof("GCEAlphaRegionBackendServices.Delete(%v, %v): called", ctx, key)
  4086. if !key.Valid() {
  4087. klog.V(2).Infof("GCEAlphaRegionBackendServices.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  4088. return fmt.Errorf("invalid GCE key (%+v)", key)
  4089. }
  4090. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "RegionBackendServices")
  4091. rk := &RateLimitKey{
  4092. ProjectID: projectID,
  4093. Operation: "Delete",
  4094. Version: meta.Version("alpha"),
  4095. Service: "RegionBackendServices",
  4096. }
  4097. klog.V(5).Infof("GCEAlphaRegionBackendServices.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4098. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4099. klog.V(4).Infof("GCEAlphaRegionBackendServices.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  4100. return err
  4101. }
  4102. call := g.s.Alpha.RegionBackendServices.Delete(projectID, key.Region, key.Name)
  4103. call.Context(ctx)
  4104. op, err := call.Do()
  4105. if err != nil {
  4106. klog.V(4).Infof("GCEAlphaRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  4107. return err
  4108. }
  4109. err = g.s.WaitForCompletion(ctx, op)
  4110. klog.V(4).Infof("GCEAlphaRegionBackendServices.Delete(%v, %v) = %v", ctx, key, err)
  4111. return err
  4112. }
  4113. // GetHealth is a method on GCEAlphaRegionBackendServices.
  4114. func (g *GCEAlphaRegionBackendServices) GetHealth(ctx context.Context, key *meta.Key, arg0 *alpha.ResourceGroupReference) (*alpha.BackendServiceGroupHealth, error) {
  4115. klog.V(5).Infof("GCEAlphaRegionBackendServices.GetHealth(%v, %v, ...): called", ctx, key)
  4116. if !key.Valid() {
  4117. klog.V(2).Infof("GCEAlphaRegionBackendServices.GetHealth(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  4118. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  4119. }
  4120. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "RegionBackendServices")
  4121. rk := &RateLimitKey{
  4122. ProjectID: projectID,
  4123. Operation: "GetHealth",
  4124. Version: meta.Version("alpha"),
  4125. Service: "RegionBackendServices",
  4126. }
  4127. klog.V(5).Infof("GCEAlphaRegionBackendServices.GetHealth(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4128. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4129. klog.V(4).Infof("GCEAlphaRegionBackendServices.GetHealth(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  4130. return nil, err
  4131. }
  4132. call := g.s.Alpha.RegionBackendServices.GetHealth(projectID, key.Region, key.Name, arg0)
  4133. call.Context(ctx)
  4134. v, err := call.Do()
  4135. klog.V(4).Infof("GCEAlphaRegionBackendServices.GetHealth(%v, %v, ...) = %+v, %v", ctx, key, v, err)
  4136. return v, err
  4137. }
  4138. // Update is a method on GCEAlphaRegionBackendServices.
  4139. func (g *GCEAlphaRegionBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error {
  4140. klog.V(5).Infof("GCEAlphaRegionBackendServices.Update(%v, %v, ...): called", ctx, key)
  4141. if !key.Valid() {
  4142. klog.V(2).Infof("GCEAlphaRegionBackendServices.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  4143. return fmt.Errorf("invalid GCE key (%+v)", key)
  4144. }
  4145. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "RegionBackendServices")
  4146. rk := &RateLimitKey{
  4147. ProjectID: projectID,
  4148. Operation: "Update",
  4149. Version: meta.Version("alpha"),
  4150. Service: "RegionBackendServices",
  4151. }
  4152. klog.V(5).Infof("GCEAlphaRegionBackendServices.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4153. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4154. klog.V(4).Infof("GCEAlphaRegionBackendServices.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  4155. return err
  4156. }
  4157. call := g.s.Alpha.RegionBackendServices.Update(projectID, key.Region, key.Name, arg0)
  4158. call.Context(ctx)
  4159. op, err := call.Do()
  4160. if err != nil {
  4161. klog.V(4).Infof("GCEAlphaRegionBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  4162. return err
  4163. }
  4164. err = g.s.WaitForCompletion(ctx, op)
  4165. klog.V(4).Infof("GCEAlphaRegionBackendServices.Update(%v, %v, ...) = %+v", ctx, key, err)
  4166. return err
  4167. }
  4168. // Disks is an interface that allows for mocking of Disks.
  4169. type Disks interface {
  4170. Get(ctx context.Context, key *meta.Key) (*ga.Disk, error)
  4171. List(ctx context.Context, zone string, fl *filter.F) ([]*ga.Disk, error)
  4172. Insert(ctx context.Context, key *meta.Key, obj *ga.Disk) error
  4173. Delete(ctx context.Context, key *meta.Key) error
  4174. Resize(context.Context, *meta.Key, *ga.DisksResizeRequest) error
  4175. }
  4176. // NewMockDisks returns a new mock for Disks.
  4177. func NewMockDisks(pr ProjectRouter, objs map[meta.Key]*MockDisksObj) *MockDisks {
  4178. mock := &MockDisks{
  4179. ProjectRouter: pr,
  4180. Objects: objs,
  4181. GetError: map[meta.Key]error{},
  4182. InsertError: map[meta.Key]error{},
  4183. DeleteError: map[meta.Key]error{},
  4184. }
  4185. return mock
  4186. }
  4187. // MockDisks is the mock for Disks.
  4188. type MockDisks struct {
  4189. Lock sync.Mutex
  4190. ProjectRouter ProjectRouter
  4191. // Objects maintained by the mock.
  4192. Objects map[meta.Key]*MockDisksObj
  4193. // If an entry exists for the given key and operation, then the error
  4194. // will be returned instead of the operation.
  4195. GetError map[meta.Key]error
  4196. ListError *error
  4197. InsertError map[meta.Key]error
  4198. DeleteError map[meta.Key]error
  4199. // xxxHook allow you to intercept the standard processing of the mock in
  4200. // order to add your own logic. Return (true, _, _) to prevent the normal
  4201. // execution flow of the mock. Return (false, nil, nil) to continue with
  4202. // normal mock behavior/ after the hook function executes.
  4203. GetHook func(ctx context.Context, key *meta.Key, m *MockDisks) (bool, *ga.Disk, error)
  4204. ListHook func(ctx context.Context, zone string, fl *filter.F, m *MockDisks) (bool, []*ga.Disk, error)
  4205. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.Disk, m *MockDisks) (bool, error)
  4206. DeleteHook func(ctx context.Context, key *meta.Key, m *MockDisks) (bool, error)
  4207. ResizeHook func(context.Context, *meta.Key, *ga.DisksResizeRequest, *MockDisks) error
  4208. // X is extra state that can be used as part of the mock. Generated code
  4209. // will not use this field.
  4210. X interface{}
  4211. }
  4212. // Get returns the object from the mock.
  4213. func (m *MockDisks) Get(ctx context.Context, key *meta.Key) (*ga.Disk, error) {
  4214. if m.GetHook != nil {
  4215. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  4216. klog.V(5).Infof("MockDisks.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  4217. return obj, err
  4218. }
  4219. }
  4220. if !key.Valid() {
  4221. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  4222. }
  4223. m.Lock.Lock()
  4224. defer m.Lock.Unlock()
  4225. if err, ok := m.GetError[*key]; ok {
  4226. klog.V(5).Infof("MockDisks.Get(%v, %s) = nil, %v", ctx, key, err)
  4227. return nil, err
  4228. }
  4229. if obj, ok := m.Objects[*key]; ok {
  4230. typedObj := obj.ToGA()
  4231. klog.V(5).Infof("MockDisks.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  4232. return typedObj, nil
  4233. }
  4234. err := &googleapi.Error{
  4235. Code: http.StatusNotFound,
  4236. Message: fmt.Sprintf("MockDisks %v not found", key),
  4237. }
  4238. klog.V(5).Infof("MockDisks.Get(%v, %s) = nil, %v", ctx, key, err)
  4239. return nil, err
  4240. }
  4241. // List all of the objects in the mock in the given zone.
  4242. func (m *MockDisks) List(ctx context.Context, zone string, fl *filter.F) ([]*ga.Disk, error) {
  4243. if m.ListHook != nil {
  4244. if intercept, objs, err := m.ListHook(ctx, zone, fl, m); intercept {
  4245. klog.V(5).Infof("MockDisks.List(%v, %q, %v) = [%v items], %v", ctx, zone, fl, len(objs), err)
  4246. return objs, err
  4247. }
  4248. }
  4249. m.Lock.Lock()
  4250. defer m.Lock.Unlock()
  4251. if m.ListError != nil {
  4252. err := *m.ListError
  4253. klog.V(5).Infof("MockDisks.List(%v, %q, %v) = nil, %v", ctx, zone, fl, err)
  4254. return nil, *m.ListError
  4255. }
  4256. var objs []*ga.Disk
  4257. for key, obj := range m.Objects {
  4258. if key.Zone != zone {
  4259. continue
  4260. }
  4261. if !fl.Match(obj.ToGA()) {
  4262. continue
  4263. }
  4264. objs = append(objs, obj.ToGA())
  4265. }
  4266. klog.V(5).Infof("MockDisks.List(%v, %q, %v) = [%v items], nil", ctx, zone, fl, len(objs))
  4267. return objs, nil
  4268. }
  4269. // Insert is a mock for inserting/creating a new object.
  4270. func (m *MockDisks) Insert(ctx context.Context, key *meta.Key, obj *ga.Disk) error {
  4271. if m.InsertHook != nil {
  4272. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  4273. klog.V(5).Infof("MockDisks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4274. return err
  4275. }
  4276. }
  4277. if !key.Valid() {
  4278. return fmt.Errorf("invalid GCE key (%+v)", key)
  4279. }
  4280. m.Lock.Lock()
  4281. defer m.Lock.Unlock()
  4282. if err, ok := m.InsertError[*key]; ok {
  4283. klog.V(5).Infof("MockDisks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4284. return err
  4285. }
  4286. if _, ok := m.Objects[*key]; ok {
  4287. err := &googleapi.Error{
  4288. Code: http.StatusConflict,
  4289. Message: fmt.Sprintf("MockDisks %v exists", key),
  4290. }
  4291. klog.V(5).Infof("MockDisks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4292. return err
  4293. }
  4294. obj.Name = key.Name
  4295. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "disks")
  4296. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "disks", key)
  4297. m.Objects[*key] = &MockDisksObj{obj}
  4298. klog.V(5).Infof("MockDisks.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  4299. return nil
  4300. }
  4301. // Delete is a mock for deleting the object.
  4302. func (m *MockDisks) Delete(ctx context.Context, key *meta.Key) error {
  4303. if m.DeleteHook != nil {
  4304. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  4305. klog.V(5).Infof("MockDisks.Delete(%v, %v) = %v", ctx, key, err)
  4306. return err
  4307. }
  4308. }
  4309. if !key.Valid() {
  4310. return fmt.Errorf("invalid GCE key (%+v)", key)
  4311. }
  4312. m.Lock.Lock()
  4313. defer m.Lock.Unlock()
  4314. if err, ok := m.DeleteError[*key]; ok {
  4315. klog.V(5).Infof("MockDisks.Delete(%v, %v) = %v", ctx, key, err)
  4316. return err
  4317. }
  4318. if _, ok := m.Objects[*key]; !ok {
  4319. err := &googleapi.Error{
  4320. Code: http.StatusNotFound,
  4321. Message: fmt.Sprintf("MockDisks %v not found", key),
  4322. }
  4323. klog.V(5).Infof("MockDisks.Delete(%v, %v) = %v", ctx, key, err)
  4324. return err
  4325. }
  4326. delete(m.Objects, *key)
  4327. klog.V(5).Infof("MockDisks.Delete(%v, %v) = nil", ctx, key)
  4328. return nil
  4329. }
  4330. // Obj wraps the object for use in the mock.
  4331. func (m *MockDisks) Obj(o *ga.Disk) *MockDisksObj {
  4332. return &MockDisksObj{o}
  4333. }
  4334. // Resize is a mock for the corresponding method.
  4335. func (m *MockDisks) Resize(ctx context.Context, key *meta.Key, arg0 *ga.DisksResizeRequest) error {
  4336. if m.ResizeHook != nil {
  4337. return m.ResizeHook(ctx, key, arg0, m)
  4338. }
  4339. return nil
  4340. }
  4341. // GCEDisks is a simplifying adapter for the GCE Disks.
  4342. type GCEDisks struct {
  4343. s *Service
  4344. }
  4345. // Get the Disk named by key.
  4346. func (g *GCEDisks) Get(ctx context.Context, key *meta.Key) (*ga.Disk, error) {
  4347. klog.V(5).Infof("GCEDisks.Get(%v, %v): called", ctx, key)
  4348. if !key.Valid() {
  4349. klog.V(2).Infof("GCEDisks.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  4350. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  4351. }
  4352. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Disks")
  4353. rk := &RateLimitKey{
  4354. ProjectID: projectID,
  4355. Operation: "Get",
  4356. Version: meta.Version("ga"),
  4357. Service: "Disks",
  4358. }
  4359. klog.V(5).Infof("GCEDisks.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4360. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4361. klog.V(4).Infof("GCEDisks.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  4362. return nil, err
  4363. }
  4364. call := g.s.GA.Disks.Get(projectID, key.Zone, key.Name)
  4365. call.Context(ctx)
  4366. v, err := call.Do()
  4367. klog.V(4).Infof("GCEDisks.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  4368. return v, err
  4369. }
  4370. // List all Disk objects.
  4371. func (g *GCEDisks) List(ctx context.Context, zone string, fl *filter.F) ([]*ga.Disk, error) {
  4372. klog.V(5).Infof("GCEDisks.List(%v, %v, %v) called", ctx, zone, fl)
  4373. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Disks")
  4374. rk := &RateLimitKey{
  4375. ProjectID: projectID,
  4376. Operation: "List",
  4377. Version: meta.Version("ga"),
  4378. Service: "Disks",
  4379. }
  4380. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4381. return nil, err
  4382. }
  4383. klog.V(5).Infof("GCEDisks.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
  4384. call := g.s.GA.Disks.List(projectID, zone)
  4385. if fl != filter.None {
  4386. call.Filter(fl.String())
  4387. }
  4388. var all []*ga.Disk
  4389. f := func(l *ga.DiskList) error {
  4390. klog.V(5).Infof("GCEDisks.List(%v, ..., %v): page %+v", ctx, fl, l)
  4391. all = append(all, l.Items...)
  4392. return nil
  4393. }
  4394. if err := call.Pages(ctx, f); err != nil {
  4395. klog.V(4).Infof("GCEDisks.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  4396. return nil, err
  4397. }
  4398. if klog.V(4) {
  4399. klog.V(4).Infof("GCEDisks.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  4400. } else if klog.V(5) {
  4401. var asStr []string
  4402. for _, o := range all {
  4403. asStr = append(asStr, fmt.Sprintf("%+v", o))
  4404. }
  4405. klog.V(5).Infof("GCEDisks.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  4406. }
  4407. return all, nil
  4408. }
  4409. // Insert Disk with key of value obj.
  4410. func (g *GCEDisks) Insert(ctx context.Context, key *meta.Key, obj *ga.Disk) error {
  4411. klog.V(5).Infof("GCEDisks.Insert(%v, %v, %+v): called", ctx, key, obj)
  4412. if !key.Valid() {
  4413. klog.V(2).Infof("GCEDisks.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  4414. return fmt.Errorf("invalid GCE key (%+v)", key)
  4415. }
  4416. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Disks")
  4417. rk := &RateLimitKey{
  4418. ProjectID: projectID,
  4419. Operation: "Insert",
  4420. Version: meta.Version("ga"),
  4421. Service: "Disks",
  4422. }
  4423. klog.V(5).Infof("GCEDisks.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4424. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4425. klog.V(4).Infof("GCEDisks.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  4426. return err
  4427. }
  4428. obj.Name = key.Name
  4429. call := g.s.GA.Disks.Insert(projectID, key.Zone, obj)
  4430. call.Context(ctx)
  4431. op, err := call.Do()
  4432. if err != nil {
  4433. klog.V(4).Infof("GCEDisks.Insert(%v, %v, ...) = %+v", ctx, key, err)
  4434. return err
  4435. }
  4436. err = g.s.WaitForCompletion(ctx, op)
  4437. klog.V(4).Infof("GCEDisks.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  4438. return err
  4439. }
  4440. // Delete the Disk referenced by key.
  4441. func (g *GCEDisks) Delete(ctx context.Context, key *meta.Key) error {
  4442. klog.V(5).Infof("GCEDisks.Delete(%v, %v): called", ctx, key)
  4443. if !key.Valid() {
  4444. klog.V(2).Infof("GCEDisks.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  4445. return fmt.Errorf("invalid GCE key (%+v)", key)
  4446. }
  4447. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Disks")
  4448. rk := &RateLimitKey{
  4449. ProjectID: projectID,
  4450. Operation: "Delete",
  4451. Version: meta.Version("ga"),
  4452. Service: "Disks",
  4453. }
  4454. klog.V(5).Infof("GCEDisks.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4455. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4456. klog.V(4).Infof("GCEDisks.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  4457. return err
  4458. }
  4459. call := g.s.GA.Disks.Delete(projectID, key.Zone, key.Name)
  4460. call.Context(ctx)
  4461. op, err := call.Do()
  4462. if err != nil {
  4463. klog.V(4).Infof("GCEDisks.Delete(%v, %v) = %v", ctx, key, err)
  4464. return err
  4465. }
  4466. err = g.s.WaitForCompletion(ctx, op)
  4467. klog.V(4).Infof("GCEDisks.Delete(%v, %v) = %v", ctx, key, err)
  4468. return err
  4469. }
  4470. // Resize is a method on GCEDisks.
  4471. func (g *GCEDisks) Resize(ctx context.Context, key *meta.Key, arg0 *ga.DisksResizeRequest) error {
  4472. klog.V(5).Infof("GCEDisks.Resize(%v, %v, ...): called", ctx, key)
  4473. if !key.Valid() {
  4474. klog.V(2).Infof("GCEDisks.Resize(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  4475. return fmt.Errorf("invalid GCE key (%+v)", key)
  4476. }
  4477. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Disks")
  4478. rk := &RateLimitKey{
  4479. ProjectID: projectID,
  4480. Operation: "Resize",
  4481. Version: meta.Version("ga"),
  4482. Service: "Disks",
  4483. }
  4484. klog.V(5).Infof("GCEDisks.Resize(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4485. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4486. klog.V(4).Infof("GCEDisks.Resize(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  4487. return err
  4488. }
  4489. call := g.s.GA.Disks.Resize(projectID, key.Zone, key.Name, arg0)
  4490. call.Context(ctx)
  4491. op, err := call.Do()
  4492. if err != nil {
  4493. klog.V(4).Infof("GCEDisks.Resize(%v, %v, ...) = %+v", ctx, key, err)
  4494. return err
  4495. }
  4496. err = g.s.WaitForCompletion(ctx, op)
  4497. klog.V(4).Infof("GCEDisks.Resize(%v, %v, ...) = %+v", ctx, key, err)
  4498. return err
  4499. }
  4500. // RegionDisks is an interface that allows for mocking of RegionDisks.
  4501. type RegionDisks interface {
  4502. Get(ctx context.Context, key *meta.Key) (*ga.Disk, error)
  4503. List(ctx context.Context, region string, fl *filter.F) ([]*ga.Disk, error)
  4504. Insert(ctx context.Context, key *meta.Key, obj *ga.Disk) error
  4505. Delete(ctx context.Context, key *meta.Key) error
  4506. Resize(context.Context, *meta.Key, *ga.RegionDisksResizeRequest) error
  4507. }
  4508. // NewMockRegionDisks returns a new mock for RegionDisks.
  4509. func NewMockRegionDisks(pr ProjectRouter, objs map[meta.Key]*MockRegionDisksObj) *MockRegionDisks {
  4510. mock := &MockRegionDisks{
  4511. ProjectRouter: pr,
  4512. Objects: objs,
  4513. GetError: map[meta.Key]error{},
  4514. InsertError: map[meta.Key]error{},
  4515. DeleteError: map[meta.Key]error{},
  4516. }
  4517. return mock
  4518. }
  4519. // MockRegionDisks is the mock for RegionDisks.
  4520. type MockRegionDisks struct {
  4521. Lock sync.Mutex
  4522. ProjectRouter ProjectRouter
  4523. // Objects maintained by the mock.
  4524. Objects map[meta.Key]*MockRegionDisksObj
  4525. // If an entry exists for the given key and operation, then the error
  4526. // will be returned instead of the operation.
  4527. GetError map[meta.Key]error
  4528. ListError *error
  4529. InsertError map[meta.Key]error
  4530. DeleteError map[meta.Key]error
  4531. // xxxHook allow you to intercept the standard processing of the mock in
  4532. // order to add your own logic. Return (true, _, _) to prevent the normal
  4533. // execution flow of the mock. Return (false, nil, nil) to continue with
  4534. // normal mock behavior/ after the hook function executes.
  4535. GetHook func(ctx context.Context, key *meta.Key, m *MockRegionDisks) (bool, *ga.Disk, error)
  4536. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockRegionDisks) (bool, []*ga.Disk, error)
  4537. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.Disk, m *MockRegionDisks) (bool, error)
  4538. DeleteHook func(ctx context.Context, key *meta.Key, m *MockRegionDisks) (bool, error)
  4539. ResizeHook func(context.Context, *meta.Key, *ga.RegionDisksResizeRequest, *MockRegionDisks) error
  4540. // X is extra state that can be used as part of the mock. Generated code
  4541. // will not use this field.
  4542. X interface{}
  4543. }
  4544. // Get returns the object from the mock.
  4545. func (m *MockRegionDisks) Get(ctx context.Context, key *meta.Key) (*ga.Disk, error) {
  4546. if m.GetHook != nil {
  4547. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  4548. klog.V(5).Infof("MockRegionDisks.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  4549. return obj, err
  4550. }
  4551. }
  4552. if !key.Valid() {
  4553. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  4554. }
  4555. m.Lock.Lock()
  4556. defer m.Lock.Unlock()
  4557. if err, ok := m.GetError[*key]; ok {
  4558. klog.V(5).Infof("MockRegionDisks.Get(%v, %s) = nil, %v", ctx, key, err)
  4559. return nil, err
  4560. }
  4561. if obj, ok := m.Objects[*key]; ok {
  4562. typedObj := obj.ToGA()
  4563. klog.V(5).Infof("MockRegionDisks.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  4564. return typedObj, nil
  4565. }
  4566. err := &googleapi.Error{
  4567. Code: http.StatusNotFound,
  4568. Message: fmt.Sprintf("MockRegionDisks %v not found", key),
  4569. }
  4570. klog.V(5).Infof("MockRegionDisks.Get(%v, %s) = nil, %v", ctx, key, err)
  4571. return nil, err
  4572. }
  4573. // List all of the objects in the mock in the given region.
  4574. func (m *MockRegionDisks) List(ctx context.Context, region string, fl *filter.F) ([]*ga.Disk, error) {
  4575. if m.ListHook != nil {
  4576. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  4577. klog.V(5).Infof("MockRegionDisks.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  4578. return objs, err
  4579. }
  4580. }
  4581. m.Lock.Lock()
  4582. defer m.Lock.Unlock()
  4583. if m.ListError != nil {
  4584. err := *m.ListError
  4585. klog.V(5).Infof("MockRegionDisks.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  4586. return nil, *m.ListError
  4587. }
  4588. var objs []*ga.Disk
  4589. for key, obj := range m.Objects {
  4590. if key.Region != region {
  4591. continue
  4592. }
  4593. if !fl.Match(obj.ToGA()) {
  4594. continue
  4595. }
  4596. objs = append(objs, obj.ToGA())
  4597. }
  4598. klog.V(5).Infof("MockRegionDisks.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  4599. return objs, nil
  4600. }
  4601. // Insert is a mock for inserting/creating a new object.
  4602. func (m *MockRegionDisks) Insert(ctx context.Context, key *meta.Key, obj *ga.Disk) error {
  4603. if m.InsertHook != nil {
  4604. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  4605. klog.V(5).Infof("MockRegionDisks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4606. return err
  4607. }
  4608. }
  4609. if !key.Valid() {
  4610. return fmt.Errorf("invalid GCE key (%+v)", key)
  4611. }
  4612. m.Lock.Lock()
  4613. defer m.Lock.Unlock()
  4614. if err, ok := m.InsertError[*key]; ok {
  4615. klog.V(5).Infof("MockRegionDisks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4616. return err
  4617. }
  4618. if _, ok := m.Objects[*key]; ok {
  4619. err := &googleapi.Error{
  4620. Code: http.StatusConflict,
  4621. Message: fmt.Sprintf("MockRegionDisks %v exists", key),
  4622. }
  4623. klog.V(5).Infof("MockRegionDisks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4624. return err
  4625. }
  4626. obj.Name = key.Name
  4627. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "disks")
  4628. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "disks", key)
  4629. m.Objects[*key] = &MockRegionDisksObj{obj}
  4630. klog.V(5).Infof("MockRegionDisks.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  4631. return nil
  4632. }
  4633. // Delete is a mock for deleting the object.
  4634. func (m *MockRegionDisks) Delete(ctx context.Context, key *meta.Key) error {
  4635. if m.DeleteHook != nil {
  4636. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  4637. klog.V(5).Infof("MockRegionDisks.Delete(%v, %v) = %v", ctx, key, err)
  4638. return err
  4639. }
  4640. }
  4641. if !key.Valid() {
  4642. return fmt.Errorf("invalid GCE key (%+v)", key)
  4643. }
  4644. m.Lock.Lock()
  4645. defer m.Lock.Unlock()
  4646. if err, ok := m.DeleteError[*key]; ok {
  4647. klog.V(5).Infof("MockRegionDisks.Delete(%v, %v) = %v", ctx, key, err)
  4648. return err
  4649. }
  4650. if _, ok := m.Objects[*key]; !ok {
  4651. err := &googleapi.Error{
  4652. Code: http.StatusNotFound,
  4653. Message: fmt.Sprintf("MockRegionDisks %v not found", key),
  4654. }
  4655. klog.V(5).Infof("MockRegionDisks.Delete(%v, %v) = %v", ctx, key, err)
  4656. return err
  4657. }
  4658. delete(m.Objects, *key)
  4659. klog.V(5).Infof("MockRegionDisks.Delete(%v, %v) = nil", ctx, key)
  4660. return nil
  4661. }
  4662. // Obj wraps the object for use in the mock.
  4663. func (m *MockRegionDisks) Obj(o *ga.Disk) *MockRegionDisksObj {
  4664. return &MockRegionDisksObj{o}
  4665. }
  4666. // Resize is a mock for the corresponding method.
  4667. func (m *MockRegionDisks) Resize(ctx context.Context, key *meta.Key, arg0 *ga.RegionDisksResizeRequest) error {
  4668. if m.ResizeHook != nil {
  4669. return m.ResizeHook(ctx, key, arg0, m)
  4670. }
  4671. return nil
  4672. }
  4673. // GCERegionDisks is a simplifying adapter for the GCE RegionDisks.
  4674. type GCERegionDisks struct {
  4675. s *Service
  4676. }
  4677. // Get the Disk named by key.
  4678. func (g *GCERegionDisks) Get(ctx context.Context, key *meta.Key) (*ga.Disk, error) {
  4679. klog.V(5).Infof("GCERegionDisks.Get(%v, %v): called", ctx, key)
  4680. if !key.Valid() {
  4681. klog.V(2).Infof("GCERegionDisks.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  4682. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  4683. }
  4684. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionDisks")
  4685. rk := &RateLimitKey{
  4686. ProjectID: projectID,
  4687. Operation: "Get",
  4688. Version: meta.Version("ga"),
  4689. Service: "RegionDisks",
  4690. }
  4691. klog.V(5).Infof("GCERegionDisks.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4692. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4693. klog.V(4).Infof("GCERegionDisks.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  4694. return nil, err
  4695. }
  4696. call := g.s.GA.RegionDisks.Get(projectID, key.Region, key.Name)
  4697. call.Context(ctx)
  4698. v, err := call.Do()
  4699. klog.V(4).Infof("GCERegionDisks.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  4700. return v, err
  4701. }
  4702. // List all Disk objects.
  4703. func (g *GCERegionDisks) List(ctx context.Context, region string, fl *filter.F) ([]*ga.Disk, error) {
  4704. klog.V(5).Infof("GCERegionDisks.List(%v, %v, %v) called", ctx, region, fl)
  4705. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionDisks")
  4706. rk := &RateLimitKey{
  4707. ProjectID: projectID,
  4708. Operation: "List",
  4709. Version: meta.Version("ga"),
  4710. Service: "RegionDisks",
  4711. }
  4712. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4713. return nil, err
  4714. }
  4715. klog.V(5).Infof("GCERegionDisks.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  4716. call := g.s.GA.RegionDisks.List(projectID, region)
  4717. if fl != filter.None {
  4718. call.Filter(fl.String())
  4719. }
  4720. var all []*ga.Disk
  4721. f := func(l *ga.DiskList) error {
  4722. klog.V(5).Infof("GCERegionDisks.List(%v, ..., %v): page %+v", ctx, fl, l)
  4723. all = append(all, l.Items...)
  4724. return nil
  4725. }
  4726. if err := call.Pages(ctx, f); err != nil {
  4727. klog.V(4).Infof("GCERegionDisks.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  4728. return nil, err
  4729. }
  4730. if klog.V(4) {
  4731. klog.V(4).Infof("GCERegionDisks.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  4732. } else if klog.V(5) {
  4733. var asStr []string
  4734. for _, o := range all {
  4735. asStr = append(asStr, fmt.Sprintf("%+v", o))
  4736. }
  4737. klog.V(5).Infof("GCERegionDisks.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  4738. }
  4739. return all, nil
  4740. }
  4741. // Insert Disk with key of value obj.
  4742. func (g *GCERegionDisks) Insert(ctx context.Context, key *meta.Key, obj *ga.Disk) error {
  4743. klog.V(5).Infof("GCERegionDisks.Insert(%v, %v, %+v): called", ctx, key, obj)
  4744. if !key.Valid() {
  4745. klog.V(2).Infof("GCERegionDisks.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  4746. return fmt.Errorf("invalid GCE key (%+v)", key)
  4747. }
  4748. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionDisks")
  4749. rk := &RateLimitKey{
  4750. ProjectID: projectID,
  4751. Operation: "Insert",
  4752. Version: meta.Version("ga"),
  4753. Service: "RegionDisks",
  4754. }
  4755. klog.V(5).Infof("GCERegionDisks.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4756. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4757. klog.V(4).Infof("GCERegionDisks.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  4758. return err
  4759. }
  4760. obj.Name = key.Name
  4761. call := g.s.GA.RegionDisks.Insert(projectID, key.Region, obj)
  4762. call.Context(ctx)
  4763. op, err := call.Do()
  4764. if err != nil {
  4765. klog.V(4).Infof("GCERegionDisks.Insert(%v, %v, ...) = %+v", ctx, key, err)
  4766. return err
  4767. }
  4768. err = g.s.WaitForCompletion(ctx, op)
  4769. klog.V(4).Infof("GCERegionDisks.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  4770. return err
  4771. }
  4772. // Delete the Disk referenced by key.
  4773. func (g *GCERegionDisks) Delete(ctx context.Context, key *meta.Key) error {
  4774. klog.V(5).Infof("GCERegionDisks.Delete(%v, %v): called", ctx, key)
  4775. if !key.Valid() {
  4776. klog.V(2).Infof("GCERegionDisks.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  4777. return fmt.Errorf("invalid GCE key (%+v)", key)
  4778. }
  4779. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionDisks")
  4780. rk := &RateLimitKey{
  4781. ProjectID: projectID,
  4782. Operation: "Delete",
  4783. Version: meta.Version("ga"),
  4784. Service: "RegionDisks",
  4785. }
  4786. klog.V(5).Infof("GCERegionDisks.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4787. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4788. klog.V(4).Infof("GCERegionDisks.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  4789. return err
  4790. }
  4791. call := g.s.GA.RegionDisks.Delete(projectID, key.Region, key.Name)
  4792. call.Context(ctx)
  4793. op, err := call.Do()
  4794. if err != nil {
  4795. klog.V(4).Infof("GCERegionDisks.Delete(%v, %v) = %v", ctx, key, err)
  4796. return err
  4797. }
  4798. err = g.s.WaitForCompletion(ctx, op)
  4799. klog.V(4).Infof("GCERegionDisks.Delete(%v, %v) = %v", ctx, key, err)
  4800. return err
  4801. }
  4802. // Resize is a method on GCERegionDisks.
  4803. func (g *GCERegionDisks) Resize(ctx context.Context, key *meta.Key, arg0 *ga.RegionDisksResizeRequest) error {
  4804. klog.V(5).Infof("GCERegionDisks.Resize(%v, %v, ...): called", ctx, key)
  4805. if !key.Valid() {
  4806. klog.V(2).Infof("GCERegionDisks.Resize(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  4807. return fmt.Errorf("invalid GCE key (%+v)", key)
  4808. }
  4809. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "RegionDisks")
  4810. rk := &RateLimitKey{
  4811. ProjectID: projectID,
  4812. Operation: "Resize",
  4813. Version: meta.Version("ga"),
  4814. Service: "RegionDisks",
  4815. }
  4816. klog.V(5).Infof("GCERegionDisks.Resize(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  4817. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  4818. klog.V(4).Infof("GCERegionDisks.Resize(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  4819. return err
  4820. }
  4821. call := g.s.GA.RegionDisks.Resize(projectID, key.Region, key.Name, arg0)
  4822. call.Context(ctx)
  4823. op, err := call.Do()
  4824. if err != nil {
  4825. klog.V(4).Infof("GCERegionDisks.Resize(%v, %v, ...) = %+v", ctx, key, err)
  4826. return err
  4827. }
  4828. err = g.s.WaitForCompletion(ctx, op)
  4829. klog.V(4).Infof("GCERegionDisks.Resize(%v, %v, ...) = %+v", ctx, key, err)
  4830. return err
  4831. }
  4832. // Firewalls is an interface that allows for mocking of Firewalls.
  4833. type Firewalls interface {
  4834. Get(ctx context.Context, key *meta.Key) (*ga.Firewall, error)
  4835. List(ctx context.Context, fl *filter.F) ([]*ga.Firewall, error)
  4836. Insert(ctx context.Context, key *meta.Key, obj *ga.Firewall) error
  4837. Delete(ctx context.Context, key *meta.Key) error
  4838. Update(context.Context, *meta.Key, *ga.Firewall) error
  4839. }
  4840. // NewMockFirewalls returns a new mock for Firewalls.
  4841. func NewMockFirewalls(pr ProjectRouter, objs map[meta.Key]*MockFirewallsObj) *MockFirewalls {
  4842. mock := &MockFirewalls{
  4843. ProjectRouter: pr,
  4844. Objects: objs,
  4845. GetError: map[meta.Key]error{},
  4846. InsertError: map[meta.Key]error{},
  4847. DeleteError: map[meta.Key]error{},
  4848. }
  4849. return mock
  4850. }
  4851. // MockFirewalls is the mock for Firewalls.
  4852. type MockFirewalls struct {
  4853. Lock sync.Mutex
  4854. ProjectRouter ProjectRouter
  4855. // Objects maintained by the mock.
  4856. Objects map[meta.Key]*MockFirewallsObj
  4857. // If an entry exists for the given key and operation, then the error
  4858. // will be returned instead of the operation.
  4859. GetError map[meta.Key]error
  4860. ListError *error
  4861. InsertError map[meta.Key]error
  4862. DeleteError map[meta.Key]error
  4863. // xxxHook allow you to intercept the standard processing of the mock in
  4864. // order to add your own logic. Return (true, _, _) to prevent the normal
  4865. // execution flow of the mock. Return (false, nil, nil) to continue with
  4866. // normal mock behavior/ after the hook function executes.
  4867. GetHook func(ctx context.Context, key *meta.Key, m *MockFirewalls) (bool, *ga.Firewall, error)
  4868. ListHook func(ctx context.Context, fl *filter.F, m *MockFirewalls) (bool, []*ga.Firewall, error)
  4869. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.Firewall, m *MockFirewalls) (bool, error)
  4870. DeleteHook func(ctx context.Context, key *meta.Key, m *MockFirewalls) (bool, error)
  4871. UpdateHook func(context.Context, *meta.Key, *ga.Firewall, *MockFirewalls) error
  4872. // X is extra state that can be used as part of the mock. Generated code
  4873. // will not use this field.
  4874. X interface{}
  4875. }
  4876. // Get returns the object from the mock.
  4877. func (m *MockFirewalls) Get(ctx context.Context, key *meta.Key) (*ga.Firewall, error) {
  4878. if m.GetHook != nil {
  4879. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  4880. klog.V(5).Infof("MockFirewalls.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  4881. return obj, err
  4882. }
  4883. }
  4884. if !key.Valid() {
  4885. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  4886. }
  4887. m.Lock.Lock()
  4888. defer m.Lock.Unlock()
  4889. if err, ok := m.GetError[*key]; ok {
  4890. klog.V(5).Infof("MockFirewalls.Get(%v, %s) = nil, %v", ctx, key, err)
  4891. return nil, err
  4892. }
  4893. if obj, ok := m.Objects[*key]; ok {
  4894. typedObj := obj.ToGA()
  4895. klog.V(5).Infof("MockFirewalls.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  4896. return typedObj, nil
  4897. }
  4898. err := &googleapi.Error{
  4899. Code: http.StatusNotFound,
  4900. Message: fmt.Sprintf("MockFirewalls %v not found", key),
  4901. }
  4902. klog.V(5).Infof("MockFirewalls.Get(%v, %s) = nil, %v", ctx, key, err)
  4903. return nil, err
  4904. }
  4905. // List all of the objects in the mock.
  4906. func (m *MockFirewalls) List(ctx context.Context, fl *filter.F) ([]*ga.Firewall, error) {
  4907. if m.ListHook != nil {
  4908. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  4909. klog.V(5).Infof("MockFirewalls.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  4910. return objs, err
  4911. }
  4912. }
  4913. m.Lock.Lock()
  4914. defer m.Lock.Unlock()
  4915. if m.ListError != nil {
  4916. err := *m.ListError
  4917. klog.V(5).Infof("MockFirewalls.List(%v, %v) = nil, %v", ctx, fl, err)
  4918. return nil, *m.ListError
  4919. }
  4920. var objs []*ga.Firewall
  4921. for _, obj := range m.Objects {
  4922. if !fl.Match(obj.ToGA()) {
  4923. continue
  4924. }
  4925. objs = append(objs, obj.ToGA())
  4926. }
  4927. klog.V(5).Infof("MockFirewalls.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  4928. return objs, nil
  4929. }
  4930. // Insert is a mock for inserting/creating a new object.
  4931. func (m *MockFirewalls) Insert(ctx context.Context, key *meta.Key, obj *ga.Firewall) error {
  4932. if m.InsertHook != nil {
  4933. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  4934. klog.V(5).Infof("MockFirewalls.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4935. return err
  4936. }
  4937. }
  4938. if !key.Valid() {
  4939. return fmt.Errorf("invalid GCE key (%+v)", key)
  4940. }
  4941. m.Lock.Lock()
  4942. defer m.Lock.Unlock()
  4943. if err, ok := m.InsertError[*key]; ok {
  4944. klog.V(5).Infof("MockFirewalls.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4945. return err
  4946. }
  4947. if _, ok := m.Objects[*key]; ok {
  4948. err := &googleapi.Error{
  4949. Code: http.StatusConflict,
  4950. Message: fmt.Sprintf("MockFirewalls %v exists", key),
  4951. }
  4952. klog.V(5).Infof("MockFirewalls.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  4953. return err
  4954. }
  4955. obj.Name = key.Name
  4956. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "firewalls")
  4957. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "firewalls", key)
  4958. m.Objects[*key] = &MockFirewallsObj{obj}
  4959. klog.V(5).Infof("MockFirewalls.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  4960. return nil
  4961. }
  4962. // Delete is a mock for deleting the object.
  4963. func (m *MockFirewalls) Delete(ctx context.Context, key *meta.Key) error {
  4964. if m.DeleteHook != nil {
  4965. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  4966. klog.V(5).Infof("MockFirewalls.Delete(%v, %v) = %v", ctx, key, err)
  4967. return err
  4968. }
  4969. }
  4970. if !key.Valid() {
  4971. return fmt.Errorf("invalid GCE key (%+v)", key)
  4972. }
  4973. m.Lock.Lock()
  4974. defer m.Lock.Unlock()
  4975. if err, ok := m.DeleteError[*key]; ok {
  4976. klog.V(5).Infof("MockFirewalls.Delete(%v, %v) = %v", ctx, key, err)
  4977. return err
  4978. }
  4979. if _, ok := m.Objects[*key]; !ok {
  4980. err := &googleapi.Error{
  4981. Code: http.StatusNotFound,
  4982. Message: fmt.Sprintf("MockFirewalls %v not found", key),
  4983. }
  4984. klog.V(5).Infof("MockFirewalls.Delete(%v, %v) = %v", ctx, key, err)
  4985. return err
  4986. }
  4987. delete(m.Objects, *key)
  4988. klog.V(5).Infof("MockFirewalls.Delete(%v, %v) = nil", ctx, key)
  4989. return nil
  4990. }
  4991. // Obj wraps the object for use in the mock.
  4992. func (m *MockFirewalls) Obj(o *ga.Firewall) *MockFirewallsObj {
  4993. return &MockFirewallsObj{o}
  4994. }
  4995. // Update is a mock for the corresponding method.
  4996. func (m *MockFirewalls) Update(ctx context.Context, key *meta.Key, arg0 *ga.Firewall) error {
  4997. if m.UpdateHook != nil {
  4998. return m.UpdateHook(ctx, key, arg0, m)
  4999. }
  5000. return nil
  5001. }
  5002. // GCEFirewalls is a simplifying adapter for the GCE Firewalls.
  5003. type GCEFirewalls struct {
  5004. s *Service
  5005. }
  5006. // Get the Firewall named by key.
  5007. func (g *GCEFirewalls) Get(ctx context.Context, key *meta.Key) (*ga.Firewall, error) {
  5008. klog.V(5).Infof("GCEFirewalls.Get(%v, %v): called", ctx, key)
  5009. if !key.Valid() {
  5010. klog.V(2).Infof("GCEFirewalls.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  5011. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  5012. }
  5013. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Firewalls")
  5014. rk := &RateLimitKey{
  5015. ProjectID: projectID,
  5016. Operation: "Get",
  5017. Version: meta.Version("ga"),
  5018. Service: "Firewalls",
  5019. }
  5020. klog.V(5).Infof("GCEFirewalls.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5021. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5022. klog.V(4).Infof("GCEFirewalls.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  5023. return nil, err
  5024. }
  5025. call := g.s.GA.Firewalls.Get(projectID, key.Name)
  5026. call.Context(ctx)
  5027. v, err := call.Do()
  5028. klog.V(4).Infof("GCEFirewalls.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  5029. return v, err
  5030. }
  5031. // List all Firewall objects.
  5032. func (g *GCEFirewalls) List(ctx context.Context, fl *filter.F) ([]*ga.Firewall, error) {
  5033. klog.V(5).Infof("GCEFirewalls.List(%v, %v) called", ctx, fl)
  5034. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Firewalls")
  5035. rk := &RateLimitKey{
  5036. ProjectID: projectID,
  5037. Operation: "List",
  5038. Version: meta.Version("ga"),
  5039. Service: "Firewalls",
  5040. }
  5041. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5042. return nil, err
  5043. }
  5044. klog.V(5).Infof("GCEFirewalls.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  5045. call := g.s.GA.Firewalls.List(projectID)
  5046. if fl != filter.None {
  5047. call.Filter(fl.String())
  5048. }
  5049. var all []*ga.Firewall
  5050. f := func(l *ga.FirewallList) error {
  5051. klog.V(5).Infof("GCEFirewalls.List(%v, ..., %v): page %+v", ctx, fl, l)
  5052. all = append(all, l.Items...)
  5053. return nil
  5054. }
  5055. if err := call.Pages(ctx, f); err != nil {
  5056. klog.V(4).Infof("GCEFirewalls.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  5057. return nil, err
  5058. }
  5059. if klog.V(4) {
  5060. klog.V(4).Infof("GCEFirewalls.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  5061. } else if klog.V(5) {
  5062. var asStr []string
  5063. for _, o := range all {
  5064. asStr = append(asStr, fmt.Sprintf("%+v", o))
  5065. }
  5066. klog.V(5).Infof("GCEFirewalls.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  5067. }
  5068. return all, nil
  5069. }
  5070. // Insert Firewall with key of value obj.
  5071. func (g *GCEFirewalls) Insert(ctx context.Context, key *meta.Key, obj *ga.Firewall) error {
  5072. klog.V(5).Infof("GCEFirewalls.Insert(%v, %v, %+v): called", ctx, key, obj)
  5073. if !key.Valid() {
  5074. klog.V(2).Infof("GCEFirewalls.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  5075. return fmt.Errorf("invalid GCE key (%+v)", key)
  5076. }
  5077. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Firewalls")
  5078. rk := &RateLimitKey{
  5079. ProjectID: projectID,
  5080. Operation: "Insert",
  5081. Version: meta.Version("ga"),
  5082. Service: "Firewalls",
  5083. }
  5084. klog.V(5).Infof("GCEFirewalls.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5085. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5086. klog.V(4).Infof("GCEFirewalls.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  5087. return err
  5088. }
  5089. obj.Name = key.Name
  5090. call := g.s.GA.Firewalls.Insert(projectID, obj)
  5091. call.Context(ctx)
  5092. op, err := call.Do()
  5093. if err != nil {
  5094. klog.V(4).Infof("GCEFirewalls.Insert(%v, %v, ...) = %+v", ctx, key, err)
  5095. return err
  5096. }
  5097. err = g.s.WaitForCompletion(ctx, op)
  5098. klog.V(4).Infof("GCEFirewalls.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  5099. return err
  5100. }
  5101. // Delete the Firewall referenced by key.
  5102. func (g *GCEFirewalls) Delete(ctx context.Context, key *meta.Key) error {
  5103. klog.V(5).Infof("GCEFirewalls.Delete(%v, %v): called", ctx, key)
  5104. if !key.Valid() {
  5105. klog.V(2).Infof("GCEFirewalls.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  5106. return fmt.Errorf("invalid GCE key (%+v)", key)
  5107. }
  5108. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Firewalls")
  5109. rk := &RateLimitKey{
  5110. ProjectID: projectID,
  5111. Operation: "Delete",
  5112. Version: meta.Version("ga"),
  5113. Service: "Firewalls",
  5114. }
  5115. klog.V(5).Infof("GCEFirewalls.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5116. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5117. klog.V(4).Infof("GCEFirewalls.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  5118. return err
  5119. }
  5120. call := g.s.GA.Firewalls.Delete(projectID, key.Name)
  5121. call.Context(ctx)
  5122. op, err := call.Do()
  5123. if err != nil {
  5124. klog.V(4).Infof("GCEFirewalls.Delete(%v, %v) = %v", ctx, key, err)
  5125. return err
  5126. }
  5127. err = g.s.WaitForCompletion(ctx, op)
  5128. klog.V(4).Infof("GCEFirewalls.Delete(%v, %v) = %v", ctx, key, err)
  5129. return err
  5130. }
  5131. // Update is a method on GCEFirewalls.
  5132. func (g *GCEFirewalls) Update(ctx context.Context, key *meta.Key, arg0 *ga.Firewall) error {
  5133. klog.V(5).Infof("GCEFirewalls.Update(%v, %v, ...): called", ctx, key)
  5134. if !key.Valid() {
  5135. klog.V(2).Infof("GCEFirewalls.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  5136. return fmt.Errorf("invalid GCE key (%+v)", key)
  5137. }
  5138. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Firewalls")
  5139. rk := &RateLimitKey{
  5140. ProjectID: projectID,
  5141. Operation: "Update",
  5142. Version: meta.Version("ga"),
  5143. Service: "Firewalls",
  5144. }
  5145. klog.V(5).Infof("GCEFirewalls.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5146. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5147. klog.V(4).Infof("GCEFirewalls.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  5148. return err
  5149. }
  5150. call := g.s.GA.Firewalls.Update(projectID, key.Name, arg0)
  5151. call.Context(ctx)
  5152. op, err := call.Do()
  5153. if err != nil {
  5154. klog.V(4).Infof("GCEFirewalls.Update(%v, %v, ...) = %+v", ctx, key, err)
  5155. return err
  5156. }
  5157. err = g.s.WaitForCompletion(ctx, op)
  5158. klog.V(4).Infof("GCEFirewalls.Update(%v, %v, ...) = %+v", ctx, key, err)
  5159. return err
  5160. }
  5161. // ForwardingRules is an interface that allows for mocking of ForwardingRules.
  5162. type ForwardingRules interface {
  5163. Get(ctx context.Context, key *meta.Key) (*ga.ForwardingRule, error)
  5164. List(ctx context.Context, region string, fl *filter.F) ([]*ga.ForwardingRule, error)
  5165. Insert(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule) error
  5166. Delete(ctx context.Context, key *meta.Key) error
  5167. }
  5168. // NewMockForwardingRules returns a new mock for ForwardingRules.
  5169. func NewMockForwardingRules(pr ProjectRouter, objs map[meta.Key]*MockForwardingRulesObj) *MockForwardingRules {
  5170. mock := &MockForwardingRules{
  5171. ProjectRouter: pr,
  5172. Objects: objs,
  5173. GetError: map[meta.Key]error{},
  5174. InsertError: map[meta.Key]error{},
  5175. DeleteError: map[meta.Key]error{},
  5176. }
  5177. return mock
  5178. }
  5179. // MockForwardingRules is the mock for ForwardingRules.
  5180. type MockForwardingRules struct {
  5181. Lock sync.Mutex
  5182. ProjectRouter ProjectRouter
  5183. // Objects maintained by the mock.
  5184. Objects map[meta.Key]*MockForwardingRulesObj
  5185. // If an entry exists for the given key and operation, then the error
  5186. // will be returned instead of the operation.
  5187. GetError map[meta.Key]error
  5188. ListError *error
  5189. InsertError map[meta.Key]error
  5190. DeleteError map[meta.Key]error
  5191. // xxxHook allow you to intercept the standard processing of the mock in
  5192. // order to add your own logic. Return (true, _, _) to prevent the normal
  5193. // execution flow of the mock. Return (false, nil, nil) to continue with
  5194. // normal mock behavior/ after the hook function executes.
  5195. GetHook func(ctx context.Context, key *meta.Key, m *MockForwardingRules) (bool, *ga.ForwardingRule, error)
  5196. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockForwardingRules) (bool, []*ga.ForwardingRule, error)
  5197. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule, m *MockForwardingRules) (bool, error)
  5198. DeleteHook func(ctx context.Context, key *meta.Key, m *MockForwardingRules) (bool, error)
  5199. // X is extra state that can be used as part of the mock. Generated code
  5200. // will not use this field.
  5201. X interface{}
  5202. }
  5203. // Get returns the object from the mock.
  5204. func (m *MockForwardingRules) Get(ctx context.Context, key *meta.Key) (*ga.ForwardingRule, error) {
  5205. if m.GetHook != nil {
  5206. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  5207. klog.V(5).Infof("MockForwardingRules.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  5208. return obj, err
  5209. }
  5210. }
  5211. if !key.Valid() {
  5212. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  5213. }
  5214. m.Lock.Lock()
  5215. defer m.Lock.Unlock()
  5216. if err, ok := m.GetError[*key]; ok {
  5217. klog.V(5).Infof("MockForwardingRules.Get(%v, %s) = nil, %v", ctx, key, err)
  5218. return nil, err
  5219. }
  5220. if obj, ok := m.Objects[*key]; ok {
  5221. typedObj := obj.ToGA()
  5222. klog.V(5).Infof("MockForwardingRules.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  5223. return typedObj, nil
  5224. }
  5225. err := &googleapi.Error{
  5226. Code: http.StatusNotFound,
  5227. Message: fmt.Sprintf("MockForwardingRules %v not found", key),
  5228. }
  5229. klog.V(5).Infof("MockForwardingRules.Get(%v, %s) = nil, %v", ctx, key, err)
  5230. return nil, err
  5231. }
  5232. // List all of the objects in the mock in the given region.
  5233. func (m *MockForwardingRules) List(ctx context.Context, region string, fl *filter.F) ([]*ga.ForwardingRule, error) {
  5234. if m.ListHook != nil {
  5235. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  5236. klog.V(5).Infof("MockForwardingRules.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  5237. return objs, err
  5238. }
  5239. }
  5240. m.Lock.Lock()
  5241. defer m.Lock.Unlock()
  5242. if m.ListError != nil {
  5243. err := *m.ListError
  5244. klog.V(5).Infof("MockForwardingRules.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  5245. return nil, *m.ListError
  5246. }
  5247. var objs []*ga.ForwardingRule
  5248. for key, obj := range m.Objects {
  5249. if key.Region != region {
  5250. continue
  5251. }
  5252. if !fl.Match(obj.ToGA()) {
  5253. continue
  5254. }
  5255. objs = append(objs, obj.ToGA())
  5256. }
  5257. klog.V(5).Infof("MockForwardingRules.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  5258. return objs, nil
  5259. }
  5260. // Insert is a mock for inserting/creating a new object.
  5261. func (m *MockForwardingRules) Insert(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule) error {
  5262. if m.InsertHook != nil {
  5263. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  5264. klog.V(5).Infof("MockForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5265. return err
  5266. }
  5267. }
  5268. if !key.Valid() {
  5269. return fmt.Errorf("invalid GCE key (%+v)", key)
  5270. }
  5271. m.Lock.Lock()
  5272. defer m.Lock.Unlock()
  5273. if err, ok := m.InsertError[*key]; ok {
  5274. klog.V(5).Infof("MockForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5275. return err
  5276. }
  5277. if _, ok := m.Objects[*key]; ok {
  5278. err := &googleapi.Error{
  5279. Code: http.StatusConflict,
  5280. Message: fmt.Sprintf("MockForwardingRules %v exists", key),
  5281. }
  5282. klog.V(5).Infof("MockForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5283. return err
  5284. }
  5285. obj.Name = key.Name
  5286. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "forwardingRules")
  5287. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "forwardingRules", key)
  5288. m.Objects[*key] = &MockForwardingRulesObj{obj}
  5289. klog.V(5).Infof("MockForwardingRules.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  5290. return nil
  5291. }
  5292. // Delete is a mock for deleting the object.
  5293. func (m *MockForwardingRules) Delete(ctx context.Context, key *meta.Key) error {
  5294. if m.DeleteHook != nil {
  5295. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  5296. klog.V(5).Infof("MockForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5297. return err
  5298. }
  5299. }
  5300. if !key.Valid() {
  5301. return fmt.Errorf("invalid GCE key (%+v)", key)
  5302. }
  5303. m.Lock.Lock()
  5304. defer m.Lock.Unlock()
  5305. if err, ok := m.DeleteError[*key]; ok {
  5306. klog.V(5).Infof("MockForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5307. return err
  5308. }
  5309. if _, ok := m.Objects[*key]; !ok {
  5310. err := &googleapi.Error{
  5311. Code: http.StatusNotFound,
  5312. Message: fmt.Sprintf("MockForwardingRules %v not found", key),
  5313. }
  5314. klog.V(5).Infof("MockForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5315. return err
  5316. }
  5317. delete(m.Objects, *key)
  5318. klog.V(5).Infof("MockForwardingRules.Delete(%v, %v) = nil", ctx, key)
  5319. return nil
  5320. }
  5321. // Obj wraps the object for use in the mock.
  5322. func (m *MockForwardingRules) Obj(o *ga.ForwardingRule) *MockForwardingRulesObj {
  5323. return &MockForwardingRulesObj{o}
  5324. }
  5325. // GCEForwardingRules is a simplifying adapter for the GCE ForwardingRules.
  5326. type GCEForwardingRules struct {
  5327. s *Service
  5328. }
  5329. // Get the ForwardingRule named by key.
  5330. func (g *GCEForwardingRules) Get(ctx context.Context, key *meta.Key) (*ga.ForwardingRule, error) {
  5331. klog.V(5).Infof("GCEForwardingRules.Get(%v, %v): called", ctx, key)
  5332. if !key.Valid() {
  5333. klog.V(2).Infof("GCEForwardingRules.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  5334. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  5335. }
  5336. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "ForwardingRules")
  5337. rk := &RateLimitKey{
  5338. ProjectID: projectID,
  5339. Operation: "Get",
  5340. Version: meta.Version("ga"),
  5341. Service: "ForwardingRules",
  5342. }
  5343. klog.V(5).Infof("GCEForwardingRules.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5344. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5345. klog.V(4).Infof("GCEForwardingRules.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  5346. return nil, err
  5347. }
  5348. call := g.s.GA.ForwardingRules.Get(projectID, key.Region, key.Name)
  5349. call.Context(ctx)
  5350. v, err := call.Do()
  5351. klog.V(4).Infof("GCEForwardingRules.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  5352. return v, err
  5353. }
  5354. // List all ForwardingRule objects.
  5355. func (g *GCEForwardingRules) List(ctx context.Context, region string, fl *filter.F) ([]*ga.ForwardingRule, error) {
  5356. klog.V(5).Infof("GCEForwardingRules.List(%v, %v, %v) called", ctx, region, fl)
  5357. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "ForwardingRules")
  5358. rk := &RateLimitKey{
  5359. ProjectID: projectID,
  5360. Operation: "List",
  5361. Version: meta.Version("ga"),
  5362. Service: "ForwardingRules",
  5363. }
  5364. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5365. return nil, err
  5366. }
  5367. klog.V(5).Infof("GCEForwardingRules.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  5368. call := g.s.GA.ForwardingRules.List(projectID, region)
  5369. if fl != filter.None {
  5370. call.Filter(fl.String())
  5371. }
  5372. var all []*ga.ForwardingRule
  5373. f := func(l *ga.ForwardingRuleList) error {
  5374. klog.V(5).Infof("GCEForwardingRules.List(%v, ..., %v): page %+v", ctx, fl, l)
  5375. all = append(all, l.Items...)
  5376. return nil
  5377. }
  5378. if err := call.Pages(ctx, f); err != nil {
  5379. klog.V(4).Infof("GCEForwardingRules.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  5380. return nil, err
  5381. }
  5382. if klog.V(4) {
  5383. klog.V(4).Infof("GCEForwardingRules.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  5384. } else if klog.V(5) {
  5385. var asStr []string
  5386. for _, o := range all {
  5387. asStr = append(asStr, fmt.Sprintf("%+v", o))
  5388. }
  5389. klog.V(5).Infof("GCEForwardingRules.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  5390. }
  5391. return all, nil
  5392. }
  5393. // Insert ForwardingRule with key of value obj.
  5394. func (g *GCEForwardingRules) Insert(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule) error {
  5395. klog.V(5).Infof("GCEForwardingRules.Insert(%v, %v, %+v): called", ctx, key, obj)
  5396. if !key.Valid() {
  5397. klog.V(2).Infof("GCEForwardingRules.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  5398. return fmt.Errorf("invalid GCE key (%+v)", key)
  5399. }
  5400. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "ForwardingRules")
  5401. rk := &RateLimitKey{
  5402. ProjectID: projectID,
  5403. Operation: "Insert",
  5404. Version: meta.Version("ga"),
  5405. Service: "ForwardingRules",
  5406. }
  5407. klog.V(5).Infof("GCEForwardingRules.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5408. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5409. klog.V(4).Infof("GCEForwardingRules.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  5410. return err
  5411. }
  5412. obj.Name = key.Name
  5413. call := g.s.GA.ForwardingRules.Insert(projectID, key.Region, obj)
  5414. call.Context(ctx)
  5415. op, err := call.Do()
  5416. if err != nil {
  5417. klog.V(4).Infof("GCEForwardingRules.Insert(%v, %v, ...) = %+v", ctx, key, err)
  5418. return err
  5419. }
  5420. err = g.s.WaitForCompletion(ctx, op)
  5421. klog.V(4).Infof("GCEForwardingRules.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  5422. return err
  5423. }
  5424. // Delete the ForwardingRule referenced by key.
  5425. func (g *GCEForwardingRules) Delete(ctx context.Context, key *meta.Key) error {
  5426. klog.V(5).Infof("GCEForwardingRules.Delete(%v, %v): called", ctx, key)
  5427. if !key.Valid() {
  5428. klog.V(2).Infof("GCEForwardingRules.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  5429. return fmt.Errorf("invalid GCE key (%+v)", key)
  5430. }
  5431. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "ForwardingRules")
  5432. rk := &RateLimitKey{
  5433. ProjectID: projectID,
  5434. Operation: "Delete",
  5435. Version: meta.Version("ga"),
  5436. Service: "ForwardingRules",
  5437. }
  5438. klog.V(5).Infof("GCEForwardingRules.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5439. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5440. klog.V(4).Infof("GCEForwardingRules.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  5441. return err
  5442. }
  5443. call := g.s.GA.ForwardingRules.Delete(projectID, key.Region, key.Name)
  5444. call.Context(ctx)
  5445. op, err := call.Do()
  5446. if err != nil {
  5447. klog.V(4).Infof("GCEForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5448. return err
  5449. }
  5450. err = g.s.WaitForCompletion(ctx, op)
  5451. klog.V(4).Infof("GCEForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5452. return err
  5453. }
  5454. // AlphaForwardingRules is an interface that allows for mocking of ForwardingRules.
  5455. type AlphaForwardingRules interface {
  5456. Get(ctx context.Context, key *meta.Key) (*alpha.ForwardingRule, error)
  5457. List(ctx context.Context, region string, fl *filter.F) ([]*alpha.ForwardingRule, error)
  5458. Insert(ctx context.Context, key *meta.Key, obj *alpha.ForwardingRule) error
  5459. Delete(ctx context.Context, key *meta.Key) error
  5460. }
  5461. // NewMockAlphaForwardingRules returns a new mock for ForwardingRules.
  5462. func NewMockAlphaForwardingRules(pr ProjectRouter, objs map[meta.Key]*MockForwardingRulesObj) *MockAlphaForwardingRules {
  5463. mock := &MockAlphaForwardingRules{
  5464. ProjectRouter: pr,
  5465. Objects: objs,
  5466. GetError: map[meta.Key]error{},
  5467. InsertError: map[meta.Key]error{},
  5468. DeleteError: map[meta.Key]error{},
  5469. }
  5470. return mock
  5471. }
  5472. // MockAlphaForwardingRules is the mock for ForwardingRules.
  5473. type MockAlphaForwardingRules struct {
  5474. Lock sync.Mutex
  5475. ProjectRouter ProjectRouter
  5476. // Objects maintained by the mock.
  5477. Objects map[meta.Key]*MockForwardingRulesObj
  5478. // If an entry exists for the given key and operation, then the error
  5479. // will be returned instead of the operation.
  5480. GetError map[meta.Key]error
  5481. ListError *error
  5482. InsertError map[meta.Key]error
  5483. DeleteError map[meta.Key]error
  5484. // xxxHook allow you to intercept the standard processing of the mock in
  5485. // order to add your own logic. Return (true, _, _) to prevent the normal
  5486. // execution flow of the mock. Return (false, nil, nil) to continue with
  5487. // normal mock behavior/ after the hook function executes.
  5488. GetHook func(ctx context.Context, key *meta.Key, m *MockAlphaForwardingRules) (bool, *alpha.ForwardingRule, error)
  5489. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockAlphaForwardingRules) (bool, []*alpha.ForwardingRule, error)
  5490. InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.ForwardingRule, m *MockAlphaForwardingRules) (bool, error)
  5491. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaForwardingRules) (bool, error)
  5492. // X is extra state that can be used as part of the mock. Generated code
  5493. // will not use this field.
  5494. X interface{}
  5495. }
  5496. // Get returns the object from the mock.
  5497. func (m *MockAlphaForwardingRules) Get(ctx context.Context, key *meta.Key) (*alpha.ForwardingRule, error) {
  5498. if m.GetHook != nil {
  5499. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  5500. klog.V(5).Infof("MockAlphaForwardingRules.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  5501. return obj, err
  5502. }
  5503. }
  5504. if !key.Valid() {
  5505. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  5506. }
  5507. m.Lock.Lock()
  5508. defer m.Lock.Unlock()
  5509. if err, ok := m.GetError[*key]; ok {
  5510. klog.V(5).Infof("MockAlphaForwardingRules.Get(%v, %s) = nil, %v", ctx, key, err)
  5511. return nil, err
  5512. }
  5513. if obj, ok := m.Objects[*key]; ok {
  5514. typedObj := obj.ToAlpha()
  5515. klog.V(5).Infof("MockAlphaForwardingRules.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  5516. return typedObj, nil
  5517. }
  5518. err := &googleapi.Error{
  5519. Code: http.StatusNotFound,
  5520. Message: fmt.Sprintf("MockAlphaForwardingRules %v not found", key),
  5521. }
  5522. klog.V(5).Infof("MockAlphaForwardingRules.Get(%v, %s) = nil, %v", ctx, key, err)
  5523. return nil, err
  5524. }
  5525. // List all of the objects in the mock in the given region.
  5526. func (m *MockAlphaForwardingRules) List(ctx context.Context, region string, fl *filter.F) ([]*alpha.ForwardingRule, error) {
  5527. if m.ListHook != nil {
  5528. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  5529. klog.V(5).Infof("MockAlphaForwardingRules.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  5530. return objs, err
  5531. }
  5532. }
  5533. m.Lock.Lock()
  5534. defer m.Lock.Unlock()
  5535. if m.ListError != nil {
  5536. err := *m.ListError
  5537. klog.V(5).Infof("MockAlphaForwardingRules.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  5538. return nil, *m.ListError
  5539. }
  5540. var objs []*alpha.ForwardingRule
  5541. for key, obj := range m.Objects {
  5542. if key.Region != region {
  5543. continue
  5544. }
  5545. if !fl.Match(obj.ToAlpha()) {
  5546. continue
  5547. }
  5548. objs = append(objs, obj.ToAlpha())
  5549. }
  5550. klog.V(5).Infof("MockAlphaForwardingRules.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  5551. return objs, nil
  5552. }
  5553. // Insert is a mock for inserting/creating a new object.
  5554. func (m *MockAlphaForwardingRules) Insert(ctx context.Context, key *meta.Key, obj *alpha.ForwardingRule) error {
  5555. if m.InsertHook != nil {
  5556. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  5557. klog.V(5).Infof("MockAlphaForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5558. return err
  5559. }
  5560. }
  5561. if !key.Valid() {
  5562. return fmt.Errorf("invalid GCE key (%+v)", key)
  5563. }
  5564. m.Lock.Lock()
  5565. defer m.Lock.Unlock()
  5566. if err, ok := m.InsertError[*key]; ok {
  5567. klog.V(5).Infof("MockAlphaForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5568. return err
  5569. }
  5570. if _, ok := m.Objects[*key]; ok {
  5571. err := &googleapi.Error{
  5572. Code: http.StatusConflict,
  5573. Message: fmt.Sprintf("MockAlphaForwardingRules %v exists", key),
  5574. }
  5575. klog.V(5).Infof("MockAlphaForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5576. return err
  5577. }
  5578. obj.Name = key.Name
  5579. projectID := m.ProjectRouter.ProjectID(ctx, "alpha", "forwardingRules")
  5580. obj.SelfLink = SelfLink(meta.VersionAlpha, projectID, "forwardingRules", key)
  5581. m.Objects[*key] = &MockForwardingRulesObj{obj}
  5582. klog.V(5).Infof("MockAlphaForwardingRules.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  5583. return nil
  5584. }
  5585. // Delete is a mock for deleting the object.
  5586. func (m *MockAlphaForwardingRules) Delete(ctx context.Context, key *meta.Key) error {
  5587. if m.DeleteHook != nil {
  5588. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  5589. klog.V(5).Infof("MockAlphaForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5590. return err
  5591. }
  5592. }
  5593. if !key.Valid() {
  5594. return fmt.Errorf("invalid GCE key (%+v)", key)
  5595. }
  5596. m.Lock.Lock()
  5597. defer m.Lock.Unlock()
  5598. if err, ok := m.DeleteError[*key]; ok {
  5599. klog.V(5).Infof("MockAlphaForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5600. return err
  5601. }
  5602. if _, ok := m.Objects[*key]; !ok {
  5603. err := &googleapi.Error{
  5604. Code: http.StatusNotFound,
  5605. Message: fmt.Sprintf("MockAlphaForwardingRules %v not found", key),
  5606. }
  5607. klog.V(5).Infof("MockAlphaForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5608. return err
  5609. }
  5610. delete(m.Objects, *key)
  5611. klog.V(5).Infof("MockAlphaForwardingRules.Delete(%v, %v) = nil", ctx, key)
  5612. return nil
  5613. }
  5614. // Obj wraps the object for use in the mock.
  5615. func (m *MockAlphaForwardingRules) Obj(o *alpha.ForwardingRule) *MockForwardingRulesObj {
  5616. return &MockForwardingRulesObj{o}
  5617. }
  5618. // GCEAlphaForwardingRules is a simplifying adapter for the GCE ForwardingRules.
  5619. type GCEAlphaForwardingRules struct {
  5620. s *Service
  5621. }
  5622. // Get the ForwardingRule named by key.
  5623. func (g *GCEAlphaForwardingRules) Get(ctx context.Context, key *meta.Key) (*alpha.ForwardingRule, error) {
  5624. klog.V(5).Infof("GCEAlphaForwardingRules.Get(%v, %v): called", ctx, key)
  5625. if !key.Valid() {
  5626. klog.V(2).Infof("GCEAlphaForwardingRules.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  5627. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  5628. }
  5629. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "ForwardingRules")
  5630. rk := &RateLimitKey{
  5631. ProjectID: projectID,
  5632. Operation: "Get",
  5633. Version: meta.Version("alpha"),
  5634. Service: "ForwardingRules",
  5635. }
  5636. klog.V(5).Infof("GCEAlphaForwardingRules.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5637. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5638. klog.V(4).Infof("GCEAlphaForwardingRules.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  5639. return nil, err
  5640. }
  5641. call := g.s.Alpha.ForwardingRules.Get(projectID, key.Region, key.Name)
  5642. call.Context(ctx)
  5643. v, err := call.Do()
  5644. klog.V(4).Infof("GCEAlphaForwardingRules.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  5645. return v, err
  5646. }
  5647. // List all ForwardingRule objects.
  5648. func (g *GCEAlphaForwardingRules) List(ctx context.Context, region string, fl *filter.F) ([]*alpha.ForwardingRule, error) {
  5649. klog.V(5).Infof("GCEAlphaForwardingRules.List(%v, %v, %v) called", ctx, region, fl)
  5650. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "ForwardingRules")
  5651. rk := &RateLimitKey{
  5652. ProjectID: projectID,
  5653. Operation: "List",
  5654. Version: meta.Version("alpha"),
  5655. Service: "ForwardingRules",
  5656. }
  5657. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5658. return nil, err
  5659. }
  5660. klog.V(5).Infof("GCEAlphaForwardingRules.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  5661. call := g.s.Alpha.ForwardingRules.List(projectID, region)
  5662. if fl != filter.None {
  5663. call.Filter(fl.String())
  5664. }
  5665. var all []*alpha.ForwardingRule
  5666. f := func(l *alpha.ForwardingRuleList) error {
  5667. klog.V(5).Infof("GCEAlphaForwardingRules.List(%v, ..., %v): page %+v", ctx, fl, l)
  5668. all = append(all, l.Items...)
  5669. return nil
  5670. }
  5671. if err := call.Pages(ctx, f); err != nil {
  5672. klog.V(4).Infof("GCEAlphaForwardingRules.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  5673. return nil, err
  5674. }
  5675. if klog.V(4) {
  5676. klog.V(4).Infof("GCEAlphaForwardingRules.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  5677. } else if klog.V(5) {
  5678. var asStr []string
  5679. for _, o := range all {
  5680. asStr = append(asStr, fmt.Sprintf("%+v", o))
  5681. }
  5682. klog.V(5).Infof("GCEAlphaForwardingRules.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  5683. }
  5684. return all, nil
  5685. }
  5686. // Insert ForwardingRule with key of value obj.
  5687. func (g *GCEAlphaForwardingRules) Insert(ctx context.Context, key *meta.Key, obj *alpha.ForwardingRule) error {
  5688. klog.V(5).Infof("GCEAlphaForwardingRules.Insert(%v, %v, %+v): called", ctx, key, obj)
  5689. if !key.Valid() {
  5690. klog.V(2).Infof("GCEAlphaForwardingRules.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  5691. return fmt.Errorf("invalid GCE key (%+v)", key)
  5692. }
  5693. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "ForwardingRules")
  5694. rk := &RateLimitKey{
  5695. ProjectID: projectID,
  5696. Operation: "Insert",
  5697. Version: meta.Version("alpha"),
  5698. Service: "ForwardingRules",
  5699. }
  5700. klog.V(5).Infof("GCEAlphaForwardingRules.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5701. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5702. klog.V(4).Infof("GCEAlphaForwardingRules.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  5703. return err
  5704. }
  5705. obj.Name = key.Name
  5706. call := g.s.Alpha.ForwardingRules.Insert(projectID, key.Region, obj)
  5707. call.Context(ctx)
  5708. op, err := call.Do()
  5709. if err != nil {
  5710. klog.V(4).Infof("GCEAlphaForwardingRules.Insert(%v, %v, ...) = %+v", ctx, key, err)
  5711. return err
  5712. }
  5713. err = g.s.WaitForCompletion(ctx, op)
  5714. klog.V(4).Infof("GCEAlphaForwardingRules.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  5715. return err
  5716. }
  5717. // Delete the ForwardingRule referenced by key.
  5718. func (g *GCEAlphaForwardingRules) Delete(ctx context.Context, key *meta.Key) error {
  5719. klog.V(5).Infof("GCEAlphaForwardingRules.Delete(%v, %v): called", ctx, key)
  5720. if !key.Valid() {
  5721. klog.V(2).Infof("GCEAlphaForwardingRules.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  5722. return fmt.Errorf("invalid GCE key (%+v)", key)
  5723. }
  5724. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "ForwardingRules")
  5725. rk := &RateLimitKey{
  5726. ProjectID: projectID,
  5727. Operation: "Delete",
  5728. Version: meta.Version("alpha"),
  5729. Service: "ForwardingRules",
  5730. }
  5731. klog.V(5).Infof("GCEAlphaForwardingRules.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5732. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5733. klog.V(4).Infof("GCEAlphaForwardingRules.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  5734. return err
  5735. }
  5736. call := g.s.Alpha.ForwardingRules.Delete(projectID, key.Region, key.Name)
  5737. call.Context(ctx)
  5738. op, err := call.Do()
  5739. if err != nil {
  5740. klog.V(4).Infof("GCEAlphaForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5741. return err
  5742. }
  5743. err = g.s.WaitForCompletion(ctx, op)
  5744. klog.V(4).Infof("GCEAlphaForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5745. return err
  5746. }
  5747. // GlobalForwardingRules is an interface that allows for mocking of GlobalForwardingRules.
  5748. type GlobalForwardingRules interface {
  5749. Get(ctx context.Context, key *meta.Key) (*ga.ForwardingRule, error)
  5750. List(ctx context.Context, fl *filter.F) ([]*ga.ForwardingRule, error)
  5751. Insert(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule) error
  5752. Delete(ctx context.Context, key *meta.Key) error
  5753. SetTarget(context.Context, *meta.Key, *ga.TargetReference) error
  5754. }
  5755. // NewMockGlobalForwardingRules returns a new mock for GlobalForwardingRules.
  5756. func NewMockGlobalForwardingRules(pr ProjectRouter, objs map[meta.Key]*MockGlobalForwardingRulesObj) *MockGlobalForwardingRules {
  5757. mock := &MockGlobalForwardingRules{
  5758. ProjectRouter: pr,
  5759. Objects: objs,
  5760. GetError: map[meta.Key]error{},
  5761. InsertError: map[meta.Key]error{},
  5762. DeleteError: map[meta.Key]error{},
  5763. }
  5764. return mock
  5765. }
  5766. // MockGlobalForwardingRules is the mock for GlobalForwardingRules.
  5767. type MockGlobalForwardingRules struct {
  5768. Lock sync.Mutex
  5769. ProjectRouter ProjectRouter
  5770. // Objects maintained by the mock.
  5771. Objects map[meta.Key]*MockGlobalForwardingRulesObj
  5772. // If an entry exists for the given key and operation, then the error
  5773. // will be returned instead of the operation.
  5774. GetError map[meta.Key]error
  5775. ListError *error
  5776. InsertError map[meta.Key]error
  5777. DeleteError map[meta.Key]error
  5778. // xxxHook allow you to intercept the standard processing of the mock in
  5779. // order to add your own logic. Return (true, _, _) to prevent the normal
  5780. // execution flow of the mock. Return (false, nil, nil) to continue with
  5781. // normal mock behavior/ after the hook function executes.
  5782. GetHook func(ctx context.Context, key *meta.Key, m *MockGlobalForwardingRules) (bool, *ga.ForwardingRule, error)
  5783. ListHook func(ctx context.Context, fl *filter.F, m *MockGlobalForwardingRules) (bool, []*ga.ForwardingRule, error)
  5784. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule, m *MockGlobalForwardingRules) (bool, error)
  5785. DeleteHook func(ctx context.Context, key *meta.Key, m *MockGlobalForwardingRules) (bool, error)
  5786. SetTargetHook func(context.Context, *meta.Key, *ga.TargetReference, *MockGlobalForwardingRules) error
  5787. // X is extra state that can be used as part of the mock. Generated code
  5788. // will not use this field.
  5789. X interface{}
  5790. }
  5791. // Get returns the object from the mock.
  5792. func (m *MockGlobalForwardingRules) Get(ctx context.Context, key *meta.Key) (*ga.ForwardingRule, error) {
  5793. if m.GetHook != nil {
  5794. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  5795. klog.V(5).Infof("MockGlobalForwardingRules.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  5796. return obj, err
  5797. }
  5798. }
  5799. if !key.Valid() {
  5800. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  5801. }
  5802. m.Lock.Lock()
  5803. defer m.Lock.Unlock()
  5804. if err, ok := m.GetError[*key]; ok {
  5805. klog.V(5).Infof("MockGlobalForwardingRules.Get(%v, %s) = nil, %v", ctx, key, err)
  5806. return nil, err
  5807. }
  5808. if obj, ok := m.Objects[*key]; ok {
  5809. typedObj := obj.ToGA()
  5810. klog.V(5).Infof("MockGlobalForwardingRules.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  5811. return typedObj, nil
  5812. }
  5813. err := &googleapi.Error{
  5814. Code: http.StatusNotFound,
  5815. Message: fmt.Sprintf("MockGlobalForwardingRules %v not found", key),
  5816. }
  5817. klog.V(5).Infof("MockGlobalForwardingRules.Get(%v, %s) = nil, %v", ctx, key, err)
  5818. return nil, err
  5819. }
  5820. // List all of the objects in the mock.
  5821. func (m *MockGlobalForwardingRules) List(ctx context.Context, fl *filter.F) ([]*ga.ForwardingRule, error) {
  5822. if m.ListHook != nil {
  5823. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  5824. klog.V(5).Infof("MockGlobalForwardingRules.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  5825. return objs, err
  5826. }
  5827. }
  5828. m.Lock.Lock()
  5829. defer m.Lock.Unlock()
  5830. if m.ListError != nil {
  5831. err := *m.ListError
  5832. klog.V(5).Infof("MockGlobalForwardingRules.List(%v, %v) = nil, %v", ctx, fl, err)
  5833. return nil, *m.ListError
  5834. }
  5835. var objs []*ga.ForwardingRule
  5836. for _, obj := range m.Objects {
  5837. if !fl.Match(obj.ToGA()) {
  5838. continue
  5839. }
  5840. objs = append(objs, obj.ToGA())
  5841. }
  5842. klog.V(5).Infof("MockGlobalForwardingRules.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  5843. return objs, nil
  5844. }
  5845. // Insert is a mock for inserting/creating a new object.
  5846. func (m *MockGlobalForwardingRules) Insert(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule) error {
  5847. if m.InsertHook != nil {
  5848. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  5849. klog.V(5).Infof("MockGlobalForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5850. return err
  5851. }
  5852. }
  5853. if !key.Valid() {
  5854. return fmt.Errorf("invalid GCE key (%+v)", key)
  5855. }
  5856. m.Lock.Lock()
  5857. defer m.Lock.Unlock()
  5858. if err, ok := m.InsertError[*key]; ok {
  5859. klog.V(5).Infof("MockGlobalForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5860. return err
  5861. }
  5862. if _, ok := m.Objects[*key]; ok {
  5863. err := &googleapi.Error{
  5864. Code: http.StatusConflict,
  5865. Message: fmt.Sprintf("MockGlobalForwardingRules %v exists", key),
  5866. }
  5867. klog.V(5).Infof("MockGlobalForwardingRules.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  5868. return err
  5869. }
  5870. obj.Name = key.Name
  5871. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "forwardingRules")
  5872. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "forwardingRules", key)
  5873. m.Objects[*key] = &MockGlobalForwardingRulesObj{obj}
  5874. klog.V(5).Infof("MockGlobalForwardingRules.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  5875. return nil
  5876. }
  5877. // Delete is a mock for deleting the object.
  5878. func (m *MockGlobalForwardingRules) Delete(ctx context.Context, key *meta.Key) error {
  5879. if m.DeleteHook != nil {
  5880. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  5881. klog.V(5).Infof("MockGlobalForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5882. return err
  5883. }
  5884. }
  5885. if !key.Valid() {
  5886. return fmt.Errorf("invalid GCE key (%+v)", key)
  5887. }
  5888. m.Lock.Lock()
  5889. defer m.Lock.Unlock()
  5890. if err, ok := m.DeleteError[*key]; ok {
  5891. klog.V(5).Infof("MockGlobalForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5892. return err
  5893. }
  5894. if _, ok := m.Objects[*key]; !ok {
  5895. err := &googleapi.Error{
  5896. Code: http.StatusNotFound,
  5897. Message: fmt.Sprintf("MockGlobalForwardingRules %v not found", key),
  5898. }
  5899. klog.V(5).Infof("MockGlobalForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  5900. return err
  5901. }
  5902. delete(m.Objects, *key)
  5903. klog.V(5).Infof("MockGlobalForwardingRules.Delete(%v, %v) = nil", ctx, key)
  5904. return nil
  5905. }
  5906. // Obj wraps the object for use in the mock.
  5907. func (m *MockGlobalForwardingRules) Obj(o *ga.ForwardingRule) *MockGlobalForwardingRulesObj {
  5908. return &MockGlobalForwardingRulesObj{o}
  5909. }
  5910. // SetTarget is a mock for the corresponding method.
  5911. func (m *MockGlobalForwardingRules) SetTarget(ctx context.Context, key *meta.Key, arg0 *ga.TargetReference) error {
  5912. if m.SetTargetHook != nil {
  5913. return m.SetTargetHook(ctx, key, arg0, m)
  5914. }
  5915. return nil
  5916. }
  5917. // GCEGlobalForwardingRules is a simplifying adapter for the GCE GlobalForwardingRules.
  5918. type GCEGlobalForwardingRules struct {
  5919. s *Service
  5920. }
  5921. // Get the ForwardingRule named by key.
  5922. func (g *GCEGlobalForwardingRules) Get(ctx context.Context, key *meta.Key) (*ga.ForwardingRule, error) {
  5923. klog.V(5).Infof("GCEGlobalForwardingRules.Get(%v, %v): called", ctx, key)
  5924. if !key.Valid() {
  5925. klog.V(2).Infof("GCEGlobalForwardingRules.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  5926. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  5927. }
  5928. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalForwardingRules")
  5929. rk := &RateLimitKey{
  5930. ProjectID: projectID,
  5931. Operation: "Get",
  5932. Version: meta.Version("ga"),
  5933. Service: "GlobalForwardingRules",
  5934. }
  5935. klog.V(5).Infof("GCEGlobalForwardingRules.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  5936. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5937. klog.V(4).Infof("GCEGlobalForwardingRules.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  5938. return nil, err
  5939. }
  5940. call := g.s.GA.GlobalForwardingRules.Get(projectID, key.Name)
  5941. call.Context(ctx)
  5942. v, err := call.Do()
  5943. klog.V(4).Infof("GCEGlobalForwardingRules.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  5944. return v, err
  5945. }
  5946. // List all ForwardingRule objects.
  5947. func (g *GCEGlobalForwardingRules) List(ctx context.Context, fl *filter.F) ([]*ga.ForwardingRule, error) {
  5948. klog.V(5).Infof("GCEGlobalForwardingRules.List(%v, %v) called", ctx, fl)
  5949. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalForwardingRules")
  5950. rk := &RateLimitKey{
  5951. ProjectID: projectID,
  5952. Operation: "List",
  5953. Version: meta.Version("ga"),
  5954. Service: "GlobalForwardingRules",
  5955. }
  5956. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  5957. return nil, err
  5958. }
  5959. klog.V(5).Infof("GCEGlobalForwardingRules.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  5960. call := g.s.GA.GlobalForwardingRules.List(projectID)
  5961. if fl != filter.None {
  5962. call.Filter(fl.String())
  5963. }
  5964. var all []*ga.ForwardingRule
  5965. f := func(l *ga.ForwardingRuleList) error {
  5966. klog.V(5).Infof("GCEGlobalForwardingRules.List(%v, ..., %v): page %+v", ctx, fl, l)
  5967. all = append(all, l.Items...)
  5968. return nil
  5969. }
  5970. if err := call.Pages(ctx, f); err != nil {
  5971. klog.V(4).Infof("GCEGlobalForwardingRules.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  5972. return nil, err
  5973. }
  5974. if klog.V(4) {
  5975. klog.V(4).Infof("GCEGlobalForwardingRules.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  5976. } else if klog.V(5) {
  5977. var asStr []string
  5978. for _, o := range all {
  5979. asStr = append(asStr, fmt.Sprintf("%+v", o))
  5980. }
  5981. klog.V(5).Infof("GCEGlobalForwardingRules.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  5982. }
  5983. return all, nil
  5984. }
  5985. // Insert ForwardingRule with key of value obj.
  5986. func (g *GCEGlobalForwardingRules) Insert(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule) error {
  5987. klog.V(5).Infof("GCEGlobalForwardingRules.Insert(%v, %v, %+v): called", ctx, key, obj)
  5988. if !key.Valid() {
  5989. klog.V(2).Infof("GCEGlobalForwardingRules.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  5990. return fmt.Errorf("invalid GCE key (%+v)", key)
  5991. }
  5992. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalForwardingRules")
  5993. rk := &RateLimitKey{
  5994. ProjectID: projectID,
  5995. Operation: "Insert",
  5996. Version: meta.Version("ga"),
  5997. Service: "GlobalForwardingRules",
  5998. }
  5999. klog.V(5).Infof("GCEGlobalForwardingRules.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6000. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6001. klog.V(4).Infof("GCEGlobalForwardingRules.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  6002. return err
  6003. }
  6004. obj.Name = key.Name
  6005. call := g.s.GA.GlobalForwardingRules.Insert(projectID, obj)
  6006. call.Context(ctx)
  6007. op, err := call.Do()
  6008. if err != nil {
  6009. klog.V(4).Infof("GCEGlobalForwardingRules.Insert(%v, %v, ...) = %+v", ctx, key, err)
  6010. return err
  6011. }
  6012. err = g.s.WaitForCompletion(ctx, op)
  6013. klog.V(4).Infof("GCEGlobalForwardingRules.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  6014. return err
  6015. }
  6016. // Delete the ForwardingRule referenced by key.
  6017. func (g *GCEGlobalForwardingRules) Delete(ctx context.Context, key *meta.Key) error {
  6018. klog.V(5).Infof("GCEGlobalForwardingRules.Delete(%v, %v): called", ctx, key)
  6019. if !key.Valid() {
  6020. klog.V(2).Infof("GCEGlobalForwardingRules.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  6021. return fmt.Errorf("invalid GCE key (%+v)", key)
  6022. }
  6023. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalForwardingRules")
  6024. rk := &RateLimitKey{
  6025. ProjectID: projectID,
  6026. Operation: "Delete",
  6027. Version: meta.Version("ga"),
  6028. Service: "GlobalForwardingRules",
  6029. }
  6030. klog.V(5).Infof("GCEGlobalForwardingRules.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6031. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6032. klog.V(4).Infof("GCEGlobalForwardingRules.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  6033. return err
  6034. }
  6035. call := g.s.GA.GlobalForwardingRules.Delete(projectID, key.Name)
  6036. call.Context(ctx)
  6037. op, err := call.Do()
  6038. if err != nil {
  6039. klog.V(4).Infof("GCEGlobalForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  6040. return err
  6041. }
  6042. err = g.s.WaitForCompletion(ctx, op)
  6043. klog.V(4).Infof("GCEGlobalForwardingRules.Delete(%v, %v) = %v", ctx, key, err)
  6044. return err
  6045. }
  6046. // SetTarget is a method on GCEGlobalForwardingRules.
  6047. func (g *GCEGlobalForwardingRules) SetTarget(ctx context.Context, key *meta.Key, arg0 *ga.TargetReference) error {
  6048. klog.V(5).Infof("GCEGlobalForwardingRules.SetTarget(%v, %v, ...): called", ctx, key)
  6049. if !key.Valid() {
  6050. klog.V(2).Infof("GCEGlobalForwardingRules.SetTarget(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  6051. return fmt.Errorf("invalid GCE key (%+v)", key)
  6052. }
  6053. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "GlobalForwardingRules")
  6054. rk := &RateLimitKey{
  6055. ProjectID: projectID,
  6056. Operation: "SetTarget",
  6057. Version: meta.Version("ga"),
  6058. Service: "GlobalForwardingRules",
  6059. }
  6060. klog.V(5).Infof("GCEGlobalForwardingRules.SetTarget(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6061. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6062. klog.V(4).Infof("GCEGlobalForwardingRules.SetTarget(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  6063. return err
  6064. }
  6065. call := g.s.GA.GlobalForwardingRules.SetTarget(projectID, key.Name, arg0)
  6066. call.Context(ctx)
  6067. op, err := call.Do()
  6068. if err != nil {
  6069. klog.V(4).Infof("GCEGlobalForwardingRules.SetTarget(%v, %v, ...) = %+v", ctx, key, err)
  6070. return err
  6071. }
  6072. err = g.s.WaitForCompletion(ctx, op)
  6073. klog.V(4).Infof("GCEGlobalForwardingRules.SetTarget(%v, %v, ...) = %+v", ctx, key, err)
  6074. return err
  6075. }
  6076. // HealthChecks is an interface that allows for mocking of HealthChecks.
  6077. type HealthChecks interface {
  6078. Get(ctx context.Context, key *meta.Key) (*ga.HealthCheck, error)
  6079. List(ctx context.Context, fl *filter.F) ([]*ga.HealthCheck, error)
  6080. Insert(ctx context.Context, key *meta.Key, obj *ga.HealthCheck) error
  6081. Delete(ctx context.Context, key *meta.Key) error
  6082. Update(context.Context, *meta.Key, *ga.HealthCheck) error
  6083. }
  6084. // NewMockHealthChecks returns a new mock for HealthChecks.
  6085. func NewMockHealthChecks(pr ProjectRouter, objs map[meta.Key]*MockHealthChecksObj) *MockHealthChecks {
  6086. mock := &MockHealthChecks{
  6087. ProjectRouter: pr,
  6088. Objects: objs,
  6089. GetError: map[meta.Key]error{},
  6090. InsertError: map[meta.Key]error{},
  6091. DeleteError: map[meta.Key]error{},
  6092. }
  6093. return mock
  6094. }
  6095. // MockHealthChecks is the mock for HealthChecks.
  6096. type MockHealthChecks struct {
  6097. Lock sync.Mutex
  6098. ProjectRouter ProjectRouter
  6099. // Objects maintained by the mock.
  6100. Objects map[meta.Key]*MockHealthChecksObj
  6101. // If an entry exists for the given key and operation, then the error
  6102. // will be returned instead of the operation.
  6103. GetError map[meta.Key]error
  6104. ListError *error
  6105. InsertError map[meta.Key]error
  6106. DeleteError map[meta.Key]error
  6107. // xxxHook allow you to intercept the standard processing of the mock in
  6108. // order to add your own logic. Return (true, _, _) to prevent the normal
  6109. // execution flow of the mock. Return (false, nil, nil) to continue with
  6110. // normal mock behavior/ after the hook function executes.
  6111. GetHook func(ctx context.Context, key *meta.Key, m *MockHealthChecks) (bool, *ga.HealthCheck, error)
  6112. ListHook func(ctx context.Context, fl *filter.F, m *MockHealthChecks) (bool, []*ga.HealthCheck, error)
  6113. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.HealthCheck, m *MockHealthChecks) (bool, error)
  6114. DeleteHook func(ctx context.Context, key *meta.Key, m *MockHealthChecks) (bool, error)
  6115. UpdateHook func(context.Context, *meta.Key, *ga.HealthCheck, *MockHealthChecks) error
  6116. // X is extra state that can be used as part of the mock. Generated code
  6117. // will not use this field.
  6118. X interface{}
  6119. }
  6120. // Get returns the object from the mock.
  6121. func (m *MockHealthChecks) Get(ctx context.Context, key *meta.Key) (*ga.HealthCheck, error) {
  6122. if m.GetHook != nil {
  6123. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  6124. klog.V(5).Infof("MockHealthChecks.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  6125. return obj, err
  6126. }
  6127. }
  6128. if !key.Valid() {
  6129. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  6130. }
  6131. m.Lock.Lock()
  6132. defer m.Lock.Unlock()
  6133. if err, ok := m.GetError[*key]; ok {
  6134. klog.V(5).Infof("MockHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  6135. return nil, err
  6136. }
  6137. if obj, ok := m.Objects[*key]; ok {
  6138. typedObj := obj.ToGA()
  6139. klog.V(5).Infof("MockHealthChecks.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  6140. return typedObj, nil
  6141. }
  6142. err := &googleapi.Error{
  6143. Code: http.StatusNotFound,
  6144. Message: fmt.Sprintf("MockHealthChecks %v not found", key),
  6145. }
  6146. klog.V(5).Infof("MockHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  6147. return nil, err
  6148. }
  6149. // List all of the objects in the mock.
  6150. func (m *MockHealthChecks) List(ctx context.Context, fl *filter.F) ([]*ga.HealthCheck, error) {
  6151. if m.ListHook != nil {
  6152. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  6153. klog.V(5).Infof("MockHealthChecks.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  6154. return objs, err
  6155. }
  6156. }
  6157. m.Lock.Lock()
  6158. defer m.Lock.Unlock()
  6159. if m.ListError != nil {
  6160. err := *m.ListError
  6161. klog.V(5).Infof("MockHealthChecks.List(%v, %v) = nil, %v", ctx, fl, err)
  6162. return nil, *m.ListError
  6163. }
  6164. var objs []*ga.HealthCheck
  6165. for _, obj := range m.Objects {
  6166. if !fl.Match(obj.ToGA()) {
  6167. continue
  6168. }
  6169. objs = append(objs, obj.ToGA())
  6170. }
  6171. klog.V(5).Infof("MockHealthChecks.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  6172. return objs, nil
  6173. }
  6174. // Insert is a mock for inserting/creating a new object.
  6175. func (m *MockHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *ga.HealthCheck) error {
  6176. if m.InsertHook != nil {
  6177. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  6178. klog.V(5).Infof("MockHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6179. return err
  6180. }
  6181. }
  6182. if !key.Valid() {
  6183. return fmt.Errorf("invalid GCE key (%+v)", key)
  6184. }
  6185. m.Lock.Lock()
  6186. defer m.Lock.Unlock()
  6187. if err, ok := m.InsertError[*key]; ok {
  6188. klog.V(5).Infof("MockHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6189. return err
  6190. }
  6191. if _, ok := m.Objects[*key]; ok {
  6192. err := &googleapi.Error{
  6193. Code: http.StatusConflict,
  6194. Message: fmt.Sprintf("MockHealthChecks %v exists", key),
  6195. }
  6196. klog.V(5).Infof("MockHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6197. return err
  6198. }
  6199. obj.Name = key.Name
  6200. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "healthChecks")
  6201. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "healthChecks", key)
  6202. m.Objects[*key] = &MockHealthChecksObj{obj}
  6203. klog.V(5).Infof("MockHealthChecks.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  6204. return nil
  6205. }
  6206. // Delete is a mock for deleting the object.
  6207. func (m *MockHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  6208. if m.DeleteHook != nil {
  6209. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  6210. klog.V(5).Infof("MockHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6211. return err
  6212. }
  6213. }
  6214. if !key.Valid() {
  6215. return fmt.Errorf("invalid GCE key (%+v)", key)
  6216. }
  6217. m.Lock.Lock()
  6218. defer m.Lock.Unlock()
  6219. if err, ok := m.DeleteError[*key]; ok {
  6220. klog.V(5).Infof("MockHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6221. return err
  6222. }
  6223. if _, ok := m.Objects[*key]; !ok {
  6224. err := &googleapi.Error{
  6225. Code: http.StatusNotFound,
  6226. Message: fmt.Sprintf("MockHealthChecks %v not found", key),
  6227. }
  6228. klog.V(5).Infof("MockHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6229. return err
  6230. }
  6231. delete(m.Objects, *key)
  6232. klog.V(5).Infof("MockHealthChecks.Delete(%v, %v) = nil", ctx, key)
  6233. return nil
  6234. }
  6235. // Obj wraps the object for use in the mock.
  6236. func (m *MockHealthChecks) Obj(o *ga.HealthCheck) *MockHealthChecksObj {
  6237. return &MockHealthChecksObj{o}
  6238. }
  6239. // Update is a mock for the corresponding method.
  6240. func (m *MockHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *ga.HealthCheck) error {
  6241. if m.UpdateHook != nil {
  6242. return m.UpdateHook(ctx, key, arg0, m)
  6243. }
  6244. return nil
  6245. }
  6246. // GCEHealthChecks is a simplifying adapter for the GCE HealthChecks.
  6247. type GCEHealthChecks struct {
  6248. s *Service
  6249. }
  6250. // Get the HealthCheck named by key.
  6251. func (g *GCEHealthChecks) Get(ctx context.Context, key *meta.Key) (*ga.HealthCheck, error) {
  6252. klog.V(5).Infof("GCEHealthChecks.Get(%v, %v): called", ctx, key)
  6253. if !key.Valid() {
  6254. klog.V(2).Infof("GCEHealthChecks.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  6255. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  6256. }
  6257. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HealthChecks")
  6258. rk := &RateLimitKey{
  6259. ProjectID: projectID,
  6260. Operation: "Get",
  6261. Version: meta.Version("ga"),
  6262. Service: "HealthChecks",
  6263. }
  6264. klog.V(5).Infof("GCEHealthChecks.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6265. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6266. klog.V(4).Infof("GCEHealthChecks.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  6267. return nil, err
  6268. }
  6269. call := g.s.GA.HealthChecks.Get(projectID, key.Name)
  6270. call.Context(ctx)
  6271. v, err := call.Do()
  6272. klog.V(4).Infof("GCEHealthChecks.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  6273. return v, err
  6274. }
  6275. // List all HealthCheck objects.
  6276. func (g *GCEHealthChecks) List(ctx context.Context, fl *filter.F) ([]*ga.HealthCheck, error) {
  6277. klog.V(5).Infof("GCEHealthChecks.List(%v, %v) called", ctx, fl)
  6278. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HealthChecks")
  6279. rk := &RateLimitKey{
  6280. ProjectID: projectID,
  6281. Operation: "List",
  6282. Version: meta.Version("ga"),
  6283. Service: "HealthChecks",
  6284. }
  6285. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6286. return nil, err
  6287. }
  6288. klog.V(5).Infof("GCEHealthChecks.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  6289. call := g.s.GA.HealthChecks.List(projectID)
  6290. if fl != filter.None {
  6291. call.Filter(fl.String())
  6292. }
  6293. var all []*ga.HealthCheck
  6294. f := func(l *ga.HealthCheckList) error {
  6295. klog.V(5).Infof("GCEHealthChecks.List(%v, ..., %v): page %+v", ctx, fl, l)
  6296. all = append(all, l.Items...)
  6297. return nil
  6298. }
  6299. if err := call.Pages(ctx, f); err != nil {
  6300. klog.V(4).Infof("GCEHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  6301. return nil, err
  6302. }
  6303. if klog.V(4) {
  6304. klog.V(4).Infof("GCEHealthChecks.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  6305. } else if klog.V(5) {
  6306. var asStr []string
  6307. for _, o := range all {
  6308. asStr = append(asStr, fmt.Sprintf("%+v", o))
  6309. }
  6310. klog.V(5).Infof("GCEHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  6311. }
  6312. return all, nil
  6313. }
  6314. // Insert HealthCheck with key of value obj.
  6315. func (g *GCEHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *ga.HealthCheck) error {
  6316. klog.V(5).Infof("GCEHealthChecks.Insert(%v, %v, %+v): called", ctx, key, obj)
  6317. if !key.Valid() {
  6318. klog.V(2).Infof("GCEHealthChecks.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  6319. return fmt.Errorf("invalid GCE key (%+v)", key)
  6320. }
  6321. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HealthChecks")
  6322. rk := &RateLimitKey{
  6323. ProjectID: projectID,
  6324. Operation: "Insert",
  6325. Version: meta.Version("ga"),
  6326. Service: "HealthChecks",
  6327. }
  6328. klog.V(5).Infof("GCEHealthChecks.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6329. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6330. klog.V(4).Infof("GCEHealthChecks.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  6331. return err
  6332. }
  6333. obj.Name = key.Name
  6334. call := g.s.GA.HealthChecks.Insert(projectID, obj)
  6335. call.Context(ctx)
  6336. op, err := call.Do()
  6337. if err != nil {
  6338. klog.V(4).Infof("GCEHealthChecks.Insert(%v, %v, ...) = %+v", ctx, key, err)
  6339. return err
  6340. }
  6341. err = g.s.WaitForCompletion(ctx, op)
  6342. klog.V(4).Infof("GCEHealthChecks.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  6343. return err
  6344. }
  6345. // Delete the HealthCheck referenced by key.
  6346. func (g *GCEHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  6347. klog.V(5).Infof("GCEHealthChecks.Delete(%v, %v): called", ctx, key)
  6348. if !key.Valid() {
  6349. klog.V(2).Infof("GCEHealthChecks.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  6350. return fmt.Errorf("invalid GCE key (%+v)", key)
  6351. }
  6352. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HealthChecks")
  6353. rk := &RateLimitKey{
  6354. ProjectID: projectID,
  6355. Operation: "Delete",
  6356. Version: meta.Version("ga"),
  6357. Service: "HealthChecks",
  6358. }
  6359. klog.V(5).Infof("GCEHealthChecks.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6360. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6361. klog.V(4).Infof("GCEHealthChecks.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  6362. return err
  6363. }
  6364. call := g.s.GA.HealthChecks.Delete(projectID, key.Name)
  6365. call.Context(ctx)
  6366. op, err := call.Do()
  6367. if err != nil {
  6368. klog.V(4).Infof("GCEHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6369. return err
  6370. }
  6371. err = g.s.WaitForCompletion(ctx, op)
  6372. klog.V(4).Infof("GCEHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6373. return err
  6374. }
  6375. // Update is a method on GCEHealthChecks.
  6376. func (g *GCEHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *ga.HealthCheck) error {
  6377. klog.V(5).Infof("GCEHealthChecks.Update(%v, %v, ...): called", ctx, key)
  6378. if !key.Valid() {
  6379. klog.V(2).Infof("GCEHealthChecks.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  6380. return fmt.Errorf("invalid GCE key (%+v)", key)
  6381. }
  6382. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HealthChecks")
  6383. rk := &RateLimitKey{
  6384. ProjectID: projectID,
  6385. Operation: "Update",
  6386. Version: meta.Version("ga"),
  6387. Service: "HealthChecks",
  6388. }
  6389. klog.V(5).Infof("GCEHealthChecks.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6390. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6391. klog.V(4).Infof("GCEHealthChecks.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  6392. return err
  6393. }
  6394. call := g.s.GA.HealthChecks.Update(projectID, key.Name, arg0)
  6395. call.Context(ctx)
  6396. op, err := call.Do()
  6397. if err != nil {
  6398. klog.V(4).Infof("GCEHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  6399. return err
  6400. }
  6401. err = g.s.WaitForCompletion(ctx, op)
  6402. klog.V(4).Infof("GCEHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  6403. return err
  6404. }
  6405. // AlphaHealthChecks is an interface that allows for mocking of HealthChecks.
  6406. type AlphaHealthChecks interface {
  6407. Get(ctx context.Context, key *meta.Key) (*alpha.HealthCheck, error)
  6408. List(ctx context.Context, fl *filter.F) ([]*alpha.HealthCheck, error)
  6409. Insert(ctx context.Context, key *meta.Key, obj *alpha.HealthCheck) error
  6410. Delete(ctx context.Context, key *meta.Key) error
  6411. Update(context.Context, *meta.Key, *alpha.HealthCheck) error
  6412. }
  6413. // NewMockAlphaHealthChecks returns a new mock for HealthChecks.
  6414. func NewMockAlphaHealthChecks(pr ProjectRouter, objs map[meta.Key]*MockHealthChecksObj) *MockAlphaHealthChecks {
  6415. mock := &MockAlphaHealthChecks{
  6416. ProjectRouter: pr,
  6417. Objects: objs,
  6418. GetError: map[meta.Key]error{},
  6419. InsertError: map[meta.Key]error{},
  6420. DeleteError: map[meta.Key]error{},
  6421. }
  6422. return mock
  6423. }
  6424. // MockAlphaHealthChecks is the mock for HealthChecks.
  6425. type MockAlphaHealthChecks struct {
  6426. Lock sync.Mutex
  6427. ProjectRouter ProjectRouter
  6428. // Objects maintained by the mock.
  6429. Objects map[meta.Key]*MockHealthChecksObj
  6430. // If an entry exists for the given key and operation, then the error
  6431. // will be returned instead of the operation.
  6432. GetError map[meta.Key]error
  6433. ListError *error
  6434. InsertError map[meta.Key]error
  6435. DeleteError map[meta.Key]error
  6436. // xxxHook allow you to intercept the standard processing of the mock in
  6437. // order to add your own logic. Return (true, _, _) to prevent the normal
  6438. // execution flow of the mock. Return (false, nil, nil) to continue with
  6439. // normal mock behavior/ after the hook function executes.
  6440. GetHook func(ctx context.Context, key *meta.Key, m *MockAlphaHealthChecks) (bool, *alpha.HealthCheck, error)
  6441. ListHook func(ctx context.Context, fl *filter.F, m *MockAlphaHealthChecks) (bool, []*alpha.HealthCheck, error)
  6442. InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.HealthCheck, m *MockAlphaHealthChecks) (bool, error)
  6443. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaHealthChecks) (bool, error)
  6444. UpdateHook func(context.Context, *meta.Key, *alpha.HealthCheck, *MockAlphaHealthChecks) error
  6445. // X is extra state that can be used as part of the mock. Generated code
  6446. // will not use this field.
  6447. X interface{}
  6448. }
  6449. // Get returns the object from the mock.
  6450. func (m *MockAlphaHealthChecks) Get(ctx context.Context, key *meta.Key) (*alpha.HealthCheck, error) {
  6451. if m.GetHook != nil {
  6452. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  6453. klog.V(5).Infof("MockAlphaHealthChecks.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  6454. return obj, err
  6455. }
  6456. }
  6457. if !key.Valid() {
  6458. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  6459. }
  6460. m.Lock.Lock()
  6461. defer m.Lock.Unlock()
  6462. if err, ok := m.GetError[*key]; ok {
  6463. klog.V(5).Infof("MockAlphaHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  6464. return nil, err
  6465. }
  6466. if obj, ok := m.Objects[*key]; ok {
  6467. typedObj := obj.ToAlpha()
  6468. klog.V(5).Infof("MockAlphaHealthChecks.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  6469. return typedObj, nil
  6470. }
  6471. err := &googleapi.Error{
  6472. Code: http.StatusNotFound,
  6473. Message: fmt.Sprintf("MockAlphaHealthChecks %v not found", key),
  6474. }
  6475. klog.V(5).Infof("MockAlphaHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  6476. return nil, err
  6477. }
  6478. // List all of the objects in the mock.
  6479. func (m *MockAlphaHealthChecks) List(ctx context.Context, fl *filter.F) ([]*alpha.HealthCheck, error) {
  6480. if m.ListHook != nil {
  6481. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  6482. klog.V(5).Infof("MockAlphaHealthChecks.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  6483. return objs, err
  6484. }
  6485. }
  6486. m.Lock.Lock()
  6487. defer m.Lock.Unlock()
  6488. if m.ListError != nil {
  6489. err := *m.ListError
  6490. klog.V(5).Infof("MockAlphaHealthChecks.List(%v, %v) = nil, %v", ctx, fl, err)
  6491. return nil, *m.ListError
  6492. }
  6493. var objs []*alpha.HealthCheck
  6494. for _, obj := range m.Objects {
  6495. if !fl.Match(obj.ToAlpha()) {
  6496. continue
  6497. }
  6498. objs = append(objs, obj.ToAlpha())
  6499. }
  6500. klog.V(5).Infof("MockAlphaHealthChecks.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  6501. return objs, nil
  6502. }
  6503. // Insert is a mock for inserting/creating a new object.
  6504. func (m *MockAlphaHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *alpha.HealthCheck) error {
  6505. if m.InsertHook != nil {
  6506. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  6507. klog.V(5).Infof("MockAlphaHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6508. return err
  6509. }
  6510. }
  6511. if !key.Valid() {
  6512. return fmt.Errorf("invalid GCE key (%+v)", key)
  6513. }
  6514. m.Lock.Lock()
  6515. defer m.Lock.Unlock()
  6516. if err, ok := m.InsertError[*key]; ok {
  6517. klog.V(5).Infof("MockAlphaHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6518. return err
  6519. }
  6520. if _, ok := m.Objects[*key]; ok {
  6521. err := &googleapi.Error{
  6522. Code: http.StatusConflict,
  6523. Message: fmt.Sprintf("MockAlphaHealthChecks %v exists", key),
  6524. }
  6525. klog.V(5).Infof("MockAlphaHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6526. return err
  6527. }
  6528. obj.Name = key.Name
  6529. projectID := m.ProjectRouter.ProjectID(ctx, "alpha", "healthChecks")
  6530. obj.SelfLink = SelfLink(meta.VersionAlpha, projectID, "healthChecks", key)
  6531. m.Objects[*key] = &MockHealthChecksObj{obj}
  6532. klog.V(5).Infof("MockAlphaHealthChecks.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  6533. return nil
  6534. }
  6535. // Delete is a mock for deleting the object.
  6536. func (m *MockAlphaHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  6537. if m.DeleteHook != nil {
  6538. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  6539. klog.V(5).Infof("MockAlphaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6540. return err
  6541. }
  6542. }
  6543. if !key.Valid() {
  6544. return fmt.Errorf("invalid GCE key (%+v)", key)
  6545. }
  6546. m.Lock.Lock()
  6547. defer m.Lock.Unlock()
  6548. if err, ok := m.DeleteError[*key]; ok {
  6549. klog.V(5).Infof("MockAlphaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6550. return err
  6551. }
  6552. if _, ok := m.Objects[*key]; !ok {
  6553. err := &googleapi.Error{
  6554. Code: http.StatusNotFound,
  6555. Message: fmt.Sprintf("MockAlphaHealthChecks %v not found", key),
  6556. }
  6557. klog.V(5).Infof("MockAlphaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6558. return err
  6559. }
  6560. delete(m.Objects, *key)
  6561. klog.V(5).Infof("MockAlphaHealthChecks.Delete(%v, %v) = nil", ctx, key)
  6562. return nil
  6563. }
  6564. // Obj wraps the object for use in the mock.
  6565. func (m *MockAlphaHealthChecks) Obj(o *alpha.HealthCheck) *MockHealthChecksObj {
  6566. return &MockHealthChecksObj{o}
  6567. }
  6568. // Update is a mock for the corresponding method.
  6569. func (m *MockAlphaHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *alpha.HealthCheck) error {
  6570. if m.UpdateHook != nil {
  6571. return m.UpdateHook(ctx, key, arg0, m)
  6572. }
  6573. return nil
  6574. }
  6575. // GCEAlphaHealthChecks is a simplifying adapter for the GCE HealthChecks.
  6576. type GCEAlphaHealthChecks struct {
  6577. s *Service
  6578. }
  6579. // Get the HealthCheck named by key.
  6580. func (g *GCEAlphaHealthChecks) Get(ctx context.Context, key *meta.Key) (*alpha.HealthCheck, error) {
  6581. klog.V(5).Infof("GCEAlphaHealthChecks.Get(%v, %v): called", ctx, key)
  6582. if !key.Valid() {
  6583. klog.V(2).Infof("GCEAlphaHealthChecks.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  6584. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  6585. }
  6586. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "HealthChecks")
  6587. rk := &RateLimitKey{
  6588. ProjectID: projectID,
  6589. Operation: "Get",
  6590. Version: meta.Version("alpha"),
  6591. Service: "HealthChecks",
  6592. }
  6593. klog.V(5).Infof("GCEAlphaHealthChecks.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6594. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6595. klog.V(4).Infof("GCEAlphaHealthChecks.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  6596. return nil, err
  6597. }
  6598. call := g.s.Alpha.HealthChecks.Get(projectID, key.Name)
  6599. call.Context(ctx)
  6600. v, err := call.Do()
  6601. klog.V(4).Infof("GCEAlphaHealthChecks.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  6602. return v, err
  6603. }
  6604. // List all HealthCheck objects.
  6605. func (g *GCEAlphaHealthChecks) List(ctx context.Context, fl *filter.F) ([]*alpha.HealthCheck, error) {
  6606. klog.V(5).Infof("GCEAlphaHealthChecks.List(%v, %v) called", ctx, fl)
  6607. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "HealthChecks")
  6608. rk := &RateLimitKey{
  6609. ProjectID: projectID,
  6610. Operation: "List",
  6611. Version: meta.Version("alpha"),
  6612. Service: "HealthChecks",
  6613. }
  6614. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6615. return nil, err
  6616. }
  6617. klog.V(5).Infof("GCEAlphaHealthChecks.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  6618. call := g.s.Alpha.HealthChecks.List(projectID)
  6619. if fl != filter.None {
  6620. call.Filter(fl.String())
  6621. }
  6622. var all []*alpha.HealthCheck
  6623. f := func(l *alpha.HealthCheckList) error {
  6624. klog.V(5).Infof("GCEAlphaHealthChecks.List(%v, ..., %v): page %+v", ctx, fl, l)
  6625. all = append(all, l.Items...)
  6626. return nil
  6627. }
  6628. if err := call.Pages(ctx, f); err != nil {
  6629. klog.V(4).Infof("GCEAlphaHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  6630. return nil, err
  6631. }
  6632. if klog.V(4) {
  6633. klog.V(4).Infof("GCEAlphaHealthChecks.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  6634. } else if klog.V(5) {
  6635. var asStr []string
  6636. for _, o := range all {
  6637. asStr = append(asStr, fmt.Sprintf("%+v", o))
  6638. }
  6639. klog.V(5).Infof("GCEAlphaHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  6640. }
  6641. return all, nil
  6642. }
  6643. // Insert HealthCheck with key of value obj.
  6644. func (g *GCEAlphaHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *alpha.HealthCheck) error {
  6645. klog.V(5).Infof("GCEAlphaHealthChecks.Insert(%v, %v, %+v): called", ctx, key, obj)
  6646. if !key.Valid() {
  6647. klog.V(2).Infof("GCEAlphaHealthChecks.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  6648. return fmt.Errorf("invalid GCE key (%+v)", key)
  6649. }
  6650. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "HealthChecks")
  6651. rk := &RateLimitKey{
  6652. ProjectID: projectID,
  6653. Operation: "Insert",
  6654. Version: meta.Version("alpha"),
  6655. Service: "HealthChecks",
  6656. }
  6657. klog.V(5).Infof("GCEAlphaHealthChecks.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6658. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6659. klog.V(4).Infof("GCEAlphaHealthChecks.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  6660. return err
  6661. }
  6662. obj.Name = key.Name
  6663. call := g.s.Alpha.HealthChecks.Insert(projectID, obj)
  6664. call.Context(ctx)
  6665. op, err := call.Do()
  6666. if err != nil {
  6667. klog.V(4).Infof("GCEAlphaHealthChecks.Insert(%v, %v, ...) = %+v", ctx, key, err)
  6668. return err
  6669. }
  6670. err = g.s.WaitForCompletion(ctx, op)
  6671. klog.V(4).Infof("GCEAlphaHealthChecks.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  6672. return err
  6673. }
  6674. // Delete the HealthCheck referenced by key.
  6675. func (g *GCEAlphaHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  6676. klog.V(5).Infof("GCEAlphaHealthChecks.Delete(%v, %v): called", ctx, key)
  6677. if !key.Valid() {
  6678. klog.V(2).Infof("GCEAlphaHealthChecks.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  6679. return fmt.Errorf("invalid GCE key (%+v)", key)
  6680. }
  6681. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "HealthChecks")
  6682. rk := &RateLimitKey{
  6683. ProjectID: projectID,
  6684. Operation: "Delete",
  6685. Version: meta.Version("alpha"),
  6686. Service: "HealthChecks",
  6687. }
  6688. klog.V(5).Infof("GCEAlphaHealthChecks.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6689. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6690. klog.V(4).Infof("GCEAlphaHealthChecks.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  6691. return err
  6692. }
  6693. call := g.s.Alpha.HealthChecks.Delete(projectID, key.Name)
  6694. call.Context(ctx)
  6695. op, err := call.Do()
  6696. if err != nil {
  6697. klog.V(4).Infof("GCEAlphaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6698. return err
  6699. }
  6700. err = g.s.WaitForCompletion(ctx, op)
  6701. klog.V(4).Infof("GCEAlphaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6702. return err
  6703. }
  6704. // Update is a method on GCEAlphaHealthChecks.
  6705. func (g *GCEAlphaHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *alpha.HealthCheck) error {
  6706. klog.V(5).Infof("GCEAlphaHealthChecks.Update(%v, %v, ...): called", ctx, key)
  6707. if !key.Valid() {
  6708. klog.V(2).Infof("GCEAlphaHealthChecks.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  6709. return fmt.Errorf("invalid GCE key (%+v)", key)
  6710. }
  6711. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "HealthChecks")
  6712. rk := &RateLimitKey{
  6713. ProjectID: projectID,
  6714. Operation: "Update",
  6715. Version: meta.Version("alpha"),
  6716. Service: "HealthChecks",
  6717. }
  6718. klog.V(5).Infof("GCEAlphaHealthChecks.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6719. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6720. klog.V(4).Infof("GCEAlphaHealthChecks.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  6721. return err
  6722. }
  6723. call := g.s.Alpha.HealthChecks.Update(projectID, key.Name, arg0)
  6724. call.Context(ctx)
  6725. op, err := call.Do()
  6726. if err != nil {
  6727. klog.V(4).Infof("GCEAlphaHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  6728. return err
  6729. }
  6730. err = g.s.WaitForCompletion(ctx, op)
  6731. klog.V(4).Infof("GCEAlphaHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  6732. return err
  6733. }
  6734. // BetaHealthChecks is an interface that allows for mocking of HealthChecks.
  6735. type BetaHealthChecks interface {
  6736. Get(ctx context.Context, key *meta.Key) (*beta.HealthCheck, error)
  6737. List(ctx context.Context, fl *filter.F) ([]*beta.HealthCheck, error)
  6738. Insert(ctx context.Context, key *meta.Key, obj *beta.HealthCheck) error
  6739. Delete(ctx context.Context, key *meta.Key) error
  6740. Update(context.Context, *meta.Key, *beta.HealthCheck) error
  6741. }
  6742. // NewMockBetaHealthChecks returns a new mock for HealthChecks.
  6743. func NewMockBetaHealthChecks(pr ProjectRouter, objs map[meta.Key]*MockHealthChecksObj) *MockBetaHealthChecks {
  6744. mock := &MockBetaHealthChecks{
  6745. ProjectRouter: pr,
  6746. Objects: objs,
  6747. GetError: map[meta.Key]error{},
  6748. InsertError: map[meta.Key]error{},
  6749. DeleteError: map[meta.Key]error{},
  6750. }
  6751. return mock
  6752. }
  6753. // MockBetaHealthChecks is the mock for HealthChecks.
  6754. type MockBetaHealthChecks struct {
  6755. Lock sync.Mutex
  6756. ProjectRouter ProjectRouter
  6757. // Objects maintained by the mock.
  6758. Objects map[meta.Key]*MockHealthChecksObj
  6759. // If an entry exists for the given key and operation, then the error
  6760. // will be returned instead of the operation.
  6761. GetError map[meta.Key]error
  6762. ListError *error
  6763. InsertError map[meta.Key]error
  6764. DeleteError map[meta.Key]error
  6765. // xxxHook allow you to intercept the standard processing of the mock in
  6766. // order to add your own logic. Return (true, _, _) to prevent the normal
  6767. // execution flow of the mock. Return (false, nil, nil) to continue with
  6768. // normal mock behavior/ after the hook function executes.
  6769. GetHook func(ctx context.Context, key *meta.Key, m *MockBetaHealthChecks) (bool, *beta.HealthCheck, error)
  6770. ListHook func(ctx context.Context, fl *filter.F, m *MockBetaHealthChecks) (bool, []*beta.HealthCheck, error)
  6771. InsertHook func(ctx context.Context, key *meta.Key, obj *beta.HealthCheck, m *MockBetaHealthChecks) (bool, error)
  6772. DeleteHook func(ctx context.Context, key *meta.Key, m *MockBetaHealthChecks) (bool, error)
  6773. UpdateHook func(context.Context, *meta.Key, *beta.HealthCheck, *MockBetaHealthChecks) error
  6774. // X is extra state that can be used as part of the mock. Generated code
  6775. // will not use this field.
  6776. X interface{}
  6777. }
  6778. // Get returns the object from the mock.
  6779. func (m *MockBetaHealthChecks) Get(ctx context.Context, key *meta.Key) (*beta.HealthCheck, error) {
  6780. if m.GetHook != nil {
  6781. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  6782. klog.V(5).Infof("MockBetaHealthChecks.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  6783. return obj, err
  6784. }
  6785. }
  6786. if !key.Valid() {
  6787. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  6788. }
  6789. m.Lock.Lock()
  6790. defer m.Lock.Unlock()
  6791. if err, ok := m.GetError[*key]; ok {
  6792. klog.V(5).Infof("MockBetaHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  6793. return nil, err
  6794. }
  6795. if obj, ok := m.Objects[*key]; ok {
  6796. typedObj := obj.ToBeta()
  6797. klog.V(5).Infof("MockBetaHealthChecks.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  6798. return typedObj, nil
  6799. }
  6800. err := &googleapi.Error{
  6801. Code: http.StatusNotFound,
  6802. Message: fmt.Sprintf("MockBetaHealthChecks %v not found", key),
  6803. }
  6804. klog.V(5).Infof("MockBetaHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  6805. return nil, err
  6806. }
  6807. // List all of the objects in the mock.
  6808. func (m *MockBetaHealthChecks) List(ctx context.Context, fl *filter.F) ([]*beta.HealthCheck, error) {
  6809. if m.ListHook != nil {
  6810. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  6811. klog.V(5).Infof("MockBetaHealthChecks.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  6812. return objs, err
  6813. }
  6814. }
  6815. m.Lock.Lock()
  6816. defer m.Lock.Unlock()
  6817. if m.ListError != nil {
  6818. err := *m.ListError
  6819. klog.V(5).Infof("MockBetaHealthChecks.List(%v, %v) = nil, %v", ctx, fl, err)
  6820. return nil, *m.ListError
  6821. }
  6822. var objs []*beta.HealthCheck
  6823. for _, obj := range m.Objects {
  6824. if !fl.Match(obj.ToBeta()) {
  6825. continue
  6826. }
  6827. objs = append(objs, obj.ToBeta())
  6828. }
  6829. klog.V(5).Infof("MockBetaHealthChecks.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  6830. return objs, nil
  6831. }
  6832. // Insert is a mock for inserting/creating a new object.
  6833. func (m *MockBetaHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *beta.HealthCheck) error {
  6834. if m.InsertHook != nil {
  6835. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  6836. klog.V(5).Infof("MockBetaHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6837. return err
  6838. }
  6839. }
  6840. if !key.Valid() {
  6841. return fmt.Errorf("invalid GCE key (%+v)", key)
  6842. }
  6843. m.Lock.Lock()
  6844. defer m.Lock.Unlock()
  6845. if err, ok := m.InsertError[*key]; ok {
  6846. klog.V(5).Infof("MockBetaHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6847. return err
  6848. }
  6849. if _, ok := m.Objects[*key]; ok {
  6850. err := &googleapi.Error{
  6851. Code: http.StatusConflict,
  6852. Message: fmt.Sprintf("MockBetaHealthChecks %v exists", key),
  6853. }
  6854. klog.V(5).Infof("MockBetaHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  6855. return err
  6856. }
  6857. obj.Name = key.Name
  6858. projectID := m.ProjectRouter.ProjectID(ctx, "beta", "healthChecks")
  6859. obj.SelfLink = SelfLink(meta.VersionBeta, projectID, "healthChecks", key)
  6860. m.Objects[*key] = &MockHealthChecksObj{obj}
  6861. klog.V(5).Infof("MockBetaHealthChecks.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  6862. return nil
  6863. }
  6864. // Delete is a mock for deleting the object.
  6865. func (m *MockBetaHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  6866. if m.DeleteHook != nil {
  6867. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  6868. klog.V(5).Infof("MockBetaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6869. return err
  6870. }
  6871. }
  6872. if !key.Valid() {
  6873. return fmt.Errorf("invalid GCE key (%+v)", key)
  6874. }
  6875. m.Lock.Lock()
  6876. defer m.Lock.Unlock()
  6877. if err, ok := m.DeleteError[*key]; ok {
  6878. klog.V(5).Infof("MockBetaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6879. return err
  6880. }
  6881. if _, ok := m.Objects[*key]; !ok {
  6882. err := &googleapi.Error{
  6883. Code: http.StatusNotFound,
  6884. Message: fmt.Sprintf("MockBetaHealthChecks %v not found", key),
  6885. }
  6886. klog.V(5).Infof("MockBetaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  6887. return err
  6888. }
  6889. delete(m.Objects, *key)
  6890. klog.V(5).Infof("MockBetaHealthChecks.Delete(%v, %v) = nil", ctx, key)
  6891. return nil
  6892. }
  6893. // Obj wraps the object for use in the mock.
  6894. func (m *MockBetaHealthChecks) Obj(o *beta.HealthCheck) *MockHealthChecksObj {
  6895. return &MockHealthChecksObj{o}
  6896. }
  6897. // Update is a mock for the corresponding method.
  6898. func (m *MockBetaHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *beta.HealthCheck) error {
  6899. if m.UpdateHook != nil {
  6900. return m.UpdateHook(ctx, key, arg0, m)
  6901. }
  6902. return nil
  6903. }
  6904. // GCEBetaHealthChecks is a simplifying adapter for the GCE HealthChecks.
  6905. type GCEBetaHealthChecks struct {
  6906. s *Service
  6907. }
  6908. // Get the HealthCheck named by key.
  6909. func (g *GCEBetaHealthChecks) Get(ctx context.Context, key *meta.Key) (*beta.HealthCheck, error) {
  6910. klog.V(5).Infof("GCEBetaHealthChecks.Get(%v, %v): called", ctx, key)
  6911. if !key.Valid() {
  6912. klog.V(2).Infof("GCEBetaHealthChecks.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  6913. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  6914. }
  6915. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "HealthChecks")
  6916. rk := &RateLimitKey{
  6917. ProjectID: projectID,
  6918. Operation: "Get",
  6919. Version: meta.Version("beta"),
  6920. Service: "HealthChecks",
  6921. }
  6922. klog.V(5).Infof("GCEBetaHealthChecks.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6923. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6924. klog.V(4).Infof("GCEBetaHealthChecks.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  6925. return nil, err
  6926. }
  6927. call := g.s.Beta.HealthChecks.Get(projectID, key.Name)
  6928. call.Context(ctx)
  6929. v, err := call.Do()
  6930. klog.V(4).Infof("GCEBetaHealthChecks.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  6931. return v, err
  6932. }
  6933. // List all HealthCheck objects.
  6934. func (g *GCEBetaHealthChecks) List(ctx context.Context, fl *filter.F) ([]*beta.HealthCheck, error) {
  6935. klog.V(5).Infof("GCEBetaHealthChecks.List(%v, %v) called", ctx, fl)
  6936. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "HealthChecks")
  6937. rk := &RateLimitKey{
  6938. ProjectID: projectID,
  6939. Operation: "List",
  6940. Version: meta.Version("beta"),
  6941. Service: "HealthChecks",
  6942. }
  6943. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6944. return nil, err
  6945. }
  6946. klog.V(5).Infof("GCEBetaHealthChecks.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  6947. call := g.s.Beta.HealthChecks.List(projectID)
  6948. if fl != filter.None {
  6949. call.Filter(fl.String())
  6950. }
  6951. var all []*beta.HealthCheck
  6952. f := func(l *beta.HealthCheckList) error {
  6953. klog.V(5).Infof("GCEBetaHealthChecks.List(%v, ..., %v): page %+v", ctx, fl, l)
  6954. all = append(all, l.Items...)
  6955. return nil
  6956. }
  6957. if err := call.Pages(ctx, f); err != nil {
  6958. klog.V(4).Infof("GCEBetaHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  6959. return nil, err
  6960. }
  6961. if klog.V(4) {
  6962. klog.V(4).Infof("GCEBetaHealthChecks.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  6963. } else if klog.V(5) {
  6964. var asStr []string
  6965. for _, o := range all {
  6966. asStr = append(asStr, fmt.Sprintf("%+v", o))
  6967. }
  6968. klog.V(5).Infof("GCEBetaHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  6969. }
  6970. return all, nil
  6971. }
  6972. // Insert HealthCheck with key of value obj.
  6973. func (g *GCEBetaHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *beta.HealthCheck) error {
  6974. klog.V(5).Infof("GCEBetaHealthChecks.Insert(%v, %v, %+v): called", ctx, key, obj)
  6975. if !key.Valid() {
  6976. klog.V(2).Infof("GCEBetaHealthChecks.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  6977. return fmt.Errorf("invalid GCE key (%+v)", key)
  6978. }
  6979. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "HealthChecks")
  6980. rk := &RateLimitKey{
  6981. ProjectID: projectID,
  6982. Operation: "Insert",
  6983. Version: meta.Version("beta"),
  6984. Service: "HealthChecks",
  6985. }
  6986. klog.V(5).Infof("GCEBetaHealthChecks.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  6987. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  6988. klog.V(4).Infof("GCEBetaHealthChecks.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  6989. return err
  6990. }
  6991. obj.Name = key.Name
  6992. call := g.s.Beta.HealthChecks.Insert(projectID, obj)
  6993. call.Context(ctx)
  6994. op, err := call.Do()
  6995. if err != nil {
  6996. klog.V(4).Infof("GCEBetaHealthChecks.Insert(%v, %v, ...) = %+v", ctx, key, err)
  6997. return err
  6998. }
  6999. err = g.s.WaitForCompletion(ctx, op)
  7000. klog.V(4).Infof("GCEBetaHealthChecks.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  7001. return err
  7002. }
  7003. // Delete the HealthCheck referenced by key.
  7004. func (g *GCEBetaHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  7005. klog.V(5).Infof("GCEBetaHealthChecks.Delete(%v, %v): called", ctx, key)
  7006. if !key.Valid() {
  7007. klog.V(2).Infof("GCEBetaHealthChecks.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  7008. return fmt.Errorf("invalid GCE key (%+v)", key)
  7009. }
  7010. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "HealthChecks")
  7011. rk := &RateLimitKey{
  7012. ProjectID: projectID,
  7013. Operation: "Delete",
  7014. Version: meta.Version("beta"),
  7015. Service: "HealthChecks",
  7016. }
  7017. klog.V(5).Infof("GCEBetaHealthChecks.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7018. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7019. klog.V(4).Infof("GCEBetaHealthChecks.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  7020. return err
  7021. }
  7022. call := g.s.Beta.HealthChecks.Delete(projectID, key.Name)
  7023. call.Context(ctx)
  7024. op, err := call.Do()
  7025. if err != nil {
  7026. klog.V(4).Infof("GCEBetaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7027. return err
  7028. }
  7029. err = g.s.WaitForCompletion(ctx, op)
  7030. klog.V(4).Infof("GCEBetaHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7031. return err
  7032. }
  7033. // Update is a method on GCEBetaHealthChecks.
  7034. func (g *GCEBetaHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *beta.HealthCheck) error {
  7035. klog.V(5).Infof("GCEBetaHealthChecks.Update(%v, %v, ...): called", ctx, key)
  7036. if !key.Valid() {
  7037. klog.V(2).Infof("GCEBetaHealthChecks.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  7038. return fmt.Errorf("invalid GCE key (%+v)", key)
  7039. }
  7040. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "HealthChecks")
  7041. rk := &RateLimitKey{
  7042. ProjectID: projectID,
  7043. Operation: "Update",
  7044. Version: meta.Version("beta"),
  7045. Service: "HealthChecks",
  7046. }
  7047. klog.V(5).Infof("GCEBetaHealthChecks.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7048. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7049. klog.V(4).Infof("GCEBetaHealthChecks.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  7050. return err
  7051. }
  7052. call := g.s.Beta.HealthChecks.Update(projectID, key.Name, arg0)
  7053. call.Context(ctx)
  7054. op, err := call.Do()
  7055. if err != nil {
  7056. klog.V(4).Infof("GCEBetaHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  7057. return err
  7058. }
  7059. err = g.s.WaitForCompletion(ctx, op)
  7060. klog.V(4).Infof("GCEBetaHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  7061. return err
  7062. }
  7063. // HttpHealthChecks is an interface that allows for mocking of HttpHealthChecks.
  7064. type HttpHealthChecks interface {
  7065. Get(ctx context.Context, key *meta.Key) (*ga.HttpHealthCheck, error)
  7066. List(ctx context.Context, fl *filter.F) ([]*ga.HttpHealthCheck, error)
  7067. Insert(ctx context.Context, key *meta.Key, obj *ga.HttpHealthCheck) error
  7068. Delete(ctx context.Context, key *meta.Key) error
  7069. Update(context.Context, *meta.Key, *ga.HttpHealthCheck) error
  7070. }
  7071. // NewMockHttpHealthChecks returns a new mock for HttpHealthChecks.
  7072. func NewMockHttpHealthChecks(pr ProjectRouter, objs map[meta.Key]*MockHttpHealthChecksObj) *MockHttpHealthChecks {
  7073. mock := &MockHttpHealthChecks{
  7074. ProjectRouter: pr,
  7075. Objects: objs,
  7076. GetError: map[meta.Key]error{},
  7077. InsertError: map[meta.Key]error{},
  7078. DeleteError: map[meta.Key]error{},
  7079. }
  7080. return mock
  7081. }
  7082. // MockHttpHealthChecks is the mock for HttpHealthChecks.
  7083. type MockHttpHealthChecks struct {
  7084. Lock sync.Mutex
  7085. ProjectRouter ProjectRouter
  7086. // Objects maintained by the mock.
  7087. Objects map[meta.Key]*MockHttpHealthChecksObj
  7088. // If an entry exists for the given key and operation, then the error
  7089. // will be returned instead of the operation.
  7090. GetError map[meta.Key]error
  7091. ListError *error
  7092. InsertError map[meta.Key]error
  7093. DeleteError map[meta.Key]error
  7094. // xxxHook allow you to intercept the standard processing of the mock in
  7095. // order to add your own logic. Return (true, _, _) to prevent the normal
  7096. // execution flow of the mock. Return (false, nil, nil) to continue with
  7097. // normal mock behavior/ after the hook function executes.
  7098. GetHook func(ctx context.Context, key *meta.Key, m *MockHttpHealthChecks) (bool, *ga.HttpHealthCheck, error)
  7099. ListHook func(ctx context.Context, fl *filter.F, m *MockHttpHealthChecks) (bool, []*ga.HttpHealthCheck, error)
  7100. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.HttpHealthCheck, m *MockHttpHealthChecks) (bool, error)
  7101. DeleteHook func(ctx context.Context, key *meta.Key, m *MockHttpHealthChecks) (bool, error)
  7102. UpdateHook func(context.Context, *meta.Key, *ga.HttpHealthCheck, *MockHttpHealthChecks) error
  7103. // X is extra state that can be used as part of the mock. Generated code
  7104. // will not use this field.
  7105. X interface{}
  7106. }
  7107. // Get returns the object from the mock.
  7108. func (m *MockHttpHealthChecks) Get(ctx context.Context, key *meta.Key) (*ga.HttpHealthCheck, error) {
  7109. if m.GetHook != nil {
  7110. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  7111. klog.V(5).Infof("MockHttpHealthChecks.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  7112. return obj, err
  7113. }
  7114. }
  7115. if !key.Valid() {
  7116. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  7117. }
  7118. m.Lock.Lock()
  7119. defer m.Lock.Unlock()
  7120. if err, ok := m.GetError[*key]; ok {
  7121. klog.V(5).Infof("MockHttpHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  7122. return nil, err
  7123. }
  7124. if obj, ok := m.Objects[*key]; ok {
  7125. typedObj := obj.ToGA()
  7126. klog.V(5).Infof("MockHttpHealthChecks.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  7127. return typedObj, nil
  7128. }
  7129. err := &googleapi.Error{
  7130. Code: http.StatusNotFound,
  7131. Message: fmt.Sprintf("MockHttpHealthChecks %v not found", key),
  7132. }
  7133. klog.V(5).Infof("MockHttpHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  7134. return nil, err
  7135. }
  7136. // List all of the objects in the mock.
  7137. func (m *MockHttpHealthChecks) List(ctx context.Context, fl *filter.F) ([]*ga.HttpHealthCheck, error) {
  7138. if m.ListHook != nil {
  7139. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  7140. klog.V(5).Infof("MockHttpHealthChecks.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  7141. return objs, err
  7142. }
  7143. }
  7144. m.Lock.Lock()
  7145. defer m.Lock.Unlock()
  7146. if m.ListError != nil {
  7147. err := *m.ListError
  7148. klog.V(5).Infof("MockHttpHealthChecks.List(%v, %v) = nil, %v", ctx, fl, err)
  7149. return nil, *m.ListError
  7150. }
  7151. var objs []*ga.HttpHealthCheck
  7152. for _, obj := range m.Objects {
  7153. if !fl.Match(obj.ToGA()) {
  7154. continue
  7155. }
  7156. objs = append(objs, obj.ToGA())
  7157. }
  7158. klog.V(5).Infof("MockHttpHealthChecks.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  7159. return objs, nil
  7160. }
  7161. // Insert is a mock for inserting/creating a new object.
  7162. func (m *MockHttpHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *ga.HttpHealthCheck) error {
  7163. if m.InsertHook != nil {
  7164. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  7165. klog.V(5).Infof("MockHttpHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7166. return err
  7167. }
  7168. }
  7169. if !key.Valid() {
  7170. return fmt.Errorf("invalid GCE key (%+v)", key)
  7171. }
  7172. m.Lock.Lock()
  7173. defer m.Lock.Unlock()
  7174. if err, ok := m.InsertError[*key]; ok {
  7175. klog.V(5).Infof("MockHttpHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7176. return err
  7177. }
  7178. if _, ok := m.Objects[*key]; ok {
  7179. err := &googleapi.Error{
  7180. Code: http.StatusConflict,
  7181. Message: fmt.Sprintf("MockHttpHealthChecks %v exists", key),
  7182. }
  7183. klog.V(5).Infof("MockHttpHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7184. return err
  7185. }
  7186. obj.Name = key.Name
  7187. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "httpHealthChecks")
  7188. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "httpHealthChecks", key)
  7189. m.Objects[*key] = &MockHttpHealthChecksObj{obj}
  7190. klog.V(5).Infof("MockHttpHealthChecks.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  7191. return nil
  7192. }
  7193. // Delete is a mock for deleting the object.
  7194. func (m *MockHttpHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  7195. if m.DeleteHook != nil {
  7196. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  7197. klog.V(5).Infof("MockHttpHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7198. return err
  7199. }
  7200. }
  7201. if !key.Valid() {
  7202. return fmt.Errorf("invalid GCE key (%+v)", key)
  7203. }
  7204. m.Lock.Lock()
  7205. defer m.Lock.Unlock()
  7206. if err, ok := m.DeleteError[*key]; ok {
  7207. klog.V(5).Infof("MockHttpHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7208. return err
  7209. }
  7210. if _, ok := m.Objects[*key]; !ok {
  7211. err := &googleapi.Error{
  7212. Code: http.StatusNotFound,
  7213. Message: fmt.Sprintf("MockHttpHealthChecks %v not found", key),
  7214. }
  7215. klog.V(5).Infof("MockHttpHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7216. return err
  7217. }
  7218. delete(m.Objects, *key)
  7219. klog.V(5).Infof("MockHttpHealthChecks.Delete(%v, %v) = nil", ctx, key)
  7220. return nil
  7221. }
  7222. // Obj wraps the object for use in the mock.
  7223. func (m *MockHttpHealthChecks) Obj(o *ga.HttpHealthCheck) *MockHttpHealthChecksObj {
  7224. return &MockHttpHealthChecksObj{o}
  7225. }
  7226. // Update is a mock for the corresponding method.
  7227. func (m *MockHttpHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *ga.HttpHealthCheck) error {
  7228. if m.UpdateHook != nil {
  7229. return m.UpdateHook(ctx, key, arg0, m)
  7230. }
  7231. return nil
  7232. }
  7233. // GCEHttpHealthChecks is a simplifying adapter for the GCE HttpHealthChecks.
  7234. type GCEHttpHealthChecks struct {
  7235. s *Service
  7236. }
  7237. // Get the HttpHealthCheck named by key.
  7238. func (g *GCEHttpHealthChecks) Get(ctx context.Context, key *meta.Key) (*ga.HttpHealthCheck, error) {
  7239. klog.V(5).Infof("GCEHttpHealthChecks.Get(%v, %v): called", ctx, key)
  7240. if !key.Valid() {
  7241. klog.V(2).Infof("GCEHttpHealthChecks.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  7242. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  7243. }
  7244. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpHealthChecks")
  7245. rk := &RateLimitKey{
  7246. ProjectID: projectID,
  7247. Operation: "Get",
  7248. Version: meta.Version("ga"),
  7249. Service: "HttpHealthChecks",
  7250. }
  7251. klog.V(5).Infof("GCEHttpHealthChecks.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7252. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7253. klog.V(4).Infof("GCEHttpHealthChecks.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  7254. return nil, err
  7255. }
  7256. call := g.s.GA.HttpHealthChecks.Get(projectID, key.Name)
  7257. call.Context(ctx)
  7258. v, err := call.Do()
  7259. klog.V(4).Infof("GCEHttpHealthChecks.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  7260. return v, err
  7261. }
  7262. // List all HttpHealthCheck objects.
  7263. func (g *GCEHttpHealthChecks) List(ctx context.Context, fl *filter.F) ([]*ga.HttpHealthCheck, error) {
  7264. klog.V(5).Infof("GCEHttpHealthChecks.List(%v, %v) called", ctx, fl)
  7265. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpHealthChecks")
  7266. rk := &RateLimitKey{
  7267. ProjectID: projectID,
  7268. Operation: "List",
  7269. Version: meta.Version("ga"),
  7270. Service: "HttpHealthChecks",
  7271. }
  7272. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7273. return nil, err
  7274. }
  7275. klog.V(5).Infof("GCEHttpHealthChecks.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  7276. call := g.s.GA.HttpHealthChecks.List(projectID)
  7277. if fl != filter.None {
  7278. call.Filter(fl.String())
  7279. }
  7280. var all []*ga.HttpHealthCheck
  7281. f := func(l *ga.HttpHealthCheckList) error {
  7282. klog.V(5).Infof("GCEHttpHealthChecks.List(%v, ..., %v): page %+v", ctx, fl, l)
  7283. all = append(all, l.Items...)
  7284. return nil
  7285. }
  7286. if err := call.Pages(ctx, f); err != nil {
  7287. klog.V(4).Infof("GCEHttpHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  7288. return nil, err
  7289. }
  7290. if klog.V(4) {
  7291. klog.V(4).Infof("GCEHttpHealthChecks.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  7292. } else if klog.V(5) {
  7293. var asStr []string
  7294. for _, o := range all {
  7295. asStr = append(asStr, fmt.Sprintf("%+v", o))
  7296. }
  7297. klog.V(5).Infof("GCEHttpHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  7298. }
  7299. return all, nil
  7300. }
  7301. // Insert HttpHealthCheck with key of value obj.
  7302. func (g *GCEHttpHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *ga.HttpHealthCheck) error {
  7303. klog.V(5).Infof("GCEHttpHealthChecks.Insert(%v, %v, %+v): called", ctx, key, obj)
  7304. if !key.Valid() {
  7305. klog.V(2).Infof("GCEHttpHealthChecks.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  7306. return fmt.Errorf("invalid GCE key (%+v)", key)
  7307. }
  7308. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpHealthChecks")
  7309. rk := &RateLimitKey{
  7310. ProjectID: projectID,
  7311. Operation: "Insert",
  7312. Version: meta.Version("ga"),
  7313. Service: "HttpHealthChecks",
  7314. }
  7315. klog.V(5).Infof("GCEHttpHealthChecks.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7316. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7317. klog.V(4).Infof("GCEHttpHealthChecks.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  7318. return err
  7319. }
  7320. obj.Name = key.Name
  7321. call := g.s.GA.HttpHealthChecks.Insert(projectID, obj)
  7322. call.Context(ctx)
  7323. op, err := call.Do()
  7324. if err != nil {
  7325. klog.V(4).Infof("GCEHttpHealthChecks.Insert(%v, %v, ...) = %+v", ctx, key, err)
  7326. return err
  7327. }
  7328. err = g.s.WaitForCompletion(ctx, op)
  7329. klog.V(4).Infof("GCEHttpHealthChecks.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  7330. return err
  7331. }
  7332. // Delete the HttpHealthCheck referenced by key.
  7333. func (g *GCEHttpHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  7334. klog.V(5).Infof("GCEHttpHealthChecks.Delete(%v, %v): called", ctx, key)
  7335. if !key.Valid() {
  7336. klog.V(2).Infof("GCEHttpHealthChecks.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  7337. return fmt.Errorf("invalid GCE key (%+v)", key)
  7338. }
  7339. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpHealthChecks")
  7340. rk := &RateLimitKey{
  7341. ProjectID: projectID,
  7342. Operation: "Delete",
  7343. Version: meta.Version("ga"),
  7344. Service: "HttpHealthChecks",
  7345. }
  7346. klog.V(5).Infof("GCEHttpHealthChecks.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7347. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7348. klog.V(4).Infof("GCEHttpHealthChecks.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  7349. return err
  7350. }
  7351. call := g.s.GA.HttpHealthChecks.Delete(projectID, key.Name)
  7352. call.Context(ctx)
  7353. op, err := call.Do()
  7354. if err != nil {
  7355. klog.V(4).Infof("GCEHttpHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7356. return err
  7357. }
  7358. err = g.s.WaitForCompletion(ctx, op)
  7359. klog.V(4).Infof("GCEHttpHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7360. return err
  7361. }
  7362. // Update is a method on GCEHttpHealthChecks.
  7363. func (g *GCEHttpHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *ga.HttpHealthCheck) error {
  7364. klog.V(5).Infof("GCEHttpHealthChecks.Update(%v, %v, ...): called", ctx, key)
  7365. if !key.Valid() {
  7366. klog.V(2).Infof("GCEHttpHealthChecks.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  7367. return fmt.Errorf("invalid GCE key (%+v)", key)
  7368. }
  7369. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpHealthChecks")
  7370. rk := &RateLimitKey{
  7371. ProjectID: projectID,
  7372. Operation: "Update",
  7373. Version: meta.Version("ga"),
  7374. Service: "HttpHealthChecks",
  7375. }
  7376. klog.V(5).Infof("GCEHttpHealthChecks.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7377. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7378. klog.V(4).Infof("GCEHttpHealthChecks.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  7379. return err
  7380. }
  7381. call := g.s.GA.HttpHealthChecks.Update(projectID, key.Name, arg0)
  7382. call.Context(ctx)
  7383. op, err := call.Do()
  7384. if err != nil {
  7385. klog.V(4).Infof("GCEHttpHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  7386. return err
  7387. }
  7388. err = g.s.WaitForCompletion(ctx, op)
  7389. klog.V(4).Infof("GCEHttpHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  7390. return err
  7391. }
  7392. // HttpsHealthChecks is an interface that allows for mocking of HttpsHealthChecks.
  7393. type HttpsHealthChecks interface {
  7394. Get(ctx context.Context, key *meta.Key) (*ga.HttpsHealthCheck, error)
  7395. List(ctx context.Context, fl *filter.F) ([]*ga.HttpsHealthCheck, error)
  7396. Insert(ctx context.Context, key *meta.Key, obj *ga.HttpsHealthCheck) error
  7397. Delete(ctx context.Context, key *meta.Key) error
  7398. Update(context.Context, *meta.Key, *ga.HttpsHealthCheck) error
  7399. }
  7400. // NewMockHttpsHealthChecks returns a new mock for HttpsHealthChecks.
  7401. func NewMockHttpsHealthChecks(pr ProjectRouter, objs map[meta.Key]*MockHttpsHealthChecksObj) *MockHttpsHealthChecks {
  7402. mock := &MockHttpsHealthChecks{
  7403. ProjectRouter: pr,
  7404. Objects: objs,
  7405. GetError: map[meta.Key]error{},
  7406. InsertError: map[meta.Key]error{},
  7407. DeleteError: map[meta.Key]error{},
  7408. }
  7409. return mock
  7410. }
  7411. // MockHttpsHealthChecks is the mock for HttpsHealthChecks.
  7412. type MockHttpsHealthChecks struct {
  7413. Lock sync.Mutex
  7414. ProjectRouter ProjectRouter
  7415. // Objects maintained by the mock.
  7416. Objects map[meta.Key]*MockHttpsHealthChecksObj
  7417. // If an entry exists for the given key and operation, then the error
  7418. // will be returned instead of the operation.
  7419. GetError map[meta.Key]error
  7420. ListError *error
  7421. InsertError map[meta.Key]error
  7422. DeleteError map[meta.Key]error
  7423. // xxxHook allow you to intercept the standard processing of the mock in
  7424. // order to add your own logic. Return (true, _, _) to prevent the normal
  7425. // execution flow of the mock. Return (false, nil, nil) to continue with
  7426. // normal mock behavior/ after the hook function executes.
  7427. GetHook func(ctx context.Context, key *meta.Key, m *MockHttpsHealthChecks) (bool, *ga.HttpsHealthCheck, error)
  7428. ListHook func(ctx context.Context, fl *filter.F, m *MockHttpsHealthChecks) (bool, []*ga.HttpsHealthCheck, error)
  7429. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.HttpsHealthCheck, m *MockHttpsHealthChecks) (bool, error)
  7430. DeleteHook func(ctx context.Context, key *meta.Key, m *MockHttpsHealthChecks) (bool, error)
  7431. UpdateHook func(context.Context, *meta.Key, *ga.HttpsHealthCheck, *MockHttpsHealthChecks) error
  7432. // X is extra state that can be used as part of the mock. Generated code
  7433. // will not use this field.
  7434. X interface{}
  7435. }
  7436. // Get returns the object from the mock.
  7437. func (m *MockHttpsHealthChecks) Get(ctx context.Context, key *meta.Key) (*ga.HttpsHealthCheck, error) {
  7438. if m.GetHook != nil {
  7439. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  7440. klog.V(5).Infof("MockHttpsHealthChecks.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  7441. return obj, err
  7442. }
  7443. }
  7444. if !key.Valid() {
  7445. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  7446. }
  7447. m.Lock.Lock()
  7448. defer m.Lock.Unlock()
  7449. if err, ok := m.GetError[*key]; ok {
  7450. klog.V(5).Infof("MockHttpsHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  7451. return nil, err
  7452. }
  7453. if obj, ok := m.Objects[*key]; ok {
  7454. typedObj := obj.ToGA()
  7455. klog.V(5).Infof("MockHttpsHealthChecks.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  7456. return typedObj, nil
  7457. }
  7458. err := &googleapi.Error{
  7459. Code: http.StatusNotFound,
  7460. Message: fmt.Sprintf("MockHttpsHealthChecks %v not found", key),
  7461. }
  7462. klog.V(5).Infof("MockHttpsHealthChecks.Get(%v, %s) = nil, %v", ctx, key, err)
  7463. return nil, err
  7464. }
  7465. // List all of the objects in the mock.
  7466. func (m *MockHttpsHealthChecks) List(ctx context.Context, fl *filter.F) ([]*ga.HttpsHealthCheck, error) {
  7467. if m.ListHook != nil {
  7468. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  7469. klog.V(5).Infof("MockHttpsHealthChecks.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  7470. return objs, err
  7471. }
  7472. }
  7473. m.Lock.Lock()
  7474. defer m.Lock.Unlock()
  7475. if m.ListError != nil {
  7476. err := *m.ListError
  7477. klog.V(5).Infof("MockHttpsHealthChecks.List(%v, %v) = nil, %v", ctx, fl, err)
  7478. return nil, *m.ListError
  7479. }
  7480. var objs []*ga.HttpsHealthCheck
  7481. for _, obj := range m.Objects {
  7482. if !fl.Match(obj.ToGA()) {
  7483. continue
  7484. }
  7485. objs = append(objs, obj.ToGA())
  7486. }
  7487. klog.V(5).Infof("MockHttpsHealthChecks.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  7488. return objs, nil
  7489. }
  7490. // Insert is a mock for inserting/creating a new object.
  7491. func (m *MockHttpsHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *ga.HttpsHealthCheck) error {
  7492. if m.InsertHook != nil {
  7493. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  7494. klog.V(5).Infof("MockHttpsHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7495. return err
  7496. }
  7497. }
  7498. if !key.Valid() {
  7499. return fmt.Errorf("invalid GCE key (%+v)", key)
  7500. }
  7501. m.Lock.Lock()
  7502. defer m.Lock.Unlock()
  7503. if err, ok := m.InsertError[*key]; ok {
  7504. klog.V(5).Infof("MockHttpsHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7505. return err
  7506. }
  7507. if _, ok := m.Objects[*key]; ok {
  7508. err := &googleapi.Error{
  7509. Code: http.StatusConflict,
  7510. Message: fmt.Sprintf("MockHttpsHealthChecks %v exists", key),
  7511. }
  7512. klog.V(5).Infof("MockHttpsHealthChecks.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7513. return err
  7514. }
  7515. obj.Name = key.Name
  7516. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "httpsHealthChecks")
  7517. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "httpsHealthChecks", key)
  7518. m.Objects[*key] = &MockHttpsHealthChecksObj{obj}
  7519. klog.V(5).Infof("MockHttpsHealthChecks.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  7520. return nil
  7521. }
  7522. // Delete is a mock for deleting the object.
  7523. func (m *MockHttpsHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  7524. if m.DeleteHook != nil {
  7525. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  7526. klog.V(5).Infof("MockHttpsHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7527. return err
  7528. }
  7529. }
  7530. if !key.Valid() {
  7531. return fmt.Errorf("invalid GCE key (%+v)", key)
  7532. }
  7533. m.Lock.Lock()
  7534. defer m.Lock.Unlock()
  7535. if err, ok := m.DeleteError[*key]; ok {
  7536. klog.V(5).Infof("MockHttpsHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7537. return err
  7538. }
  7539. if _, ok := m.Objects[*key]; !ok {
  7540. err := &googleapi.Error{
  7541. Code: http.StatusNotFound,
  7542. Message: fmt.Sprintf("MockHttpsHealthChecks %v not found", key),
  7543. }
  7544. klog.V(5).Infof("MockHttpsHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7545. return err
  7546. }
  7547. delete(m.Objects, *key)
  7548. klog.V(5).Infof("MockHttpsHealthChecks.Delete(%v, %v) = nil", ctx, key)
  7549. return nil
  7550. }
  7551. // Obj wraps the object for use in the mock.
  7552. func (m *MockHttpsHealthChecks) Obj(o *ga.HttpsHealthCheck) *MockHttpsHealthChecksObj {
  7553. return &MockHttpsHealthChecksObj{o}
  7554. }
  7555. // Update is a mock for the corresponding method.
  7556. func (m *MockHttpsHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *ga.HttpsHealthCheck) error {
  7557. if m.UpdateHook != nil {
  7558. return m.UpdateHook(ctx, key, arg0, m)
  7559. }
  7560. return nil
  7561. }
  7562. // GCEHttpsHealthChecks is a simplifying adapter for the GCE HttpsHealthChecks.
  7563. type GCEHttpsHealthChecks struct {
  7564. s *Service
  7565. }
  7566. // Get the HttpsHealthCheck named by key.
  7567. func (g *GCEHttpsHealthChecks) Get(ctx context.Context, key *meta.Key) (*ga.HttpsHealthCheck, error) {
  7568. klog.V(5).Infof("GCEHttpsHealthChecks.Get(%v, %v): called", ctx, key)
  7569. if !key.Valid() {
  7570. klog.V(2).Infof("GCEHttpsHealthChecks.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  7571. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  7572. }
  7573. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpsHealthChecks")
  7574. rk := &RateLimitKey{
  7575. ProjectID: projectID,
  7576. Operation: "Get",
  7577. Version: meta.Version("ga"),
  7578. Service: "HttpsHealthChecks",
  7579. }
  7580. klog.V(5).Infof("GCEHttpsHealthChecks.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7581. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7582. klog.V(4).Infof("GCEHttpsHealthChecks.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  7583. return nil, err
  7584. }
  7585. call := g.s.GA.HttpsHealthChecks.Get(projectID, key.Name)
  7586. call.Context(ctx)
  7587. v, err := call.Do()
  7588. klog.V(4).Infof("GCEHttpsHealthChecks.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  7589. return v, err
  7590. }
  7591. // List all HttpsHealthCheck objects.
  7592. func (g *GCEHttpsHealthChecks) List(ctx context.Context, fl *filter.F) ([]*ga.HttpsHealthCheck, error) {
  7593. klog.V(5).Infof("GCEHttpsHealthChecks.List(%v, %v) called", ctx, fl)
  7594. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpsHealthChecks")
  7595. rk := &RateLimitKey{
  7596. ProjectID: projectID,
  7597. Operation: "List",
  7598. Version: meta.Version("ga"),
  7599. Service: "HttpsHealthChecks",
  7600. }
  7601. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7602. return nil, err
  7603. }
  7604. klog.V(5).Infof("GCEHttpsHealthChecks.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  7605. call := g.s.GA.HttpsHealthChecks.List(projectID)
  7606. if fl != filter.None {
  7607. call.Filter(fl.String())
  7608. }
  7609. var all []*ga.HttpsHealthCheck
  7610. f := func(l *ga.HttpsHealthCheckList) error {
  7611. klog.V(5).Infof("GCEHttpsHealthChecks.List(%v, ..., %v): page %+v", ctx, fl, l)
  7612. all = append(all, l.Items...)
  7613. return nil
  7614. }
  7615. if err := call.Pages(ctx, f); err != nil {
  7616. klog.V(4).Infof("GCEHttpsHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  7617. return nil, err
  7618. }
  7619. if klog.V(4) {
  7620. klog.V(4).Infof("GCEHttpsHealthChecks.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  7621. } else if klog.V(5) {
  7622. var asStr []string
  7623. for _, o := range all {
  7624. asStr = append(asStr, fmt.Sprintf("%+v", o))
  7625. }
  7626. klog.V(5).Infof("GCEHttpsHealthChecks.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  7627. }
  7628. return all, nil
  7629. }
  7630. // Insert HttpsHealthCheck with key of value obj.
  7631. func (g *GCEHttpsHealthChecks) Insert(ctx context.Context, key *meta.Key, obj *ga.HttpsHealthCheck) error {
  7632. klog.V(5).Infof("GCEHttpsHealthChecks.Insert(%v, %v, %+v): called", ctx, key, obj)
  7633. if !key.Valid() {
  7634. klog.V(2).Infof("GCEHttpsHealthChecks.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  7635. return fmt.Errorf("invalid GCE key (%+v)", key)
  7636. }
  7637. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpsHealthChecks")
  7638. rk := &RateLimitKey{
  7639. ProjectID: projectID,
  7640. Operation: "Insert",
  7641. Version: meta.Version("ga"),
  7642. Service: "HttpsHealthChecks",
  7643. }
  7644. klog.V(5).Infof("GCEHttpsHealthChecks.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7645. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7646. klog.V(4).Infof("GCEHttpsHealthChecks.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  7647. return err
  7648. }
  7649. obj.Name = key.Name
  7650. call := g.s.GA.HttpsHealthChecks.Insert(projectID, obj)
  7651. call.Context(ctx)
  7652. op, err := call.Do()
  7653. if err != nil {
  7654. klog.V(4).Infof("GCEHttpsHealthChecks.Insert(%v, %v, ...) = %+v", ctx, key, err)
  7655. return err
  7656. }
  7657. err = g.s.WaitForCompletion(ctx, op)
  7658. klog.V(4).Infof("GCEHttpsHealthChecks.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  7659. return err
  7660. }
  7661. // Delete the HttpsHealthCheck referenced by key.
  7662. func (g *GCEHttpsHealthChecks) Delete(ctx context.Context, key *meta.Key) error {
  7663. klog.V(5).Infof("GCEHttpsHealthChecks.Delete(%v, %v): called", ctx, key)
  7664. if !key.Valid() {
  7665. klog.V(2).Infof("GCEHttpsHealthChecks.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  7666. return fmt.Errorf("invalid GCE key (%+v)", key)
  7667. }
  7668. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpsHealthChecks")
  7669. rk := &RateLimitKey{
  7670. ProjectID: projectID,
  7671. Operation: "Delete",
  7672. Version: meta.Version("ga"),
  7673. Service: "HttpsHealthChecks",
  7674. }
  7675. klog.V(5).Infof("GCEHttpsHealthChecks.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7676. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7677. klog.V(4).Infof("GCEHttpsHealthChecks.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  7678. return err
  7679. }
  7680. call := g.s.GA.HttpsHealthChecks.Delete(projectID, key.Name)
  7681. call.Context(ctx)
  7682. op, err := call.Do()
  7683. if err != nil {
  7684. klog.V(4).Infof("GCEHttpsHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7685. return err
  7686. }
  7687. err = g.s.WaitForCompletion(ctx, op)
  7688. klog.V(4).Infof("GCEHttpsHealthChecks.Delete(%v, %v) = %v", ctx, key, err)
  7689. return err
  7690. }
  7691. // Update is a method on GCEHttpsHealthChecks.
  7692. func (g *GCEHttpsHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *ga.HttpsHealthCheck) error {
  7693. klog.V(5).Infof("GCEHttpsHealthChecks.Update(%v, %v, ...): called", ctx, key)
  7694. if !key.Valid() {
  7695. klog.V(2).Infof("GCEHttpsHealthChecks.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  7696. return fmt.Errorf("invalid GCE key (%+v)", key)
  7697. }
  7698. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "HttpsHealthChecks")
  7699. rk := &RateLimitKey{
  7700. ProjectID: projectID,
  7701. Operation: "Update",
  7702. Version: meta.Version("ga"),
  7703. Service: "HttpsHealthChecks",
  7704. }
  7705. klog.V(5).Infof("GCEHttpsHealthChecks.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7706. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7707. klog.V(4).Infof("GCEHttpsHealthChecks.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  7708. return err
  7709. }
  7710. call := g.s.GA.HttpsHealthChecks.Update(projectID, key.Name, arg0)
  7711. call.Context(ctx)
  7712. op, err := call.Do()
  7713. if err != nil {
  7714. klog.V(4).Infof("GCEHttpsHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  7715. return err
  7716. }
  7717. err = g.s.WaitForCompletion(ctx, op)
  7718. klog.V(4).Infof("GCEHttpsHealthChecks.Update(%v, %v, ...) = %+v", ctx, key, err)
  7719. return err
  7720. }
  7721. // InstanceGroups is an interface that allows for mocking of InstanceGroups.
  7722. type InstanceGroups interface {
  7723. Get(ctx context.Context, key *meta.Key) (*ga.InstanceGroup, error)
  7724. List(ctx context.Context, zone string, fl *filter.F) ([]*ga.InstanceGroup, error)
  7725. Insert(ctx context.Context, key *meta.Key, obj *ga.InstanceGroup) error
  7726. Delete(ctx context.Context, key *meta.Key) error
  7727. AddInstances(context.Context, *meta.Key, *ga.InstanceGroupsAddInstancesRequest) error
  7728. ListInstances(context.Context, *meta.Key, *ga.InstanceGroupsListInstancesRequest, *filter.F) ([]*ga.InstanceWithNamedPorts, error)
  7729. RemoveInstances(context.Context, *meta.Key, *ga.InstanceGroupsRemoveInstancesRequest) error
  7730. SetNamedPorts(context.Context, *meta.Key, *ga.InstanceGroupsSetNamedPortsRequest) error
  7731. }
  7732. // NewMockInstanceGroups returns a new mock for InstanceGroups.
  7733. func NewMockInstanceGroups(pr ProjectRouter, objs map[meta.Key]*MockInstanceGroupsObj) *MockInstanceGroups {
  7734. mock := &MockInstanceGroups{
  7735. ProjectRouter: pr,
  7736. Objects: objs,
  7737. GetError: map[meta.Key]error{},
  7738. InsertError: map[meta.Key]error{},
  7739. DeleteError: map[meta.Key]error{},
  7740. }
  7741. return mock
  7742. }
  7743. // MockInstanceGroups is the mock for InstanceGroups.
  7744. type MockInstanceGroups struct {
  7745. Lock sync.Mutex
  7746. ProjectRouter ProjectRouter
  7747. // Objects maintained by the mock.
  7748. Objects map[meta.Key]*MockInstanceGroupsObj
  7749. // If an entry exists for the given key and operation, then the error
  7750. // will be returned instead of the operation.
  7751. GetError map[meta.Key]error
  7752. ListError *error
  7753. InsertError map[meta.Key]error
  7754. DeleteError map[meta.Key]error
  7755. // xxxHook allow you to intercept the standard processing of the mock in
  7756. // order to add your own logic. Return (true, _, _) to prevent the normal
  7757. // execution flow of the mock. Return (false, nil, nil) to continue with
  7758. // normal mock behavior/ after the hook function executes.
  7759. GetHook func(ctx context.Context, key *meta.Key, m *MockInstanceGroups) (bool, *ga.InstanceGroup, error)
  7760. ListHook func(ctx context.Context, zone string, fl *filter.F, m *MockInstanceGroups) (bool, []*ga.InstanceGroup, error)
  7761. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.InstanceGroup, m *MockInstanceGroups) (bool, error)
  7762. DeleteHook func(ctx context.Context, key *meta.Key, m *MockInstanceGroups) (bool, error)
  7763. AddInstancesHook func(context.Context, *meta.Key, *ga.InstanceGroupsAddInstancesRequest, *MockInstanceGroups) error
  7764. ListInstancesHook func(context.Context, *meta.Key, *ga.InstanceGroupsListInstancesRequest, *filter.F, *MockInstanceGroups) ([]*ga.InstanceWithNamedPorts, error)
  7765. RemoveInstancesHook func(context.Context, *meta.Key, *ga.InstanceGroupsRemoveInstancesRequest, *MockInstanceGroups) error
  7766. SetNamedPortsHook func(context.Context, *meta.Key, *ga.InstanceGroupsSetNamedPortsRequest, *MockInstanceGroups) error
  7767. // X is extra state that can be used as part of the mock. Generated code
  7768. // will not use this field.
  7769. X interface{}
  7770. }
  7771. // Get returns the object from the mock.
  7772. func (m *MockInstanceGroups) Get(ctx context.Context, key *meta.Key) (*ga.InstanceGroup, error) {
  7773. if m.GetHook != nil {
  7774. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  7775. klog.V(5).Infof("MockInstanceGroups.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  7776. return obj, err
  7777. }
  7778. }
  7779. if !key.Valid() {
  7780. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  7781. }
  7782. m.Lock.Lock()
  7783. defer m.Lock.Unlock()
  7784. if err, ok := m.GetError[*key]; ok {
  7785. klog.V(5).Infof("MockInstanceGroups.Get(%v, %s) = nil, %v", ctx, key, err)
  7786. return nil, err
  7787. }
  7788. if obj, ok := m.Objects[*key]; ok {
  7789. typedObj := obj.ToGA()
  7790. klog.V(5).Infof("MockInstanceGroups.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  7791. return typedObj, nil
  7792. }
  7793. err := &googleapi.Error{
  7794. Code: http.StatusNotFound,
  7795. Message: fmt.Sprintf("MockInstanceGroups %v not found", key),
  7796. }
  7797. klog.V(5).Infof("MockInstanceGroups.Get(%v, %s) = nil, %v", ctx, key, err)
  7798. return nil, err
  7799. }
  7800. // List all of the objects in the mock in the given zone.
  7801. func (m *MockInstanceGroups) List(ctx context.Context, zone string, fl *filter.F) ([]*ga.InstanceGroup, error) {
  7802. if m.ListHook != nil {
  7803. if intercept, objs, err := m.ListHook(ctx, zone, fl, m); intercept {
  7804. klog.V(5).Infof("MockInstanceGroups.List(%v, %q, %v) = [%v items], %v", ctx, zone, fl, len(objs), err)
  7805. return objs, err
  7806. }
  7807. }
  7808. m.Lock.Lock()
  7809. defer m.Lock.Unlock()
  7810. if m.ListError != nil {
  7811. err := *m.ListError
  7812. klog.V(5).Infof("MockInstanceGroups.List(%v, %q, %v) = nil, %v", ctx, zone, fl, err)
  7813. return nil, *m.ListError
  7814. }
  7815. var objs []*ga.InstanceGroup
  7816. for key, obj := range m.Objects {
  7817. if key.Zone != zone {
  7818. continue
  7819. }
  7820. if !fl.Match(obj.ToGA()) {
  7821. continue
  7822. }
  7823. objs = append(objs, obj.ToGA())
  7824. }
  7825. klog.V(5).Infof("MockInstanceGroups.List(%v, %q, %v) = [%v items], nil", ctx, zone, fl, len(objs))
  7826. return objs, nil
  7827. }
  7828. // Insert is a mock for inserting/creating a new object.
  7829. func (m *MockInstanceGroups) Insert(ctx context.Context, key *meta.Key, obj *ga.InstanceGroup) error {
  7830. if m.InsertHook != nil {
  7831. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  7832. klog.V(5).Infof("MockInstanceGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7833. return err
  7834. }
  7835. }
  7836. if !key.Valid() {
  7837. return fmt.Errorf("invalid GCE key (%+v)", key)
  7838. }
  7839. m.Lock.Lock()
  7840. defer m.Lock.Unlock()
  7841. if err, ok := m.InsertError[*key]; ok {
  7842. klog.V(5).Infof("MockInstanceGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7843. return err
  7844. }
  7845. if _, ok := m.Objects[*key]; ok {
  7846. err := &googleapi.Error{
  7847. Code: http.StatusConflict,
  7848. Message: fmt.Sprintf("MockInstanceGroups %v exists", key),
  7849. }
  7850. klog.V(5).Infof("MockInstanceGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  7851. return err
  7852. }
  7853. obj.Name = key.Name
  7854. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "instanceGroups")
  7855. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "instanceGroups", key)
  7856. m.Objects[*key] = &MockInstanceGroupsObj{obj}
  7857. klog.V(5).Infof("MockInstanceGroups.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  7858. return nil
  7859. }
  7860. // Delete is a mock for deleting the object.
  7861. func (m *MockInstanceGroups) Delete(ctx context.Context, key *meta.Key) error {
  7862. if m.DeleteHook != nil {
  7863. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  7864. klog.V(5).Infof("MockInstanceGroups.Delete(%v, %v) = %v", ctx, key, err)
  7865. return err
  7866. }
  7867. }
  7868. if !key.Valid() {
  7869. return fmt.Errorf("invalid GCE key (%+v)", key)
  7870. }
  7871. m.Lock.Lock()
  7872. defer m.Lock.Unlock()
  7873. if err, ok := m.DeleteError[*key]; ok {
  7874. klog.V(5).Infof("MockInstanceGroups.Delete(%v, %v) = %v", ctx, key, err)
  7875. return err
  7876. }
  7877. if _, ok := m.Objects[*key]; !ok {
  7878. err := &googleapi.Error{
  7879. Code: http.StatusNotFound,
  7880. Message: fmt.Sprintf("MockInstanceGroups %v not found", key),
  7881. }
  7882. klog.V(5).Infof("MockInstanceGroups.Delete(%v, %v) = %v", ctx, key, err)
  7883. return err
  7884. }
  7885. delete(m.Objects, *key)
  7886. klog.V(5).Infof("MockInstanceGroups.Delete(%v, %v) = nil", ctx, key)
  7887. return nil
  7888. }
  7889. // Obj wraps the object for use in the mock.
  7890. func (m *MockInstanceGroups) Obj(o *ga.InstanceGroup) *MockInstanceGroupsObj {
  7891. return &MockInstanceGroupsObj{o}
  7892. }
  7893. // AddInstances is a mock for the corresponding method.
  7894. func (m *MockInstanceGroups) AddInstances(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsAddInstancesRequest) error {
  7895. if m.AddInstancesHook != nil {
  7896. return m.AddInstancesHook(ctx, key, arg0, m)
  7897. }
  7898. return nil
  7899. }
  7900. // ListInstances is a mock for the corresponding method.
  7901. func (m *MockInstanceGroups) ListInstances(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsListInstancesRequest, fl *filter.F) ([]*ga.InstanceWithNamedPorts, error) {
  7902. if m.ListInstancesHook != nil {
  7903. return m.ListInstancesHook(ctx, key, arg0, fl, m)
  7904. }
  7905. return nil, nil
  7906. }
  7907. // RemoveInstances is a mock for the corresponding method.
  7908. func (m *MockInstanceGroups) RemoveInstances(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsRemoveInstancesRequest) error {
  7909. if m.RemoveInstancesHook != nil {
  7910. return m.RemoveInstancesHook(ctx, key, arg0, m)
  7911. }
  7912. return nil
  7913. }
  7914. // SetNamedPorts is a mock for the corresponding method.
  7915. func (m *MockInstanceGroups) SetNamedPorts(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsSetNamedPortsRequest) error {
  7916. if m.SetNamedPortsHook != nil {
  7917. return m.SetNamedPortsHook(ctx, key, arg0, m)
  7918. }
  7919. return nil
  7920. }
  7921. // GCEInstanceGroups is a simplifying adapter for the GCE InstanceGroups.
  7922. type GCEInstanceGroups struct {
  7923. s *Service
  7924. }
  7925. // Get the InstanceGroup named by key.
  7926. func (g *GCEInstanceGroups) Get(ctx context.Context, key *meta.Key) (*ga.InstanceGroup, error) {
  7927. klog.V(5).Infof("GCEInstanceGroups.Get(%v, %v): called", ctx, key)
  7928. if !key.Valid() {
  7929. klog.V(2).Infof("GCEInstanceGroups.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  7930. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  7931. }
  7932. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  7933. rk := &RateLimitKey{
  7934. ProjectID: projectID,
  7935. Operation: "Get",
  7936. Version: meta.Version("ga"),
  7937. Service: "InstanceGroups",
  7938. }
  7939. klog.V(5).Infof("GCEInstanceGroups.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  7940. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7941. klog.V(4).Infof("GCEInstanceGroups.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  7942. return nil, err
  7943. }
  7944. call := g.s.GA.InstanceGroups.Get(projectID, key.Zone, key.Name)
  7945. call.Context(ctx)
  7946. v, err := call.Do()
  7947. klog.V(4).Infof("GCEInstanceGroups.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  7948. return v, err
  7949. }
  7950. // List all InstanceGroup objects.
  7951. func (g *GCEInstanceGroups) List(ctx context.Context, zone string, fl *filter.F) ([]*ga.InstanceGroup, error) {
  7952. klog.V(5).Infof("GCEInstanceGroups.List(%v, %v, %v) called", ctx, zone, fl)
  7953. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  7954. rk := &RateLimitKey{
  7955. ProjectID: projectID,
  7956. Operation: "List",
  7957. Version: meta.Version("ga"),
  7958. Service: "InstanceGroups",
  7959. }
  7960. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  7961. return nil, err
  7962. }
  7963. klog.V(5).Infof("GCEInstanceGroups.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
  7964. call := g.s.GA.InstanceGroups.List(projectID, zone)
  7965. if fl != filter.None {
  7966. call.Filter(fl.String())
  7967. }
  7968. var all []*ga.InstanceGroup
  7969. f := func(l *ga.InstanceGroupList) error {
  7970. klog.V(5).Infof("GCEInstanceGroups.List(%v, ..., %v): page %+v", ctx, fl, l)
  7971. all = append(all, l.Items...)
  7972. return nil
  7973. }
  7974. if err := call.Pages(ctx, f); err != nil {
  7975. klog.V(4).Infof("GCEInstanceGroups.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  7976. return nil, err
  7977. }
  7978. if klog.V(4) {
  7979. klog.V(4).Infof("GCEInstanceGroups.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  7980. } else if klog.V(5) {
  7981. var asStr []string
  7982. for _, o := range all {
  7983. asStr = append(asStr, fmt.Sprintf("%+v", o))
  7984. }
  7985. klog.V(5).Infof("GCEInstanceGroups.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  7986. }
  7987. return all, nil
  7988. }
  7989. // Insert InstanceGroup with key of value obj.
  7990. func (g *GCEInstanceGroups) Insert(ctx context.Context, key *meta.Key, obj *ga.InstanceGroup) error {
  7991. klog.V(5).Infof("GCEInstanceGroups.Insert(%v, %v, %+v): called", ctx, key, obj)
  7992. if !key.Valid() {
  7993. klog.V(2).Infof("GCEInstanceGroups.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  7994. return fmt.Errorf("invalid GCE key (%+v)", key)
  7995. }
  7996. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  7997. rk := &RateLimitKey{
  7998. ProjectID: projectID,
  7999. Operation: "Insert",
  8000. Version: meta.Version("ga"),
  8001. Service: "InstanceGroups",
  8002. }
  8003. klog.V(5).Infof("GCEInstanceGroups.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8004. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8005. klog.V(4).Infof("GCEInstanceGroups.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8006. return err
  8007. }
  8008. obj.Name = key.Name
  8009. call := g.s.GA.InstanceGroups.Insert(projectID, key.Zone, obj)
  8010. call.Context(ctx)
  8011. op, err := call.Do()
  8012. if err != nil {
  8013. klog.V(4).Infof("GCEInstanceGroups.Insert(%v, %v, ...) = %+v", ctx, key, err)
  8014. return err
  8015. }
  8016. err = g.s.WaitForCompletion(ctx, op)
  8017. klog.V(4).Infof("GCEInstanceGroups.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  8018. return err
  8019. }
  8020. // Delete the InstanceGroup referenced by key.
  8021. func (g *GCEInstanceGroups) Delete(ctx context.Context, key *meta.Key) error {
  8022. klog.V(5).Infof("GCEInstanceGroups.Delete(%v, %v): called", ctx, key)
  8023. if !key.Valid() {
  8024. klog.V(2).Infof("GCEInstanceGroups.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  8025. return fmt.Errorf("invalid GCE key (%+v)", key)
  8026. }
  8027. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  8028. rk := &RateLimitKey{
  8029. ProjectID: projectID,
  8030. Operation: "Delete",
  8031. Version: meta.Version("ga"),
  8032. Service: "InstanceGroups",
  8033. }
  8034. klog.V(5).Infof("GCEInstanceGroups.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8035. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8036. klog.V(4).Infof("GCEInstanceGroups.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  8037. return err
  8038. }
  8039. call := g.s.GA.InstanceGroups.Delete(projectID, key.Zone, key.Name)
  8040. call.Context(ctx)
  8041. op, err := call.Do()
  8042. if err != nil {
  8043. klog.V(4).Infof("GCEInstanceGroups.Delete(%v, %v) = %v", ctx, key, err)
  8044. return err
  8045. }
  8046. err = g.s.WaitForCompletion(ctx, op)
  8047. klog.V(4).Infof("GCEInstanceGroups.Delete(%v, %v) = %v", ctx, key, err)
  8048. return err
  8049. }
  8050. // AddInstances is a method on GCEInstanceGroups.
  8051. func (g *GCEInstanceGroups) AddInstances(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsAddInstancesRequest) error {
  8052. klog.V(5).Infof("GCEInstanceGroups.AddInstances(%v, %v, ...): called", ctx, key)
  8053. if !key.Valid() {
  8054. klog.V(2).Infof("GCEInstanceGroups.AddInstances(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8055. return fmt.Errorf("invalid GCE key (%+v)", key)
  8056. }
  8057. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  8058. rk := &RateLimitKey{
  8059. ProjectID: projectID,
  8060. Operation: "AddInstances",
  8061. Version: meta.Version("ga"),
  8062. Service: "InstanceGroups",
  8063. }
  8064. klog.V(5).Infof("GCEInstanceGroups.AddInstances(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8065. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8066. klog.V(4).Infof("GCEInstanceGroups.AddInstances(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8067. return err
  8068. }
  8069. call := g.s.GA.InstanceGroups.AddInstances(projectID, key.Zone, key.Name, arg0)
  8070. call.Context(ctx)
  8071. op, err := call.Do()
  8072. if err != nil {
  8073. klog.V(4).Infof("GCEInstanceGroups.AddInstances(%v, %v, ...) = %+v", ctx, key, err)
  8074. return err
  8075. }
  8076. err = g.s.WaitForCompletion(ctx, op)
  8077. klog.V(4).Infof("GCEInstanceGroups.AddInstances(%v, %v, ...) = %+v", ctx, key, err)
  8078. return err
  8079. }
  8080. // ListInstances is a method on GCEInstanceGroups.
  8081. func (g *GCEInstanceGroups) ListInstances(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsListInstancesRequest, fl *filter.F) ([]*ga.InstanceWithNamedPorts, error) {
  8082. klog.V(5).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...): called", ctx, key)
  8083. if !key.Valid() {
  8084. klog.V(2).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8085. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  8086. }
  8087. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  8088. rk := &RateLimitKey{
  8089. ProjectID: projectID,
  8090. Operation: "ListInstances",
  8091. Version: meta.Version("ga"),
  8092. Service: "InstanceGroups",
  8093. }
  8094. klog.V(5).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8095. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8096. klog.V(4).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8097. return nil, err
  8098. }
  8099. call := g.s.GA.InstanceGroups.ListInstances(projectID, key.Zone, key.Name, arg0)
  8100. var all []*ga.InstanceWithNamedPorts
  8101. f := func(l *ga.InstanceGroupsListInstances) error {
  8102. klog.V(5).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...): page %+v", ctx, key, l)
  8103. all = append(all, l.Items...)
  8104. return nil
  8105. }
  8106. if err := call.Pages(ctx, f); err != nil {
  8107. klog.V(4).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...) = %v, %v", ctx, key, nil, err)
  8108. return nil, err
  8109. }
  8110. if klog.V(4) {
  8111. klog.V(4).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...) = [%v items], %v", ctx, key, len(all), nil)
  8112. } else if klog.V(5) {
  8113. var asStr []string
  8114. for _, o := range all {
  8115. asStr = append(asStr, fmt.Sprintf("%+v", o))
  8116. }
  8117. klog.V(5).Infof("GCEInstanceGroups.ListInstances(%v, %v, ...) = %v, %v", ctx, key, asStr, nil)
  8118. }
  8119. return all, nil
  8120. }
  8121. // RemoveInstances is a method on GCEInstanceGroups.
  8122. func (g *GCEInstanceGroups) RemoveInstances(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsRemoveInstancesRequest) error {
  8123. klog.V(5).Infof("GCEInstanceGroups.RemoveInstances(%v, %v, ...): called", ctx, key)
  8124. if !key.Valid() {
  8125. klog.V(2).Infof("GCEInstanceGroups.RemoveInstances(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8126. return fmt.Errorf("invalid GCE key (%+v)", key)
  8127. }
  8128. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  8129. rk := &RateLimitKey{
  8130. ProjectID: projectID,
  8131. Operation: "RemoveInstances",
  8132. Version: meta.Version("ga"),
  8133. Service: "InstanceGroups",
  8134. }
  8135. klog.V(5).Infof("GCEInstanceGroups.RemoveInstances(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8136. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8137. klog.V(4).Infof("GCEInstanceGroups.RemoveInstances(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8138. return err
  8139. }
  8140. call := g.s.GA.InstanceGroups.RemoveInstances(projectID, key.Zone, key.Name, arg0)
  8141. call.Context(ctx)
  8142. op, err := call.Do()
  8143. if err != nil {
  8144. klog.V(4).Infof("GCEInstanceGroups.RemoveInstances(%v, %v, ...) = %+v", ctx, key, err)
  8145. return err
  8146. }
  8147. err = g.s.WaitForCompletion(ctx, op)
  8148. klog.V(4).Infof("GCEInstanceGroups.RemoveInstances(%v, %v, ...) = %+v", ctx, key, err)
  8149. return err
  8150. }
  8151. // SetNamedPorts is a method on GCEInstanceGroups.
  8152. func (g *GCEInstanceGroups) SetNamedPorts(ctx context.Context, key *meta.Key, arg0 *ga.InstanceGroupsSetNamedPortsRequest) error {
  8153. klog.V(5).Infof("GCEInstanceGroups.SetNamedPorts(%v, %v, ...): called", ctx, key)
  8154. if !key.Valid() {
  8155. klog.V(2).Infof("GCEInstanceGroups.SetNamedPorts(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8156. return fmt.Errorf("invalid GCE key (%+v)", key)
  8157. }
  8158. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "InstanceGroups")
  8159. rk := &RateLimitKey{
  8160. ProjectID: projectID,
  8161. Operation: "SetNamedPorts",
  8162. Version: meta.Version("ga"),
  8163. Service: "InstanceGroups",
  8164. }
  8165. klog.V(5).Infof("GCEInstanceGroups.SetNamedPorts(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8166. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8167. klog.V(4).Infof("GCEInstanceGroups.SetNamedPorts(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8168. return err
  8169. }
  8170. call := g.s.GA.InstanceGroups.SetNamedPorts(projectID, key.Zone, key.Name, arg0)
  8171. call.Context(ctx)
  8172. op, err := call.Do()
  8173. if err != nil {
  8174. klog.V(4).Infof("GCEInstanceGroups.SetNamedPorts(%v, %v, ...) = %+v", ctx, key, err)
  8175. return err
  8176. }
  8177. err = g.s.WaitForCompletion(ctx, op)
  8178. klog.V(4).Infof("GCEInstanceGroups.SetNamedPorts(%v, %v, ...) = %+v", ctx, key, err)
  8179. return err
  8180. }
  8181. // Instances is an interface that allows for mocking of Instances.
  8182. type Instances interface {
  8183. Get(ctx context.Context, key *meta.Key) (*ga.Instance, error)
  8184. List(ctx context.Context, zone string, fl *filter.F) ([]*ga.Instance, error)
  8185. Insert(ctx context.Context, key *meta.Key, obj *ga.Instance) error
  8186. Delete(ctx context.Context, key *meta.Key) error
  8187. AttachDisk(context.Context, *meta.Key, *ga.AttachedDisk) error
  8188. DetachDisk(context.Context, *meta.Key, string) error
  8189. }
  8190. // NewMockInstances returns a new mock for Instances.
  8191. func NewMockInstances(pr ProjectRouter, objs map[meta.Key]*MockInstancesObj) *MockInstances {
  8192. mock := &MockInstances{
  8193. ProjectRouter: pr,
  8194. Objects: objs,
  8195. GetError: map[meta.Key]error{},
  8196. InsertError: map[meta.Key]error{},
  8197. DeleteError: map[meta.Key]error{},
  8198. }
  8199. return mock
  8200. }
  8201. // MockInstances is the mock for Instances.
  8202. type MockInstances struct {
  8203. Lock sync.Mutex
  8204. ProjectRouter ProjectRouter
  8205. // Objects maintained by the mock.
  8206. Objects map[meta.Key]*MockInstancesObj
  8207. // If an entry exists for the given key and operation, then the error
  8208. // will be returned instead of the operation.
  8209. GetError map[meta.Key]error
  8210. ListError *error
  8211. InsertError map[meta.Key]error
  8212. DeleteError map[meta.Key]error
  8213. // xxxHook allow you to intercept the standard processing of the mock in
  8214. // order to add your own logic. Return (true, _, _) to prevent the normal
  8215. // execution flow of the mock. Return (false, nil, nil) to continue with
  8216. // normal mock behavior/ after the hook function executes.
  8217. GetHook func(ctx context.Context, key *meta.Key, m *MockInstances) (bool, *ga.Instance, error)
  8218. ListHook func(ctx context.Context, zone string, fl *filter.F, m *MockInstances) (bool, []*ga.Instance, error)
  8219. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.Instance, m *MockInstances) (bool, error)
  8220. DeleteHook func(ctx context.Context, key *meta.Key, m *MockInstances) (bool, error)
  8221. AttachDiskHook func(context.Context, *meta.Key, *ga.AttachedDisk, *MockInstances) error
  8222. DetachDiskHook func(context.Context, *meta.Key, string, *MockInstances) error
  8223. // X is extra state that can be used as part of the mock. Generated code
  8224. // will not use this field.
  8225. X interface{}
  8226. }
  8227. // Get returns the object from the mock.
  8228. func (m *MockInstances) Get(ctx context.Context, key *meta.Key) (*ga.Instance, error) {
  8229. if m.GetHook != nil {
  8230. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  8231. klog.V(5).Infof("MockInstances.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  8232. return obj, err
  8233. }
  8234. }
  8235. if !key.Valid() {
  8236. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  8237. }
  8238. m.Lock.Lock()
  8239. defer m.Lock.Unlock()
  8240. if err, ok := m.GetError[*key]; ok {
  8241. klog.V(5).Infof("MockInstances.Get(%v, %s) = nil, %v", ctx, key, err)
  8242. return nil, err
  8243. }
  8244. if obj, ok := m.Objects[*key]; ok {
  8245. typedObj := obj.ToGA()
  8246. klog.V(5).Infof("MockInstances.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  8247. return typedObj, nil
  8248. }
  8249. err := &googleapi.Error{
  8250. Code: http.StatusNotFound,
  8251. Message: fmt.Sprintf("MockInstances %v not found", key),
  8252. }
  8253. klog.V(5).Infof("MockInstances.Get(%v, %s) = nil, %v", ctx, key, err)
  8254. return nil, err
  8255. }
  8256. // List all of the objects in the mock in the given zone.
  8257. func (m *MockInstances) List(ctx context.Context, zone string, fl *filter.F) ([]*ga.Instance, error) {
  8258. if m.ListHook != nil {
  8259. if intercept, objs, err := m.ListHook(ctx, zone, fl, m); intercept {
  8260. klog.V(5).Infof("MockInstances.List(%v, %q, %v) = [%v items], %v", ctx, zone, fl, len(objs), err)
  8261. return objs, err
  8262. }
  8263. }
  8264. m.Lock.Lock()
  8265. defer m.Lock.Unlock()
  8266. if m.ListError != nil {
  8267. err := *m.ListError
  8268. klog.V(5).Infof("MockInstances.List(%v, %q, %v) = nil, %v", ctx, zone, fl, err)
  8269. return nil, *m.ListError
  8270. }
  8271. var objs []*ga.Instance
  8272. for key, obj := range m.Objects {
  8273. if key.Zone != zone {
  8274. continue
  8275. }
  8276. if !fl.Match(obj.ToGA()) {
  8277. continue
  8278. }
  8279. objs = append(objs, obj.ToGA())
  8280. }
  8281. klog.V(5).Infof("MockInstances.List(%v, %q, %v) = [%v items], nil", ctx, zone, fl, len(objs))
  8282. return objs, nil
  8283. }
  8284. // Insert is a mock for inserting/creating a new object.
  8285. func (m *MockInstances) Insert(ctx context.Context, key *meta.Key, obj *ga.Instance) error {
  8286. if m.InsertHook != nil {
  8287. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  8288. klog.V(5).Infof("MockInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  8289. return err
  8290. }
  8291. }
  8292. if !key.Valid() {
  8293. return fmt.Errorf("invalid GCE key (%+v)", key)
  8294. }
  8295. m.Lock.Lock()
  8296. defer m.Lock.Unlock()
  8297. if err, ok := m.InsertError[*key]; ok {
  8298. klog.V(5).Infof("MockInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  8299. return err
  8300. }
  8301. if _, ok := m.Objects[*key]; ok {
  8302. err := &googleapi.Error{
  8303. Code: http.StatusConflict,
  8304. Message: fmt.Sprintf("MockInstances %v exists", key),
  8305. }
  8306. klog.V(5).Infof("MockInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  8307. return err
  8308. }
  8309. obj.Name = key.Name
  8310. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "instances")
  8311. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "instances", key)
  8312. m.Objects[*key] = &MockInstancesObj{obj}
  8313. klog.V(5).Infof("MockInstances.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  8314. return nil
  8315. }
  8316. // Delete is a mock for deleting the object.
  8317. func (m *MockInstances) Delete(ctx context.Context, key *meta.Key) error {
  8318. if m.DeleteHook != nil {
  8319. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  8320. klog.V(5).Infof("MockInstances.Delete(%v, %v) = %v", ctx, key, err)
  8321. return err
  8322. }
  8323. }
  8324. if !key.Valid() {
  8325. return fmt.Errorf("invalid GCE key (%+v)", key)
  8326. }
  8327. m.Lock.Lock()
  8328. defer m.Lock.Unlock()
  8329. if err, ok := m.DeleteError[*key]; ok {
  8330. klog.V(5).Infof("MockInstances.Delete(%v, %v) = %v", ctx, key, err)
  8331. return err
  8332. }
  8333. if _, ok := m.Objects[*key]; !ok {
  8334. err := &googleapi.Error{
  8335. Code: http.StatusNotFound,
  8336. Message: fmt.Sprintf("MockInstances %v not found", key),
  8337. }
  8338. klog.V(5).Infof("MockInstances.Delete(%v, %v) = %v", ctx, key, err)
  8339. return err
  8340. }
  8341. delete(m.Objects, *key)
  8342. klog.V(5).Infof("MockInstances.Delete(%v, %v) = nil", ctx, key)
  8343. return nil
  8344. }
  8345. // Obj wraps the object for use in the mock.
  8346. func (m *MockInstances) Obj(o *ga.Instance) *MockInstancesObj {
  8347. return &MockInstancesObj{o}
  8348. }
  8349. // AttachDisk is a mock for the corresponding method.
  8350. func (m *MockInstances) AttachDisk(ctx context.Context, key *meta.Key, arg0 *ga.AttachedDisk) error {
  8351. if m.AttachDiskHook != nil {
  8352. return m.AttachDiskHook(ctx, key, arg0, m)
  8353. }
  8354. return nil
  8355. }
  8356. // DetachDisk is a mock for the corresponding method.
  8357. func (m *MockInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 string) error {
  8358. if m.DetachDiskHook != nil {
  8359. return m.DetachDiskHook(ctx, key, arg0, m)
  8360. }
  8361. return nil
  8362. }
  8363. // GCEInstances is a simplifying adapter for the GCE Instances.
  8364. type GCEInstances struct {
  8365. s *Service
  8366. }
  8367. // Get the Instance named by key.
  8368. func (g *GCEInstances) Get(ctx context.Context, key *meta.Key) (*ga.Instance, error) {
  8369. klog.V(5).Infof("GCEInstances.Get(%v, %v): called", ctx, key)
  8370. if !key.Valid() {
  8371. klog.V(2).Infof("GCEInstances.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  8372. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  8373. }
  8374. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Instances")
  8375. rk := &RateLimitKey{
  8376. ProjectID: projectID,
  8377. Operation: "Get",
  8378. Version: meta.Version("ga"),
  8379. Service: "Instances",
  8380. }
  8381. klog.V(5).Infof("GCEInstances.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8382. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8383. klog.V(4).Infof("GCEInstances.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  8384. return nil, err
  8385. }
  8386. call := g.s.GA.Instances.Get(projectID, key.Zone, key.Name)
  8387. call.Context(ctx)
  8388. v, err := call.Do()
  8389. klog.V(4).Infof("GCEInstances.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  8390. return v, err
  8391. }
  8392. // List all Instance objects.
  8393. func (g *GCEInstances) List(ctx context.Context, zone string, fl *filter.F) ([]*ga.Instance, error) {
  8394. klog.V(5).Infof("GCEInstances.List(%v, %v, %v) called", ctx, zone, fl)
  8395. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Instances")
  8396. rk := &RateLimitKey{
  8397. ProjectID: projectID,
  8398. Operation: "List",
  8399. Version: meta.Version("ga"),
  8400. Service: "Instances",
  8401. }
  8402. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8403. return nil, err
  8404. }
  8405. klog.V(5).Infof("GCEInstances.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
  8406. call := g.s.GA.Instances.List(projectID, zone)
  8407. if fl != filter.None {
  8408. call.Filter(fl.String())
  8409. }
  8410. var all []*ga.Instance
  8411. f := func(l *ga.InstanceList) error {
  8412. klog.V(5).Infof("GCEInstances.List(%v, ..., %v): page %+v", ctx, fl, l)
  8413. all = append(all, l.Items...)
  8414. return nil
  8415. }
  8416. if err := call.Pages(ctx, f); err != nil {
  8417. klog.V(4).Infof("GCEInstances.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  8418. return nil, err
  8419. }
  8420. if klog.V(4) {
  8421. klog.V(4).Infof("GCEInstances.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  8422. } else if klog.V(5) {
  8423. var asStr []string
  8424. for _, o := range all {
  8425. asStr = append(asStr, fmt.Sprintf("%+v", o))
  8426. }
  8427. klog.V(5).Infof("GCEInstances.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  8428. }
  8429. return all, nil
  8430. }
  8431. // Insert Instance with key of value obj.
  8432. func (g *GCEInstances) Insert(ctx context.Context, key *meta.Key, obj *ga.Instance) error {
  8433. klog.V(5).Infof("GCEInstances.Insert(%v, %v, %+v): called", ctx, key, obj)
  8434. if !key.Valid() {
  8435. klog.V(2).Infof("GCEInstances.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8436. return fmt.Errorf("invalid GCE key (%+v)", key)
  8437. }
  8438. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Instances")
  8439. rk := &RateLimitKey{
  8440. ProjectID: projectID,
  8441. Operation: "Insert",
  8442. Version: meta.Version("ga"),
  8443. Service: "Instances",
  8444. }
  8445. klog.V(5).Infof("GCEInstances.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8446. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8447. klog.V(4).Infof("GCEInstances.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8448. return err
  8449. }
  8450. obj.Name = key.Name
  8451. call := g.s.GA.Instances.Insert(projectID, key.Zone, obj)
  8452. call.Context(ctx)
  8453. op, err := call.Do()
  8454. if err != nil {
  8455. klog.V(4).Infof("GCEInstances.Insert(%v, %v, ...) = %+v", ctx, key, err)
  8456. return err
  8457. }
  8458. err = g.s.WaitForCompletion(ctx, op)
  8459. klog.V(4).Infof("GCEInstances.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  8460. return err
  8461. }
  8462. // Delete the Instance referenced by key.
  8463. func (g *GCEInstances) Delete(ctx context.Context, key *meta.Key) error {
  8464. klog.V(5).Infof("GCEInstances.Delete(%v, %v): called", ctx, key)
  8465. if !key.Valid() {
  8466. klog.V(2).Infof("GCEInstances.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  8467. return fmt.Errorf("invalid GCE key (%+v)", key)
  8468. }
  8469. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Instances")
  8470. rk := &RateLimitKey{
  8471. ProjectID: projectID,
  8472. Operation: "Delete",
  8473. Version: meta.Version("ga"),
  8474. Service: "Instances",
  8475. }
  8476. klog.V(5).Infof("GCEInstances.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8477. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8478. klog.V(4).Infof("GCEInstances.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  8479. return err
  8480. }
  8481. call := g.s.GA.Instances.Delete(projectID, key.Zone, key.Name)
  8482. call.Context(ctx)
  8483. op, err := call.Do()
  8484. if err != nil {
  8485. klog.V(4).Infof("GCEInstances.Delete(%v, %v) = %v", ctx, key, err)
  8486. return err
  8487. }
  8488. err = g.s.WaitForCompletion(ctx, op)
  8489. klog.V(4).Infof("GCEInstances.Delete(%v, %v) = %v", ctx, key, err)
  8490. return err
  8491. }
  8492. // AttachDisk is a method on GCEInstances.
  8493. func (g *GCEInstances) AttachDisk(ctx context.Context, key *meta.Key, arg0 *ga.AttachedDisk) error {
  8494. klog.V(5).Infof("GCEInstances.AttachDisk(%v, %v, ...): called", ctx, key)
  8495. if !key.Valid() {
  8496. klog.V(2).Infof("GCEInstances.AttachDisk(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8497. return fmt.Errorf("invalid GCE key (%+v)", key)
  8498. }
  8499. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Instances")
  8500. rk := &RateLimitKey{
  8501. ProjectID: projectID,
  8502. Operation: "AttachDisk",
  8503. Version: meta.Version("ga"),
  8504. Service: "Instances",
  8505. }
  8506. klog.V(5).Infof("GCEInstances.AttachDisk(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8507. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8508. klog.V(4).Infof("GCEInstances.AttachDisk(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8509. return err
  8510. }
  8511. call := g.s.GA.Instances.AttachDisk(projectID, key.Zone, key.Name, arg0)
  8512. call.Context(ctx)
  8513. op, err := call.Do()
  8514. if err != nil {
  8515. klog.V(4).Infof("GCEInstances.AttachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8516. return err
  8517. }
  8518. err = g.s.WaitForCompletion(ctx, op)
  8519. klog.V(4).Infof("GCEInstances.AttachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8520. return err
  8521. }
  8522. // DetachDisk is a method on GCEInstances.
  8523. func (g *GCEInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 string) error {
  8524. klog.V(5).Infof("GCEInstances.DetachDisk(%v, %v, ...): called", ctx, key)
  8525. if !key.Valid() {
  8526. klog.V(2).Infof("GCEInstances.DetachDisk(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8527. return fmt.Errorf("invalid GCE key (%+v)", key)
  8528. }
  8529. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Instances")
  8530. rk := &RateLimitKey{
  8531. ProjectID: projectID,
  8532. Operation: "DetachDisk",
  8533. Version: meta.Version("ga"),
  8534. Service: "Instances",
  8535. }
  8536. klog.V(5).Infof("GCEInstances.DetachDisk(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8537. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8538. klog.V(4).Infof("GCEInstances.DetachDisk(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8539. return err
  8540. }
  8541. call := g.s.GA.Instances.DetachDisk(projectID, key.Zone, key.Name, arg0)
  8542. call.Context(ctx)
  8543. op, err := call.Do()
  8544. if err != nil {
  8545. klog.V(4).Infof("GCEInstances.DetachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8546. return err
  8547. }
  8548. err = g.s.WaitForCompletion(ctx, op)
  8549. klog.V(4).Infof("GCEInstances.DetachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8550. return err
  8551. }
  8552. // BetaInstances is an interface that allows for mocking of Instances.
  8553. type BetaInstances interface {
  8554. Get(ctx context.Context, key *meta.Key) (*beta.Instance, error)
  8555. List(ctx context.Context, zone string, fl *filter.F) ([]*beta.Instance, error)
  8556. Insert(ctx context.Context, key *meta.Key, obj *beta.Instance) error
  8557. Delete(ctx context.Context, key *meta.Key) error
  8558. AttachDisk(context.Context, *meta.Key, *beta.AttachedDisk) error
  8559. DetachDisk(context.Context, *meta.Key, string) error
  8560. UpdateNetworkInterface(context.Context, *meta.Key, string, *beta.NetworkInterface) error
  8561. }
  8562. // NewMockBetaInstances returns a new mock for Instances.
  8563. func NewMockBetaInstances(pr ProjectRouter, objs map[meta.Key]*MockInstancesObj) *MockBetaInstances {
  8564. mock := &MockBetaInstances{
  8565. ProjectRouter: pr,
  8566. Objects: objs,
  8567. GetError: map[meta.Key]error{},
  8568. InsertError: map[meta.Key]error{},
  8569. DeleteError: map[meta.Key]error{},
  8570. }
  8571. return mock
  8572. }
  8573. // MockBetaInstances is the mock for Instances.
  8574. type MockBetaInstances struct {
  8575. Lock sync.Mutex
  8576. ProjectRouter ProjectRouter
  8577. // Objects maintained by the mock.
  8578. Objects map[meta.Key]*MockInstancesObj
  8579. // If an entry exists for the given key and operation, then the error
  8580. // will be returned instead of the operation.
  8581. GetError map[meta.Key]error
  8582. ListError *error
  8583. InsertError map[meta.Key]error
  8584. DeleteError map[meta.Key]error
  8585. // xxxHook allow you to intercept the standard processing of the mock in
  8586. // order to add your own logic. Return (true, _, _) to prevent the normal
  8587. // execution flow of the mock. Return (false, nil, nil) to continue with
  8588. // normal mock behavior/ after the hook function executes.
  8589. GetHook func(ctx context.Context, key *meta.Key, m *MockBetaInstances) (bool, *beta.Instance, error)
  8590. ListHook func(ctx context.Context, zone string, fl *filter.F, m *MockBetaInstances) (bool, []*beta.Instance, error)
  8591. InsertHook func(ctx context.Context, key *meta.Key, obj *beta.Instance, m *MockBetaInstances) (bool, error)
  8592. DeleteHook func(ctx context.Context, key *meta.Key, m *MockBetaInstances) (bool, error)
  8593. AttachDiskHook func(context.Context, *meta.Key, *beta.AttachedDisk, *MockBetaInstances) error
  8594. DetachDiskHook func(context.Context, *meta.Key, string, *MockBetaInstances) error
  8595. UpdateNetworkInterfaceHook func(context.Context, *meta.Key, string, *beta.NetworkInterface, *MockBetaInstances) error
  8596. // X is extra state that can be used as part of the mock. Generated code
  8597. // will not use this field.
  8598. X interface{}
  8599. }
  8600. // Get returns the object from the mock.
  8601. func (m *MockBetaInstances) Get(ctx context.Context, key *meta.Key) (*beta.Instance, error) {
  8602. if m.GetHook != nil {
  8603. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  8604. klog.V(5).Infof("MockBetaInstances.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  8605. return obj, err
  8606. }
  8607. }
  8608. if !key.Valid() {
  8609. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  8610. }
  8611. m.Lock.Lock()
  8612. defer m.Lock.Unlock()
  8613. if err, ok := m.GetError[*key]; ok {
  8614. klog.V(5).Infof("MockBetaInstances.Get(%v, %s) = nil, %v", ctx, key, err)
  8615. return nil, err
  8616. }
  8617. if obj, ok := m.Objects[*key]; ok {
  8618. typedObj := obj.ToBeta()
  8619. klog.V(5).Infof("MockBetaInstances.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  8620. return typedObj, nil
  8621. }
  8622. err := &googleapi.Error{
  8623. Code: http.StatusNotFound,
  8624. Message: fmt.Sprintf("MockBetaInstances %v not found", key),
  8625. }
  8626. klog.V(5).Infof("MockBetaInstances.Get(%v, %s) = nil, %v", ctx, key, err)
  8627. return nil, err
  8628. }
  8629. // List all of the objects in the mock in the given zone.
  8630. func (m *MockBetaInstances) List(ctx context.Context, zone string, fl *filter.F) ([]*beta.Instance, error) {
  8631. if m.ListHook != nil {
  8632. if intercept, objs, err := m.ListHook(ctx, zone, fl, m); intercept {
  8633. klog.V(5).Infof("MockBetaInstances.List(%v, %q, %v) = [%v items], %v", ctx, zone, fl, len(objs), err)
  8634. return objs, err
  8635. }
  8636. }
  8637. m.Lock.Lock()
  8638. defer m.Lock.Unlock()
  8639. if m.ListError != nil {
  8640. err := *m.ListError
  8641. klog.V(5).Infof("MockBetaInstances.List(%v, %q, %v) = nil, %v", ctx, zone, fl, err)
  8642. return nil, *m.ListError
  8643. }
  8644. var objs []*beta.Instance
  8645. for key, obj := range m.Objects {
  8646. if key.Zone != zone {
  8647. continue
  8648. }
  8649. if !fl.Match(obj.ToBeta()) {
  8650. continue
  8651. }
  8652. objs = append(objs, obj.ToBeta())
  8653. }
  8654. klog.V(5).Infof("MockBetaInstances.List(%v, %q, %v) = [%v items], nil", ctx, zone, fl, len(objs))
  8655. return objs, nil
  8656. }
  8657. // Insert is a mock for inserting/creating a new object.
  8658. func (m *MockBetaInstances) Insert(ctx context.Context, key *meta.Key, obj *beta.Instance) error {
  8659. if m.InsertHook != nil {
  8660. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  8661. klog.V(5).Infof("MockBetaInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  8662. return err
  8663. }
  8664. }
  8665. if !key.Valid() {
  8666. return fmt.Errorf("invalid GCE key (%+v)", key)
  8667. }
  8668. m.Lock.Lock()
  8669. defer m.Lock.Unlock()
  8670. if err, ok := m.InsertError[*key]; ok {
  8671. klog.V(5).Infof("MockBetaInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  8672. return err
  8673. }
  8674. if _, ok := m.Objects[*key]; ok {
  8675. err := &googleapi.Error{
  8676. Code: http.StatusConflict,
  8677. Message: fmt.Sprintf("MockBetaInstances %v exists", key),
  8678. }
  8679. klog.V(5).Infof("MockBetaInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  8680. return err
  8681. }
  8682. obj.Name = key.Name
  8683. projectID := m.ProjectRouter.ProjectID(ctx, "beta", "instances")
  8684. obj.SelfLink = SelfLink(meta.VersionBeta, projectID, "instances", key)
  8685. m.Objects[*key] = &MockInstancesObj{obj}
  8686. klog.V(5).Infof("MockBetaInstances.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  8687. return nil
  8688. }
  8689. // Delete is a mock for deleting the object.
  8690. func (m *MockBetaInstances) Delete(ctx context.Context, key *meta.Key) error {
  8691. if m.DeleteHook != nil {
  8692. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  8693. klog.V(5).Infof("MockBetaInstances.Delete(%v, %v) = %v", ctx, key, err)
  8694. return err
  8695. }
  8696. }
  8697. if !key.Valid() {
  8698. return fmt.Errorf("invalid GCE key (%+v)", key)
  8699. }
  8700. m.Lock.Lock()
  8701. defer m.Lock.Unlock()
  8702. if err, ok := m.DeleteError[*key]; ok {
  8703. klog.V(5).Infof("MockBetaInstances.Delete(%v, %v) = %v", ctx, key, err)
  8704. return err
  8705. }
  8706. if _, ok := m.Objects[*key]; !ok {
  8707. err := &googleapi.Error{
  8708. Code: http.StatusNotFound,
  8709. Message: fmt.Sprintf("MockBetaInstances %v not found", key),
  8710. }
  8711. klog.V(5).Infof("MockBetaInstances.Delete(%v, %v) = %v", ctx, key, err)
  8712. return err
  8713. }
  8714. delete(m.Objects, *key)
  8715. klog.V(5).Infof("MockBetaInstances.Delete(%v, %v) = nil", ctx, key)
  8716. return nil
  8717. }
  8718. // Obj wraps the object for use in the mock.
  8719. func (m *MockBetaInstances) Obj(o *beta.Instance) *MockInstancesObj {
  8720. return &MockInstancesObj{o}
  8721. }
  8722. // AttachDisk is a mock for the corresponding method.
  8723. func (m *MockBetaInstances) AttachDisk(ctx context.Context, key *meta.Key, arg0 *beta.AttachedDisk) error {
  8724. if m.AttachDiskHook != nil {
  8725. return m.AttachDiskHook(ctx, key, arg0, m)
  8726. }
  8727. return nil
  8728. }
  8729. // DetachDisk is a mock for the corresponding method.
  8730. func (m *MockBetaInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 string) error {
  8731. if m.DetachDiskHook != nil {
  8732. return m.DetachDiskHook(ctx, key, arg0, m)
  8733. }
  8734. return nil
  8735. }
  8736. // UpdateNetworkInterface is a mock for the corresponding method.
  8737. func (m *MockBetaInstances) UpdateNetworkInterface(ctx context.Context, key *meta.Key, arg0 string, arg1 *beta.NetworkInterface) error {
  8738. if m.UpdateNetworkInterfaceHook != nil {
  8739. return m.UpdateNetworkInterfaceHook(ctx, key, arg0, arg1, m)
  8740. }
  8741. return nil
  8742. }
  8743. // GCEBetaInstances is a simplifying adapter for the GCE Instances.
  8744. type GCEBetaInstances struct {
  8745. s *Service
  8746. }
  8747. // Get the Instance named by key.
  8748. func (g *GCEBetaInstances) Get(ctx context.Context, key *meta.Key) (*beta.Instance, error) {
  8749. klog.V(5).Infof("GCEBetaInstances.Get(%v, %v): called", ctx, key)
  8750. if !key.Valid() {
  8751. klog.V(2).Infof("GCEBetaInstances.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  8752. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  8753. }
  8754. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances")
  8755. rk := &RateLimitKey{
  8756. ProjectID: projectID,
  8757. Operation: "Get",
  8758. Version: meta.Version("beta"),
  8759. Service: "Instances",
  8760. }
  8761. klog.V(5).Infof("GCEBetaInstances.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8762. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8763. klog.V(4).Infof("GCEBetaInstances.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  8764. return nil, err
  8765. }
  8766. call := g.s.Beta.Instances.Get(projectID, key.Zone, key.Name)
  8767. call.Context(ctx)
  8768. v, err := call.Do()
  8769. klog.V(4).Infof("GCEBetaInstances.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  8770. return v, err
  8771. }
  8772. // List all Instance objects.
  8773. func (g *GCEBetaInstances) List(ctx context.Context, zone string, fl *filter.F) ([]*beta.Instance, error) {
  8774. klog.V(5).Infof("GCEBetaInstances.List(%v, %v, %v) called", ctx, zone, fl)
  8775. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances")
  8776. rk := &RateLimitKey{
  8777. ProjectID: projectID,
  8778. Operation: "List",
  8779. Version: meta.Version("beta"),
  8780. Service: "Instances",
  8781. }
  8782. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8783. return nil, err
  8784. }
  8785. klog.V(5).Infof("GCEBetaInstances.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
  8786. call := g.s.Beta.Instances.List(projectID, zone)
  8787. if fl != filter.None {
  8788. call.Filter(fl.String())
  8789. }
  8790. var all []*beta.Instance
  8791. f := func(l *beta.InstanceList) error {
  8792. klog.V(5).Infof("GCEBetaInstances.List(%v, ..., %v): page %+v", ctx, fl, l)
  8793. all = append(all, l.Items...)
  8794. return nil
  8795. }
  8796. if err := call.Pages(ctx, f); err != nil {
  8797. klog.V(4).Infof("GCEBetaInstances.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  8798. return nil, err
  8799. }
  8800. if klog.V(4) {
  8801. klog.V(4).Infof("GCEBetaInstances.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  8802. } else if klog.V(5) {
  8803. var asStr []string
  8804. for _, o := range all {
  8805. asStr = append(asStr, fmt.Sprintf("%+v", o))
  8806. }
  8807. klog.V(5).Infof("GCEBetaInstances.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  8808. }
  8809. return all, nil
  8810. }
  8811. // Insert Instance with key of value obj.
  8812. func (g *GCEBetaInstances) Insert(ctx context.Context, key *meta.Key, obj *beta.Instance) error {
  8813. klog.V(5).Infof("GCEBetaInstances.Insert(%v, %v, %+v): called", ctx, key, obj)
  8814. if !key.Valid() {
  8815. klog.V(2).Infof("GCEBetaInstances.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8816. return fmt.Errorf("invalid GCE key (%+v)", key)
  8817. }
  8818. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances")
  8819. rk := &RateLimitKey{
  8820. ProjectID: projectID,
  8821. Operation: "Insert",
  8822. Version: meta.Version("beta"),
  8823. Service: "Instances",
  8824. }
  8825. klog.V(5).Infof("GCEBetaInstances.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8826. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8827. klog.V(4).Infof("GCEBetaInstances.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8828. return err
  8829. }
  8830. obj.Name = key.Name
  8831. call := g.s.Beta.Instances.Insert(projectID, key.Zone, obj)
  8832. call.Context(ctx)
  8833. op, err := call.Do()
  8834. if err != nil {
  8835. klog.V(4).Infof("GCEBetaInstances.Insert(%v, %v, ...) = %+v", ctx, key, err)
  8836. return err
  8837. }
  8838. err = g.s.WaitForCompletion(ctx, op)
  8839. klog.V(4).Infof("GCEBetaInstances.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  8840. return err
  8841. }
  8842. // Delete the Instance referenced by key.
  8843. func (g *GCEBetaInstances) Delete(ctx context.Context, key *meta.Key) error {
  8844. klog.V(5).Infof("GCEBetaInstances.Delete(%v, %v): called", ctx, key)
  8845. if !key.Valid() {
  8846. klog.V(2).Infof("GCEBetaInstances.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  8847. return fmt.Errorf("invalid GCE key (%+v)", key)
  8848. }
  8849. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances")
  8850. rk := &RateLimitKey{
  8851. ProjectID: projectID,
  8852. Operation: "Delete",
  8853. Version: meta.Version("beta"),
  8854. Service: "Instances",
  8855. }
  8856. klog.V(5).Infof("GCEBetaInstances.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8857. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8858. klog.V(4).Infof("GCEBetaInstances.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  8859. return err
  8860. }
  8861. call := g.s.Beta.Instances.Delete(projectID, key.Zone, key.Name)
  8862. call.Context(ctx)
  8863. op, err := call.Do()
  8864. if err != nil {
  8865. klog.V(4).Infof("GCEBetaInstances.Delete(%v, %v) = %v", ctx, key, err)
  8866. return err
  8867. }
  8868. err = g.s.WaitForCompletion(ctx, op)
  8869. klog.V(4).Infof("GCEBetaInstances.Delete(%v, %v) = %v", ctx, key, err)
  8870. return err
  8871. }
  8872. // AttachDisk is a method on GCEBetaInstances.
  8873. func (g *GCEBetaInstances) AttachDisk(ctx context.Context, key *meta.Key, arg0 *beta.AttachedDisk) error {
  8874. klog.V(5).Infof("GCEBetaInstances.AttachDisk(%v, %v, ...): called", ctx, key)
  8875. if !key.Valid() {
  8876. klog.V(2).Infof("GCEBetaInstances.AttachDisk(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8877. return fmt.Errorf("invalid GCE key (%+v)", key)
  8878. }
  8879. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances")
  8880. rk := &RateLimitKey{
  8881. ProjectID: projectID,
  8882. Operation: "AttachDisk",
  8883. Version: meta.Version("beta"),
  8884. Service: "Instances",
  8885. }
  8886. klog.V(5).Infof("GCEBetaInstances.AttachDisk(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8887. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8888. klog.V(4).Infof("GCEBetaInstances.AttachDisk(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8889. return err
  8890. }
  8891. call := g.s.Beta.Instances.AttachDisk(projectID, key.Zone, key.Name, arg0)
  8892. call.Context(ctx)
  8893. op, err := call.Do()
  8894. if err != nil {
  8895. klog.V(4).Infof("GCEBetaInstances.AttachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8896. return err
  8897. }
  8898. err = g.s.WaitForCompletion(ctx, op)
  8899. klog.V(4).Infof("GCEBetaInstances.AttachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8900. return err
  8901. }
  8902. // DetachDisk is a method on GCEBetaInstances.
  8903. func (g *GCEBetaInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 string) error {
  8904. klog.V(5).Infof("GCEBetaInstances.DetachDisk(%v, %v, ...): called", ctx, key)
  8905. if !key.Valid() {
  8906. klog.V(2).Infof("GCEBetaInstances.DetachDisk(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8907. return fmt.Errorf("invalid GCE key (%+v)", key)
  8908. }
  8909. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances")
  8910. rk := &RateLimitKey{
  8911. ProjectID: projectID,
  8912. Operation: "DetachDisk",
  8913. Version: meta.Version("beta"),
  8914. Service: "Instances",
  8915. }
  8916. klog.V(5).Infof("GCEBetaInstances.DetachDisk(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8917. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8918. klog.V(4).Infof("GCEBetaInstances.DetachDisk(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8919. return err
  8920. }
  8921. call := g.s.Beta.Instances.DetachDisk(projectID, key.Zone, key.Name, arg0)
  8922. call.Context(ctx)
  8923. op, err := call.Do()
  8924. if err != nil {
  8925. klog.V(4).Infof("GCEBetaInstances.DetachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8926. return err
  8927. }
  8928. err = g.s.WaitForCompletion(ctx, op)
  8929. klog.V(4).Infof("GCEBetaInstances.DetachDisk(%v, %v, ...) = %+v", ctx, key, err)
  8930. return err
  8931. }
  8932. // UpdateNetworkInterface is a method on GCEBetaInstances.
  8933. func (g *GCEBetaInstances) UpdateNetworkInterface(ctx context.Context, key *meta.Key, arg0 string, arg1 *beta.NetworkInterface) error {
  8934. klog.V(5).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): called", ctx, key)
  8935. if !key.Valid() {
  8936. klog.V(2).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  8937. return fmt.Errorf("invalid GCE key (%+v)", key)
  8938. }
  8939. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances")
  8940. rk := &RateLimitKey{
  8941. ProjectID: projectID,
  8942. Operation: "UpdateNetworkInterface",
  8943. Version: meta.Version("beta"),
  8944. Service: "Instances",
  8945. }
  8946. klog.V(5).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  8947. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  8948. klog.V(4).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  8949. return err
  8950. }
  8951. call := g.s.Beta.Instances.UpdateNetworkInterface(projectID, key.Zone, key.Name, arg0, arg1)
  8952. call.Context(ctx)
  8953. op, err := call.Do()
  8954. if err != nil {
  8955. klog.V(4).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...) = %+v", ctx, key, err)
  8956. return err
  8957. }
  8958. err = g.s.WaitForCompletion(ctx, op)
  8959. klog.V(4).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...) = %+v", ctx, key, err)
  8960. return err
  8961. }
  8962. // AlphaInstances is an interface that allows for mocking of Instances.
  8963. type AlphaInstances interface {
  8964. Get(ctx context.Context, key *meta.Key) (*alpha.Instance, error)
  8965. List(ctx context.Context, zone string, fl *filter.F) ([]*alpha.Instance, error)
  8966. Insert(ctx context.Context, key *meta.Key, obj *alpha.Instance) error
  8967. Delete(ctx context.Context, key *meta.Key) error
  8968. AttachDisk(context.Context, *meta.Key, *alpha.AttachedDisk) error
  8969. DetachDisk(context.Context, *meta.Key, string) error
  8970. UpdateNetworkInterface(context.Context, *meta.Key, string, *alpha.NetworkInterface) error
  8971. }
  8972. // NewMockAlphaInstances returns a new mock for Instances.
  8973. func NewMockAlphaInstances(pr ProjectRouter, objs map[meta.Key]*MockInstancesObj) *MockAlphaInstances {
  8974. mock := &MockAlphaInstances{
  8975. ProjectRouter: pr,
  8976. Objects: objs,
  8977. GetError: map[meta.Key]error{},
  8978. InsertError: map[meta.Key]error{},
  8979. DeleteError: map[meta.Key]error{},
  8980. }
  8981. return mock
  8982. }
  8983. // MockAlphaInstances is the mock for Instances.
  8984. type MockAlphaInstances struct {
  8985. Lock sync.Mutex
  8986. ProjectRouter ProjectRouter
  8987. // Objects maintained by the mock.
  8988. Objects map[meta.Key]*MockInstancesObj
  8989. // If an entry exists for the given key and operation, then the error
  8990. // will be returned instead of the operation.
  8991. GetError map[meta.Key]error
  8992. ListError *error
  8993. InsertError map[meta.Key]error
  8994. DeleteError map[meta.Key]error
  8995. // xxxHook allow you to intercept the standard processing of the mock in
  8996. // order to add your own logic. Return (true, _, _) to prevent the normal
  8997. // execution flow of the mock. Return (false, nil, nil) to continue with
  8998. // normal mock behavior/ after the hook function executes.
  8999. GetHook func(ctx context.Context, key *meta.Key, m *MockAlphaInstances) (bool, *alpha.Instance, error)
  9000. ListHook func(ctx context.Context, zone string, fl *filter.F, m *MockAlphaInstances) (bool, []*alpha.Instance, error)
  9001. InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.Instance, m *MockAlphaInstances) (bool, error)
  9002. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaInstances) (bool, error)
  9003. AttachDiskHook func(context.Context, *meta.Key, *alpha.AttachedDisk, *MockAlphaInstances) error
  9004. DetachDiskHook func(context.Context, *meta.Key, string, *MockAlphaInstances) error
  9005. UpdateNetworkInterfaceHook func(context.Context, *meta.Key, string, *alpha.NetworkInterface, *MockAlphaInstances) error
  9006. // X is extra state that can be used as part of the mock. Generated code
  9007. // will not use this field.
  9008. X interface{}
  9009. }
  9010. // Get returns the object from the mock.
  9011. func (m *MockAlphaInstances) Get(ctx context.Context, key *meta.Key) (*alpha.Instance, error) {
  9012. if m.GetHook != nil {
  9013. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  9014. klog.V(5).Infof("MockAlphaInstances.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  9015. return obj, err
  9016. }
  9017. }
  9018. if !key.Valid() {
  9019. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  9020. }
  9021. m.Lock.Lock()
  9022. defer m.Lock.Unlock()
  9023. if err, ok := m.GetError[*key]; ok {
  9024. klog.V(5).Infof("MockAlphaInstances.Get(%v, %s) = nil, %v", ctx, key, err)
  9025. return nil, err
  9026. }
  9027. if obj, ok := m.Objects[*key]; ok {
  9028. typedObj := obj.ToAlpha()
  9029. klog.V(5).Infof("MockAlphaInstances.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  9030. return typedObj, nil
  9031. }
  9032. err := &googleapi.Error{
  9033. Code: http.StatusNotFound,
  9034. Message: fmt.Sprintf("MockAlphaInstances %v not found", key),
  9035. }
  9036. klog.V(5).Infof("MockAlphaInstances.Get(%v, %s) = nil, %v", ctx, key, err)
  9037. return nil, err
  9038. }
  9039. // List all of the objects in the mock in the given zone.
  9040. func (m *MockAlphaInstances) List(ctx context.Context, zone string, fl *filter.F) ([]*alpha.Instance, error) {
  9041. if m.ListHook != nil {
  9042. if intercept, objs, err := m.ListHook(ctx, zone, fl, m); intercept {
  9043. klog.V(5).Infof("MockAlphaInstances.List(%v, %q, %v) = [%v items], %v", ctx, zone, fl, len(objs), err)
  9044. return objs, err
  9045. }
  9046. }
  9047. m.Lock.Lock()
  9048. defer m.Lock.Unlock()
  9049. if m.ListError != nil {
  9050. err := *m.ListError
  9051. klog.V(5).Infof("MockAlphaInstances.List(%v, %q, %v) = nil, %v", ctx, zone, fl, err)
  9052. return nil, *m.ListError
  9053. }
  9054. var objs []*alpha.Instance
  9055. for key, obj := range m.Objects {
  9056. if key.Zone != zone {
  9057. continue
  9058. }
  9059. if !fl.Match(obj.ToAlpha()) {
  9060. continue
  9061. }
  9062. objs = append(objs, obj.ToAlpha())
  9063. }
  9064. klog.V(5).Infof("MockAlphaInstances.List(%v, %q, %v) = [%v items], nil", ctx, zone, fl, len(objs))
  9065. return objs, nil
  9066. }
  9067. // Insert is a mock for inserting/creating a new object.
  9068. func (m *MockAlphaInstances) Insert(ctx context.Context, key *meta.Key, obj *alpha.Instance) error {
  9069. if m.InsertHook != nil {
  9070. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  9071. klog.V(5).Infof("MockAlphaInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9072. return err
  9073. }
  9074. }
  9075. if !key.Valid() {
  9076. return fmt.Errorf("invalid GCE key (%+v)", key)
  9077. }
  9078. m.Lock.Lock()
  9079. defer m.Lock.Unlock()
  9080. if err, ok := m.InsertError[*key]; ok {
  9081. klog.V(5).Infof("MockAlphaInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9082. return err
  9083. }
  9084. if _, ok := m.Objects[*key]; ok {
  9085. err := &googleapi.Error{
  9086. Code: http.StatusConflict,
  9087. Message: fmt.Sprintf("MockAlphaInstances %v exists", key),
  9088. }
  9089. klog.V(5).Infof("MockAlphaInstances.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9090. return err
  9091. }
  9092. obj.Name = key.Name
  9093. projectID := m.ProjectRouter.ProjectID(ctx, "alpha", "instances")
  9094. obj.SelfLink = SelfLink(meta.VersionAlpha, projectID, "instances", key)
  9095. m.Objects[*key] = &MockInstancesObj{obj}
  9096. klog.V(5).Infof("MockAlphaInstances.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  9097. return nil
  9098. }
  9099. // Delete is a mock for deleting the object.
  9100. func (m *MockAlphaInstances) Delete(ctx context.Context, key *meta.Key) error {
  9101. if m.DeleteHook != nil {
  9102. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  9103. klog.V(5).Infof("MockAlphaInstances.Delete(%v, %v) = %v", ctx, key, err)
  9104. return err
  9105. }
  9106. }
  9107. if !key.Valid() {
  9108. return fmt.Errorf("invalid GCE key (%+v)", key)
  9109. }
  9110. m.Lock.Lock()
  9111. defer m.Lock.Unlock()
  9112. if err, ok := m.DeleteError[*key]; ok {
  9113. klog.V(5).Infof("MockAlphaInstances.Delete(%v, %v) = %v", ctx, key, err)
  9114. return err
  9115. }
  9116. if _, ok := m.Objects[*key]; !ok {
  9117. err := &googleapi.Error{
  9118. Code: http.StatusNotFound,
  9119. Message: fmt.Sprintf("MockAlphaInstances %v not found", key),
  9120. }
  9121. klog.V(5).Infof("MockAlphaInstances.Delete(%v, %v) = %v", ctx, key, err)
  9122. return err
  9123. }
  9124. delete(m.Objects, *key)
  9125. klog.V(5).Infof("MockAlphaInstances.Delete(%v, %v) = nil", ctx, key)
  9126. return nil
  9127. }
  9128. // Obj wraps the object for use in the mock.
  9129. func (m *MockAlphaInstances) Obj(o *alpha.Instance) *MockInstancesObj {
  9130. return &MockInstancesObj{o}
  9131. }
  9132. // AttachDisk is a mock for the corresponding method.
  9133. func (m *MockAlphaInstances) AttachDisk(ctx context.Context, key *meta.Key, arg0 *alpha.AttachedDisk) error {
  9134. if m.AttachDiskHook != nil {
  9135. return m.AttachDiskHook(ctx, key, arg0, m)
  9136. }
  9137. return nil
  9138. }
  9139. // DetachDisk is a mock for the corresponding method.
  9140. func (m *MockAlphaInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 string) error {
  9141. if m.DetachDiskHook != nil {
  9142. return m.DetachDiskHook(ctx, key, arg0, m)
  9143. }
  9144. return nil
  9145. }
  9146. // UpdateNetworkInterface is a mock for the corresponding method.
  9147. func (m *MockAlphaInstances) UpdateNetworkInterface(ctx context.Context, key *meta.Key, arg0 string, arg1 *alpha.NetworkInterface) error {
  9148. if m.UpdateNetworkInterfaceHook != nil {
  9149. return m.UpdateNetworkInterfaceHook(ctx, key, arg0, arg1, m)
  9150. }
  9151. return nil
  9152. }
  9153. // GCEAlphaInstances is a simplifying adapter for the GCE Instances.
  9154. type GCEAlphaInstances struct {
  9155. s *Service
  9156. }
  9157. // Get the Instance named by key.
  9158. func (g *GCEAlphaInstances) Get(ctx context.Context, key *meta.Key) (*alpha.Instance, error) {
  9159. klog.V(5).Infof("GCEAlphaInstances.Get(%v, %v): called", ctx, key)
  9160. if !key.Valid() {
  9161. klog.V(2).Infof("GCEAlphaInstances.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  9162. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  9163. }
  9164. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Instances")
  9165. rk := &RateLimitKey{
  9166. ProjectID: projectID,
  9167. Operation: "Get",
  9168. Version: meta.Version("alpha"),
  9169. Service: "Instances",
  9170. }
  9171. klog.V(5).Infof("GCEAlphaInstances.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9172. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9173. klog.V(4).Infof("GCEAlphaInstances.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  9174. return nil, err
  9175. }
  9176. call := g.s.Alpha.Instances.Get(projectID, key.Zone, key.Name)
  9177. call.Context(ctx)
  9178. v, err := call.Do()
  9179. klog.V(4).Infof("GCEAlphaInstances.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  9180. return v, err
  9181. }
  9182. // List all Instance objects.
  9183. func (g *GCEAlphaInstances) List(ctx context.Context, zone string, fl *filter.F) ([]*alpha.Instance, error) {
  9184. klog.V(5).Infof("GCEAlphaInstances.List(%v, %v, %v) called", ctx, zone, fl)
  9185. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Instances")
  9186. rk := &RateLimitKey{
  9187. ProjectID: projectID,
  9188. Operation: "List",
  9189. Version: meta.Version("alpha"),
  9190. Service: "Instances",
  9191. }
  9192. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9193. return nil, err
  9194. }
  9195. klog.V(5).Infof("GCEAlphaInstances.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
  9196. call := g.s.Alpha.Instances.List(projectID, zone)
  9197. if fl != filter.None {
  9198. call.Filter(fl.String())
  9199. }
  9200. var all []*alpha.Instance
  9201. f := func(l *alpha.InstanceList) error {
  9202. klog.V(5).Infof("GCEAlphaInstances.List(%v, ..., %v): page %+v", ctx, fl, l)
  9203. all = append(all, l.Items...)
  9204. return nil
  9205. }
  9206. if err := call.Pages(ctx, f); err != nil {
  9207. klog.V(4).Infof("GCEAlphaInstances.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  9208. return nil, err
  9209. }
  9210. if klog.V(4) {
  9211. klog.V(4).Infof("GCEAlphaInstances.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  9212. } else if klog.V(5) {
  9213. var asStr []string
  9214. for _, o := range all {
  9215. asStr = append(asStr, fmt.Sprintf("%+v", o))
  9216. }
  9217. klog.V(5).Infof("GCEAlphaInstances.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  9218. }
  9219. return all, nil
  9220. }
  9221. // Insert Instance with key of value obj.
  9222. func (g *GCEAlphaInstances) Insert(ctx context.Context, key *meta.Key, obj *alpha.Instance) error {
  9223. klog.V(5).Infof("GCEAlphaInstances.Insert(%v, %v, %+v): called", ctx, key, obj)
  9224. if !key.Valid() {
  9225. klog.V(2).Infof("GCEAlphaInstances.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9226. return fmt.Errorf("invalid GCE key (%+v)", key)
  9227. }
  9228. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Instances")
  9229. rk := &RateLimitKey{
  9230. ProjectID: projectID,
  9231. Operation: "Insert",
  9232. Version: meta.Version("alpha"),
  9233. Service: "Instances",
  9234. }
  9235. klog.V(5).Infof("GCEAlphaInstances.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9236. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9237. klog.V(4).Infof("GCEAlphaInstances.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9238. return err
  9239. }
  9240. obj.Name = key.Name
  9241. call := g.s.Alpha.Instances.Insert(projectID, key.Zone, obj)
  9242. call.Context(ctx)
  9243. op, err := call.Do()
  9244. if err != nil {
  9245. klog.V(4).Infof("GCEAlphaInstances.Insert(%v, %v, ...) = %+v", ctx, key, err)
  9246. return err
  9247. }
  9248. err = g.s.WaitForCompletion(ctx, op)
  9249. klog.V(4).Infof("GCEAlphaInstances.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  9250. return err
  9251. }
  9252. // Delete the Instance referenced by key.
  9253. func (g *GCEAlphaInstances) Delete(ctx context.Context, key *meta.Key) error {
  9254. klog.V(5).Infof("GCEAlphaInstances.Delete(%v, %v): called", ctx, key)
  9255. if !key.Valid() {
  9256. klog.V(2).Infof("GCEAlphaInstances.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  9257. return fmt.Errorf("invalid GCE key (%+v)", key)
  9258. }
  9259. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Instances")
  9260. rk := &RateLimitKey{
  9261. ProjectID: projectID,
  9262. Operation: "Delete",
  9263. Version: meta.Version("alpha"),
  9264. Service: "Instances",
  9265. }
  9266. klog.V(5).Infof("GCEAlphaInstances.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9267. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9268. klog.V(4).Infof("GCEAlphaInstances.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  9269. return err
  9270. }
  9271. call := g.s.Alpha.Instances.Delete(projectID, key.Zone, key.Name)
  9272. call.Context(ctx)
  9273. op, err := call.Do()
  9274. if err != nil {
  9275. klog.V(4).Infof("GCEAlphaInstances.Delete(%v, %v) = %v", ctx, key, err)
  9276. return err
  9277. }
  9278. err = g.s.WaitForCompletion(ctx, op)
  9279. klog.V(4).Infof("GCEAlphaInstances.Delete(%v, %v) = %v", ctx, key, err)
  9280. return err
  9281. }
  9282. // AttachDisk is a method on GCEAlphaInstances.
  9283. func (g *GCEAlphaInstances) AttachDisk(ctx context.Context, key *meta.Key, arg0 *alpha.AttachedDisk) error {
  9284. klog.V(5).Infof("GCEAlphaInstances.AttachDisk(%v, %v, ...): called", ctx, key)
  9285. if !key.Valid() {
  9286. klog.V(2).Infof("GCEAlphaInstances.AttachDisk(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9287. return fmt.Errorf("invalid GCE key (%+v)", key)
  9288. }
  9289. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Instances")
  9290. rk := &RateLimitKey{
  9291. ProjectID: projectID,
  9292. Operation: "AttachDisk",
  9293. Version: meta.Version("alpha"),
  9294. Service: "Instances",
  9295. }
  9296. klog.V(5).Infof("GCEAlphaInstances.AttachDisk(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9297. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9298. klog.V(4).Infof("GCEAlphaInstances.AttachDisk(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9299. return err
  9300. }
  9301. call := g.s.Alpha.Instances.AttachDisk(projectID, key.Zone, key.Name, arg0)
  9302. call.Context(ctx)
  9303. op, err := call.Do()
  9304. if err != nil {
  9305. klog.V(4).Infof("GCEAlphaInstances.AttachDisk(%v, %v, ...) = %+v", ctx, key, err)
  9306. return err
  9307. }
  9308. err = g.s.WaitForCompletion(ctx, op)
  9309. klog.V(4).Infof("GCEAlphaInstances.AttachDisk(%v, %v, ...) = %+v", ctx, key, err)
  9310. return err
  9311. }
  9312. // DetachDisk is a method on GCEAlphaInstances.
  9313. func (g *GCEAlphaInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 string) error {
  9314. klog.V(5).Infof("GCEAlphaInstances.DetachDisk(%v, %v, ...): called", ctx, key)
  9315. if !key.Valid() {
  9316. klog.V(2).Infof("GCEAlphaInstances.DetachDisk(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9317. return fmt.Errorf("invalid GCE key (%+v)", key)
  9318. }
  9319. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Instances")
  9320. rk := &RateLimitKey{
  9321. ProjectID: projectID,
  9322. Operation: "DetachDisk",
  9323. Version: meta.Version("alpha"),
  9324. Service: "Instances",
  9325. }
  9326. klog.V(5).Infof("GCEAlphaInstances.DetachDisk(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9327. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9328. klog.V(4).Infof("GCEAlphaInstances.DetachDisk(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9329. return err
  9330. }
  9331. call := g.s.Alpha.Instances.DetachDisk(projectID, key.Zone, key.Name, arg0)
  9332. call.Context(ctx)
  9333. op, err := call.Do()
  9334. if err != nil {
  9335. klog.V(4).Infof("GCEAlphaInstances.DetachDisk(%v, %v, ...) = %+v", ctx, key, err)
  9336. return err
  9337. }
  9338. err = g.s.WaitForCompletion(ctx, op)
  9339. klog.V(4).Infof("GCEAlphaInstances.DetachDisk(%v, %v, ...) = %+v", ctx, key, err)
  9340. return err
  9341. }
  9342. // UpdateNetworkInterface is a method on GCEAlphaInstances.
  9343. func (g *GCEAlphaInstances) UpdateNetworkInterface(ctx context.Context, key *meta.Key, arg0 string, arg1 *alpha.NetworkInterface) error {
  9344. klog.V(5).Infof("GCEAlphaInstances.UpdateNetworkInterface(%v, %v, ...): called", ctx, key)
  9345. if !key.Valid() {
  9346. klog.V(2).Infof("GCEAlphaInstances.UpdateNetworkInterface(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9347. return fmt.Errorf("invalid GCE key (%+v)", key)
  9348. }
  9349. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "Instances")
  9350. rk := &RateLimitKey{
  9351. ProjectID: projectID,
  9352. Operation: "UpdateNetworkInterface",
  9353. Version: meta.Version("alpha"),
  9354. Service: "Instances",
  9355. }
  9356. klog.V(5).Infof("GCEAlphaInstances.UpdateNetworkInterface(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9357. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9358. klog.V(4).Infof("GCEAlphaInstances.UpdateNetworkInterface(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9359. return err
  9360. }
  9361. call := g.s.Alpha.Instances.UpdateNetworkInterface(projectID, key.Zone, key.Name, arg0, arg1)
  9362. call.Context(ctx)
  9363. op, err := call.Do()
  9364. if err != nil {
  9365. klog.V(4).Infof("GCEAlphaInstances.UpdateNetworkInterface(%v, %v, ...) = %+v", ctx, key, err)
  9366. return err
  9367. }
  9368. err = g.s.WaitForCompletion(ctx, op)
  9369. klog.V(4).Infof("GCEAlphaInstances.UpdateNetworkInterface(%v, %v, ...) = %+v", ctx, key, err)
  9370. return err
  9371. }
  9372. // AlphaNetworkEndpointGroups is an interface that allows for mocking of NetworkEndpointGroups.
  9373. type AlphaNetworkEndpointGroups interface {
  9374. Get(ctx context.Context, key *meta.Key) (*alpha.NetworkEndpointGroup, error)
  9375. List(ctx context.Context, zone string, fl *filter.F) ([]*alpha.NetworkEndpointGroup, error)
  9376. Insert(ctx context.Context, key *meta.Key, obj *alpha.NetworkEndpointGroup) error
  9377. Delete(ctx context.Context, key *meta.Key) error
  9378. AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*alpha.NetworkEndpointGroup, error)
  9379. AttachNetworkEndpoints(context.Context, *meta.Key, *alpha.NetworkEndpointGroupsAttachEndpointsRequest) error
  9380. DetachNetworkEndpoints(context.Context, *meta.Key, *alpha.NetworkEndpointGroupsDetachEndpointsRequest) error
  9381. ListNetworkEndpoints(context.Context, *meta.Key, *alpha.NetworkEndpointGroupsListEndpointsRequest, *filter.F) ([]*alpha.NetworkEndpointWithHealthStatus, error)
  9382. }
  9383. // NewMockAlphaNetworkEndpointGroups returns a new mock for NetworkEndpointGroups.
  9384. func NewMockAlphaNetworkEndpointGroups(pr ProjectRouter, objs map[meta.Key]*MockNetworkEndpointGroupsObj) *MockAlphaNetworkEndpointGroups {
  9385. mock := &MockAlphaNetworkEndpointGroups{
  9386. ProjectRouter: pr,
  9387. Objects: objs,
  9388. GetError: map[meta.Key]error{},
  9389. InsertError: map[meta.Key]error{},
  9390. DeleteError: map[meta.Key]error{},
  9391. }
  9392. return mock
  9393. }
  9394. // MockAlphaNetworkEndpointGroups is the mock for NetworkEndpointGroups.
  9395. type MockAlphaNetworkEndpointGroups struct {
  9396. Lock sync.Mutex
  9397. ProjectRouter ProjectRouter
  9398. // Objects maintained by the mock.
  9399. Objects map[meta.Key]*MockNetworkEndpointGroupsObj
  9400. // If an entry exists for the given key and operation, then the error
  9401. // will be returned instead of the operation.
  9402. GetError map[meta.Key]error
  9403. ListError *error
  9404. InsertError map[meta.Key]error
  9405. DeleteError map[meta.Key]error
  9406. AggregatedListError *error
  9407. // xxxHook allow you to intercept the standard processing of the mock in
  9408. // order to add your own logic. Return (true, _, _) to prevent the normal
  9409. // execution flow of the mock. Return (false, nil, nil) to continue with
  9410. // normal mock behavior/ after the hook function executes.
  9411. GetHook func(ctx context.Context, key *meta.Key, m *MockAlphaNetworkEndpointGroups) (bool, *alpha.NetworkEndpointGroup, error)
  9412. ListHook func(ctx context.Context, zone string, fl *filter.F, m *MockAlphaNetworkEndpointGroups) (bool, []*alpha.NetworkEndpointGroup, error)
  9413. InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.NetworkEndpointGroup, m *MockAlphaNetworkEndpointGroups) (bool, error)
  9414. DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaNetworkEndpointGroups) (bool, error)
  9415. AggregatedListHook func(ctx context.Context, fl *filter.F, m *MockAlphaNetworkEndpointGroups) (bool, map[string][]*alpha.NetworkEndpointGroup, error)
  9416. AttachNetworkEndpointsHook func(context.Context, *meta.Key, *alpha.NetworkEndpointGroupsAttachEndpointsRequest, *MockAlphaNetworkEndpointGroups) error
  9417. DetachNetworkEndpointsHook func(context.Context, *meta.Key, *alpha.NetworkEndpointGroupsDetachEndpointsRequest, *MockAlphaNetworkEndpointGroups) error
  9418. ListNetworkEndpointsHook func(context.Context, *meta.Key, *alpha.NetworkEndpointGroupsListEndpointsRequest, *filter.F, *MockAlphaNetworkEndpointGroups) ([]*alpha.NetworkEndpointWithHealthStatus, error)
  9419. // X is extra state that can be used as part of the mock. Generated code
  9420. // will not use this field.
  9421. X interface{}
  9422. }
  9423. // Get returns the object from the mock.
  9424. func (m *MockAlphaNetworkEndpointGroups) Get(ctx context.Context, key *meta.Key) (*alpha.NetworkEndpointGroup, error) {
  9425. if m.GetHook != nil {
  9426. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  9427. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  9428. return obj, err
  9429. }
  9430. }
  9431. if !key.Valid() {
  9432. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  9433. }
  9434. m.Lock.Lock()
  9435. defer m.Lock.Unlock()
  9436. if err, ok := m.GetError[*key]; ok {
  9437. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Get(%v, %s) = nil, %v", ctx, key, err)
  9438. return nil, err
  9439. }
  9440. if obj, ok := m.Objects[*key]; ok {
  9441. typedObj := obj.ToAlpha()
  9442. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  9443. return typedObj, nil
  9444. }
  9445. err := &googleapi.Error{
  9446. Code: http.StatusNotFound,
  9447. Message: fmt.Sprintf("MockAlphaNetworkEndpointGroups %v not found", key),
  9448. }
  9449. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Get(%v, %s) = nil, %v", ctx, key, err)
  9450. return nil, err
  9451. }
  9452. // List all of the objects in the mock in the given zone.
  9453. func (m *MockAlphaNetworkEndpointGroups) List(ctx context.Context, zone string, fl *filter.F) ([]*alpha.NetworkEndpointGroup, error) {
  9454. if m.ListHook != nil {
  9455. if intercept, objs, err := m.ListHook(ctx, zone, fl, m); intercept {
  9456. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.List(%v, %q, %v) = [%v items], %v", ctx, zone, fl, len(objs), err)
  9457. return objs, err
  9458. }
  9459. }
  9460. m.Lock.Lock()
  9461. defer m.Lock.Unlock()
  9462. if m.ListError != nil {
  9463. err := *m.ListError
  9464. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.List(%v, %q, %v) = nil, %v", ctx, zone, fl, err)
  9465. return nil, *m.ListError
  9466. }
  9467. var objs []*alpha.NetworkEndpointGroup
  9468. for key, obj := range m.Objects {
  9469. if key.Zone != zone {
  9470. continue
  9471. }
  9472. if !fl.Match(obj.ToAlpha()) {
  9473. continue
  9474. }
  9475. objs = append(objs, obj.ToAlpha())
  9476. }
  9477. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.List(%v, %q, %v) = [%v items], nil", ctx, zone, fl, len(objs))
  9478. return objs, nil
  9479. }
  9480. // Insert is a mock for inserting/creating a new object.
  9481. func (m *MockAlphaNetworkEndpointGroups) Insert(ctx context.Context, key *meta.Key, obj *alpha.NetworkEndpointGroup) error {
  9482. if m.InsertHook != nil {
  9483. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  9484. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9485. return err
  9486. }
  9487. }
  9488. if !key.Valid() {
  9489. return fmt.Errorf("invalid GCE key (%+v)", key)
  9490. }
  9491. m.Lock.Lock()
  9492. defer m.Lock.Unlock()
  9493. if err, ok := m.InsertError[*key]; ok {
  9494. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9495. return err
  9496. }
  9497. if _, ok := m.Objects[*key]; ok {
  9498. err := &googleapi.Error{
  9499. Code: http.StatusConflict,
  9500. Message: fmt.Sprintf("MockAlphaNetworkEndpointGroups %v exists", key),
  9501. }
  9502. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9503. return err
  9504. }
  9505. obj.Name = key.Name
  9506. projectID := m.ProjectRouter.ProjectID(ctx, "alpha", "networkEndpointGroups")
  9507. obj.SelfLink = SelfLink(meta.VersionAlpha, projectID, "networkEndpointGroups", key)
  9508. m.Objects[*key] = &MockNetworkEndpointGroupsObj{obj}
  9509. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  9510. return nil
  9511. }
  9512. // Delete is a mock for deleting the object.
  9513. func (m *MockAlphaNetworkEndpointGroups) Delete(ctx context.Context, key *meta.Key) error {
  9514. if m.DeleteHook != nil {
  9515. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  9516. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  9517. return err
  9518. }
  9519. }
  9520. if !key.Valid() {
  9521. return fmt.Errorf("invalid GCE key (%+v)", key)
  9522. }
  9523. m.Lock.Lock()
  9524. defer m.Lock.Unlock()
  9525. if err, ok := m.DeleteError[*key]; ok {
  9526. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  9527. return err
  9528. }
  9529. if _, ok := m.Objects[*key]; !ok {
  9530. err := &googleapi.Error{
  9531. Code: http.StatusNotFound,
  9532. Message: fmt.Sprintf("MockAlphaNetworkEndpointGroups %v not found", key),
  9533. }
  9534. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  9535. return err
  9536. }
  9537. delete(m.Objects, *key)
  9538. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.Delete(%v, %v) = nil", ctx, key)
  9539. return nil
  9540. }
  9541. // AggregatedList is a mock for AggregatedList.
  9542. func (m *MockAlphaNetworkEndpointGroups) AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*alpha.NetworkEndpointGroup, error) {
  9543. if m.AggregatedListHook != nil {
  9544. if intercept, objs, err := m.AggregatedListHook(ctx, fl, m); intercept {
  9545. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.AggregatedList(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  9546. return objs, err
  9547. }
  9548. }
  9549. m.Lock.Lock()
  9550. defer m.Lock.Unlock()
  9551. if m.AggregatedListError != nil {
  9552. err := *m.AggregatedListError
  9553. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.AggregatedList(%v, %v) = nil, %v", ctx, fl, err)
  9554. return nil, err
  9555. }
  9556. objs := map[string][]*alpha.NetworkEndpointGroup{}
  9557. for _, obj := range m.Objects {
  9558. res, err := ParseResourceURL(obj.ToAlpha().SelfLink)
  9559. location := res.Key.Zone
  9560. if err != nil {
  9561. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.AggregatedList(%v, %v) = nil, %v", ctx, fl, err)
  9562. return nil, err
  9563. }
  9564. if !fl.Match(obj.ToAlpha()) {
  9565. continue
  9566. }
  9567. objs[location] = append(objs[location], obj.ToAlpha())
  9568. }
  9569. klog.V(5).Infof("MockAlphaNetworkEndpointGroups.AggregatedList(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  9570. return objs, nil
  9571. }
  9572. // Obj wraps the object for use in the mock.
  9573. func (m *MockAlphaNetworkEndpointGroups) Obj(o *alpha.NetworkEndpointGroup) *MockNetworkEndpointGroupsObj {
  9574. return &MockNetworkEndpointGroupsObj{o}
  9575. }
  9576. // AttachNetworkEndpoints is a mock for the corresponding method.
  9577. func (m *MockAlphaNetworkEndpointGroups) AttachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *alpha.NetworkEndpointGroupsAttachEndpointsRequest) error {
  9578. if m.AttachNetworkEndpointsHook != nil {
  9579. return m.AttachNetworkEndpointsHook(ctx, key, arg0, m)
  9580. }
  9581. return nil
  9582. }
  9583. // DetachNetworkEndpoints is a mock for the corresponding method.
  9584. func (m *MockAlphaNetworkEndpointGroups) DetachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *alpha.NetworkEndpointGroupsDetachEndpointsRequest) error {
  9585. if m.DetachNetworkEndpointsHook != nil {
  9586. return m.DetachNetworkEndpointsHook(ctx, key, arg0, m)
  9587. }
  9588. return nil
  9589. }
  9590. // ListNetworkEndpoints is a mock for the corresponding method.
  9591. func (m *MockAlphaNetworkEndpointGroups) ListNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *alpha.NetworkEndpointGroupsListEndpointsRequest, fl *filter.F) ([]*alpha.NetworkEndpointWithHealthStatus, error) {
  9592. if m.ListNetworkEndpointsHook != nil {
  9593. return m.ListNetworkEndpointsHook(ctx, key, arg0, fl, m)
  9594. }
  9595. return nil, nil
  9596. }
  9597. // GCEAlphaNetworkEndpointGroups is a simplifying adapter for the GCE NetworkEndpointGroups.
  9598. type GCEAlphaNetworkEndpointGroups struct {
  9599. s *Service
  9600. }
  9601. // Get the NetworkEndpointGroup named by key.
  9602. func (g *GCEAlphaNetworkEndpointGroups) Get(ctx context.Context, key *meta.Key) (*alpha.NetworkEndpointGroup, error) {
  9603. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.Get(%v, %v): called", ctx, key)
  9604. if !key.Valid() {
  9605. klog.V(2).Infof("GCEAlphaNetworkEndpointGroups.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  9606. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  9607. }
  9608. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9609. rk := &RateLimitKey{
  9610. ProjectID: projectID,
  9611. Operation: "Get",
  9612. Version: meta.Version("alpha"),
  9613. Service: "NetworkEndpointGroups",
  9614. }
  9615. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9616. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9617. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  9618. return nil, err
  9619. }
  9620. call := g.s.Alpha.NetworkEndpointGroups.Get(projectID, key.Zone, key.Name)
  9621. call.Context(ctx)
  9622. v, err := call.Do()
  9623. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  9624. return v, err
  9625. }
  9626. // List all NetworkEndpointGroup objects.
  9627. func (g *GCEAlphaNetworkEndpointGroups) List(ctx context.Context, zone string, fl *filter.F) ([]*alpha.NetworkEndpointGroup, error) {
  9628. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.List(%v, %v, %v) called", ctx, zone, fl)
  9629. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9630. rk := &RateLimitKey{
  9631. ProjectID: projectID,
  9632. Operation: "List",
  9633. Version: meta.Version("alpha"),
  9634. Service: "NetworkEndpointGroups",
  9635. }
  9636. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9637. return nil, err
  9638. }
  9639. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
  9640. call := g.s.Alpha.NetworkEndpointGroups.List(projectID, zone)
  9641. if fl != filter.None {
  9642. call.Filter(fl.String())
  9643. }
  9644. var all []*alpha.NetworkEndpointGroup
  9645. f := func(l *alpha.NetworkEndpointGroupList) error {
  9646. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.List(%v, ..., %v): page %+v", ctx, fl, l)
  9647. all = append(all, l.Items...)
  9648. return nil
  9649. }
  9650. if err := call.Pages(ctx, f); err != nil {
  9651. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  9652. return nil, err
  9653. }
  9654. if klog.V(4) {
  9655. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  9656. } else if klog.V(5) {
  9657. var asStr []string
  9658. for _, o := range all {
  9659. asStr = append(asStr, fmt.Sprintf("%+v", o))
  9660. }
  9661. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  9662. }
  9663. return all, nil
  9664. }
  9665. // Insert NetworkEndpointGroup with key of value obj.
  9666. func (g *GCEAlphaNetworkEndpointGroups) Insert(ctx context.Context, key *meta.Key, obj *alpha.NetworkEndpointGroup) error {
  9667. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.Insert(%v, %v, %+v): called", ctx, key, obj)
  9668. if !key.Valid() {
  9669. klog.V(2).Infof("GCEAlphaNetworkEndpointGroups.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9670. return fmt.Errorf("invalid GCE key (%+v)", key)
  9671. }
  9672. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9673. rk := &RateLimitKey{
  9674. ProjectID: projectID,
  9675. Operation: "Insert",
  9676. Version: meta.Version("alpha"),
  9677. Service: "NetworkEndpointGroups",
  9678. }
  9679. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9680. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9681. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9682. return err
  9683. }
  9684. obj.Name = key.Name
  9685. call := g.s.Alpha.NetworkEndpointGroups.Insert(projectID, key.Zone, obj)
  9686. call.Context(ctx)
  9687. op, err := call.Do()
  9688. if err != nil {
  9689. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Insert(%v, %v, ...) = %+v", ctx, key, err)
  9690. return err
  9691. }
  9692. err = g.s.WaitForCompletion(ctx, op)
  9693. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  9694. return err
  9695. }
  9696. // Delete the NetworkEndpointGroup referenced by key.
  9697. func (g *GCEAlphaNetworkEndpointGroups) Delete(ctx context.Context, key *meta.Key) error {
  9698. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.Delete(%v, %v): called", ctx, key)
  9699. if !key.Valid() {
  9700. klog.V(2).Infof("GCEAlphaNetworkEndpointGroups.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  9701. return fmt.Errorf("invalid GCE key (%+v)", key)
  9702. }
  9703. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9704. rk := &RateLimitKey{
  9705. ProjectID: projectID,
  9706. Operation: "Delete",
  9707. Version: meta.Version("alpha"),
  9708. Service: "NetworkEndpointGroups",
  9709. }
  9710. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9711. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9712. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  9713. return err
  9714. }
  9715. call := g.s.Alpha.NetworkEndpointGroups.Delete(projectID, key.Zone, key.Name)
  9716. call.Context(ctx)
  9717. op, err := call.Do()
  9718. if err != nil {
  9719. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  9720. return err
  9721. }
  9722. err = g.s.WaitForCompletion(ctx, op)
  9723. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  9724. return err
  9725. }
  9726. // AggregatedList lists all resources of the given type across all locations.
  9727. func (g *GCEAlphaNetworkEndpointGroups) AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*alpha.NetworkEndpointGroup, error) {
  9728. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.AggregatedList(%v, %v) called", ctx, fl)
  9729. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9730. rk := &RateLimitKey{
  9731. ProjectID: projectID,
  9732. Operation: "AggregatedList",
  9733. Version: meta.Version("alpha"),
  9734. Service: "NetworkEndpointGroups",
  9735. }
  9736. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.AggregatedList(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  9737. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9738. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.AggregatedList(%v, %v): RateLimiter error: %v", ctx, fl, err)
  9739. return nil, err
  9740. }
  9741. call := g.s.Alpha.NetworkEndpointGroups.AggregatedList(projectID)
  9742. call.Context(ctx)
  9743. if fl != filter.None {
  9744. call.Filter(fl.String())
  9745. }
  9746. all := map[string][]*alpha.NetworkEndpointGroup{}
  9747. f := func(l *alpha.NetworkEndpointGroupAggregatedList) error {
  9748. for k, v := range l.Items {
  9749. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.AggregatedList(%v, %v): page[%v]%+v", ctx, fl, k, v)
  9750. all[k] = append(all[k], v.NetworkEndpointGroups...)
  9751. }
  9752. return nil
  9753. }
  9754. if err := call.Pages(ctx, f); err != nil {
  9755. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.AggregatedList(%v, %v) = %v, %v", ctx, fl, nil, err)
  9756. return nil, err
  9757. }
  9758. if klog.V(4) {
  9759. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.AggregatedList(%v, %v) = [%v items], %v", ctx, fl, len(all), nil)
  9760. } else if klog.V(5) {
  9761. var asStr []string
  9762. for _, o := range all {
  9763. asStr = append(asStr, fmt.Sprintf("%+v", o))
  9764. }
  9765. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.AggregatedList(%v, %v) = %v, %v", ctx, fl, asStr, nil)
  9766. }
  9767. return all, nil
  9768. }
  9769. // AttachNetworkEndpoints is a method on GCEAlphaNetworkEndpointGroups.
  9770. func (g *GCEAlphaNetworkEndpointGroups) AttachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *alpha.NetworkEndpointGroupsAttachEndpointsRequest) error {
  9771. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): called", ctx, key)
  9772. if !key.Valid() {
  9773. klog.V(2).Infof("GCEAlphaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9774. return fmt.Errorf("invalid GCE key (%+v)", key)
  9775. }
  9776. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9777. rk := &RateLimitKey{
  9778. ProjectID: projectID,
  9779. Operation: "AttachNetworkEndpoints",
  9780. Version: meta.Version("alpha"),
  9781. Service: "NetworkEndpointGroups",
  9782. }
  9783. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9784. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9785. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9786. return err
  9787. }
  9788. call := g.s.Alpha.NetworkEndpointGroups.AttachNetworkEndpoints(projectID, key.Zone, key.Name, arg0)
  9789. call.Context(ctx)
  9790. op, err := call.Do()
  9791. if err != nil {
  9792. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  9793. return err
  9794. }
  9795. err = g.s.WaitForCompletion(ctx, op)
  9796. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  9797. return err
  9798. }
  9799. // DetachNetworkEndpoints is a method on GCEAlphaNetworkEndpointGroups.
  9800. func (g *GCEAlphaNetworkEndpointGroups) DetachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *alpha.NetworkEndpointGroupsDetachEndpointsRequest) error {
  9801. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): called", ctx, key)
  9802. if !key.Valid() {
  9803. klog.V(2).Infof("GCEAlphaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9804. return fmt.Errorf("invalid GCE key (%+v)", key)
  9805. }
  9806. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9807. rk := &RateLimitKey{
  9808. ProjectID: projectID,
  9809. Operation: "DetachNetworkEndpoints",
  9810. Version: meta.Version("alpha"),
  9811. Service: "NetworkEndpointGroups",
  9812. }
  9813. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9814. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9815. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9816. return err
  9817. }
  9818. call := g.s.Alpha.NetworkEndpointGroups.DetachNetworkEndpoints(projectID, key.Zone, key.Name, arg0)
  9819. call.Context(ctx)
  9820. op, err := call.Do()
  9821. if err != nil {
  9822. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  9823. return err
  9824. }
  9825. err = g.s.WaitForCompletion(ctx, op)
  9826. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  9827. return err
  9828. }
  9829. // ListNetworkEndpoints is a method on GCEAlphaNetworkEndpointGroups.
  9830. func (g *GCEAlphaNetworkEndpointGroups) ListNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *alpha.NetworkEndpointGroupsListEndpointsRequest, fl *filter.F) ([]*alpha.NetworkEndpointWithHealthStatus, error) {
  9831. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): called", ctx, key)
  9832. if !key.Valid() {
  9833. klog.V(2).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  9834. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  9835. }
  9836. projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "NetworkEndpointGroups")
  9837. rk := &RateLimitKey{
  9838. ProjectID: projectID,
  9839. Operation: "ListNetworkEndpoints",
  9840. Version: meta.Version("alpha"),
  9841. Service: "NetworkEndpointGroups",
  9842. }
  9843. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  9844. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  9845. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  9846. return nil, err
  9847. }
  9848. call := g.s.Alpha.NetworkEndpointGroups.ListNetworkEndpoints(projectID, key.Zone, key.Name, arg0)
  9849. var all []*alpha.NetworkEndpointWithHealthStatus
  9850. f := func(l *alpha.NetworkEndpointGroupsListNetworkEndpoints) error {
  9851. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): page %+v", ctx, key, l)
  9852. all = append(all, l.Items...)
  9853. return nil
  9854. }
  9855. if err := call.Pages(ctx, f); err != nil {
  9856. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...) = %v, %v", ctx, key, nil, err)
  9857. return nil, err
  9858. }
  9859. if klog.V(4) {
  9860. klog.V(4).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...) = [%v items], %v", ctx, key, len(all), nil)
  9861. } else if klog.V(5) {
  9862. var asStr []string
  9863. for _, o := range all {
  9864. asStr = append(asStr, fmt.Sprintf("%+v", o))
  9865. }
  9866. klog.V(5).Infof("GCEAlphaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...) = %v, %v", ctx, key, asStr, nil)
  9867. }
  9868. return all, nil
  9869. }
  9870. // BetaNetworkEndpointGroups is an interface that allows for mocking of NetworkEndpointGroups.
  9871. type BetaNetworkEndpointGroups interface {
  9872. Get(ctx context.Context, key *meta.Key) (*beta.NetworkEndpointGroup, error)
  9873. List(ctx context.Context, zone string, fl *filter.F) ([]*beta.NetworkEndpointGroup, error)
  9874. Insert(ctx context.Context, key *meta.Key, obj *beta.NetworkEndpointGroup) error
  9875. Delete(ctx context.Context, key *meta.Key) error
  9876. AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*beta.NetworkEndpointGroup, error)
  9877. AttachNetworkEndpoints(context.Context, *meta.Key, *beta.NetworkEndpointGroupsAttachEndpointsRequest) error
  9878. DetachNetworkEndpoints(context.Context, *meta.Key, *beta.NetworkEndpointGroupsDetachEndpointsRequest) error
  9879. ListNetworkEndpoints(context.Context, *meta.Key, *beta.NetworkEndpointGroupsListEndpointsRequest, *filter.F) ([]*beta.NetworkEndpointWithHealthStatus, error)
  9880. }
  9881. // NewMockBetaNetworkEndpointGroups returns a new mock for NetworkEndpointGroups.
  9882. func NewMockBetaNetworkEndpointGroups(pr ProjectRouter, objs map[meta.Key]*MockNetworkEndpointGroupsObj) *MockBetaNetworkEndpointGroups {
  9883. mock := &MockBetaNetworkEndpointGroups{
  9884. ProjectRouter: pr,
  9885. Objects: objs,
  9886. GetError: map[meta.Key]error{},
  9887. InsertError: map[meta.Key]error{},
  9888. DeleteError: map[meta.Key]error{},
  9889. }
  9890. return mock
  9891. }
  9892. // MockBetaNetworkEndpointGroups is the mock for NetworkEndpointGroups.
  9893. type MockBetaNetworkEndpointGroups struct {
  9894. Lock sync.Mutex
  9895. ProjectRouter ProjectRouter
  9896. // Objects maintained by the mock.
  9897. Objects map[meta.Key]*MockNetworkEndpointGroupsObj
  9898. // If an entry exists for the given key and operation, then the error
  9899. // will be returned instead of the operation.
  9900. GetError map[meta.Key]error
  9901. ListError *error
  9902. InsertError map[meta.Key]error
  9903. DeleteError map[meta.Key]error
  9904. AggregatedListError *error
  9905. // xxxHook allow you to intercept the standard processing of the mock in
  9906. // order to add your own logic. Return (true, _, _) to prevent the normal
  9907. // execution flow of the mock. Return (false, nil, nil) to continue with
  9908. // normal mock behavior/ after the hook function executes.
  9909. GetHook func(ctx context.Context, key *meta.Key, m *MockBetaNetworkEndpointGroups) (bool, *beta.NetworkEndpointGroup, error)
  9910. ListHook func(ctx context.Context, zone string, fl *filter.F, m *MockBetaNetworkEndpointGroups) (bool, []*beta.NetworkEndpointGroup, error)
  9911. InsertHook func(ctx context.Context, key *meta.Key, obj *beta.NetworkEndpointGroup, m *MockBetaNetworkEndpointGroups) (bool, error)
  9912. DeleteHook func(ctx context.Context, key *meta.Key, m *MockBetaNetworkEndpointGroups) (bool, error)
  9913. AggregatedListHook func(ctx context.Context, fl *filter.F, m *MockBetaNetworkEndpointGroups) (bool, map[string][]*beta.NetworkEndpointGroup, error)
  9914. AttachNetworkEndpointsHook func(context.Context, *meta.Key, *beta.NetworkEndpointGroupsAttachEndpointsRequest, *MockBetaNetworkEndpointGroups) error
  9915. DetachNetworkEndpointsHook func(context.Context, *meta.Key, *beta.NetworkEndpointGroupsDetachEndpointsRequest, *MockBetaNetworkEndpointGroups) error
  9916. ListNetworkEndpointsHook func(context.Context, *meta.Key, *beta.NetworkEndpointGroupsListEndpointsRequest, *filter.F, *MockBetaNetworkEndpointGroups) ([]*beta.NetworkEndpointWithHealthStatus, error)
  9917. // X is extra state that can be used as part of the mock. Generated code
  9918. // will not use this field.
  9919. X interface{}
  9920. }
  9921. // Get returns the object from the mock.
  9922. func (m *MockBetaNetworkEndpointGroups) Get(ctx context.Context, key *meta.Key) (*beta.NetworkEndpointGroup, error) {
  9923. if m.GetHook != nil {
  9924. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  9925. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  9926. return obj, err
  9927. }
  9928. }
  9929. if !key.Valid() {
  9930. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  9931. }
  9932. m.Lock.Lock()
  9933. defer m.Lock.Unlock()
  9934. if err, ok := m.GetError[*key]; ok {
  9935. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Get(%v, %s) = nil, %v", ctx, key, err)
  9936. return nil, err
  9937. }
  9938. if obj, ok := m.Objects[*key]; ok {
  9939. typedObj := obj.ToBeta()
  9940. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  9941. return typedObj, nil
  9942. }
  9943. err := &googleapi.Error{
  9944. Code: http.StatusNotFound,
  9945. Message: fmt.Sprintf("MockBetaNetworkEndpointGroups %v not found", key),
  9946. }
  9947. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Get(%v, %s) = nil, %v", ctx, key, err)
  9948. return nil, err
  9949. }
  9950. // List all of the objects in the mock in the given zone.
  9951. func (m *MockBetaNetworkEndpointGroups) List(ctx context.Context, zone string, fl *filter.F) ([]*beta.NetworkEndpointGroup, error) {
  9952. if m.ListHook != nil {
  9953. if intercept, objs, err := m.ListHook(ctx, zone, fl, m); intercept {
  9954. klog.V(5).Infof("MockBetaNetworkEndpointGroups.List(%v, %q, %v) = [%v items], %v", ctx, zone, fl, len(objs), err)
  9955. return objs, err
  9956. }
  9957. }
  9958. m.Lock.Lock()
  9959. defer m.Lock.Unlock()
  9960. if m.ListError != nil {
  9961. err := *m.ListError
  9962. klog.V(5).Infof("MockBetaNetworkEndpointGroups.List(%v, %q, %v) = nil, %v", ctx, zone, fl, err)
  9963. return nil, *m.ListError
  9964. }
  9965. var objs []*beta.NetworkEndpointGroup
  9966. for key, obj := range m.Objects {
  9967. if key.Zone != zone {
  9968. continue
  9969. }
  9970. if !fl.Match(obj.ToBeta()) {
  9971. continue
  9972. }
  9973. objs = append(objs, obj.ToBeta())
  9974. }
  9975. klog.V(5).Infof("MockBetaNetworkEndpointGroups.List(%v, %q, %v) = [%v items], nil", ctx, zone, fl, len(objs))
  9976. return objs, nil
  9977. }
  9978. // Insert is a mock for inserting/creating a new object.
  9979. func (m *MockBetaNetworkEndpointGroups) Insert(ctx context.Context, key *meta.Key, obj *beta.NetworkEndpointGroup) error {
  9980. if m.InsertHook != nil {
  9981. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  9982. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9983. return err
  9984. }
  9985. }
  9986. if !key.Valid() {
  9987. return fmt.Errorf("invalid GCE key (%+v)", key)
  9988. }
  9989. m.Lock.Lock()
  9990. defer m.Lock.Unlock()
  9991. if err, ok := m.InsertError[*key]; ok {
  9992. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  9993. return err
  9994. }
  9995. if _, ok := m.Objects[*key]; ok {
  9996. err := &googleapi.Error{
  9997. Code: http.StatusConflict,
  9998. Message: fmt.Sprintf("MockBetaNetworkEndpointGroups %v exists", key),
  9999. }
  10000. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  10001. return err
  10002. }
  10003. obj.Name = key.Name
  10004. projectID := m.ProjectRouter.ProjectID(ctx, "beta", "networkEndpointGroups")
  10005. obj.SelfLink = SelfLink(meta.VersionBeta, projectID, "networkEndpointGroups", key)
  10006. m.Objects[*key] = &MockNetworkEndpointGroupsObj{obj}
  10007. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  10008. return nil
  10009. }
  10010. // Delete is a mock for deleting the object.
  10011. func (m *MockBetaNetworkEndpointGroups) Delete(ctx context.Context, key *meta.Key) error {
  10012. if m.DeleteHook != nil {
  10013. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  10014. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  10015. return err
  10016. }
  10017. }
  10018. if !key.Valid() {
  10019. return fmt.Errorf("invalid GCE key (%+v)", key)
  10020. }
  10021. m.Lock.Lock()
  10022. defer m.Lock.Unlock()
  10023. if err, ok := m.DeleteError[*key]; ok {
  10024. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  10025. return err
  10026. }
  10027. if _, ok := m.Objects[*key]; !ok {
  10028. err := &googleapi.Error{
  10029. Code: http.StatusNotFound,
  10030. Message: fmt.Sprintf("MockBetaNetworkEndpointGroups %v not found", key),
  10031. }
  10032. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  10033. return err
  10034. }
  10035. delete(m.Objects, *key)
  10036. klog.V(5).Infof("MockBetaNetworkEndpointGroups.Delete(%v, %v) = nil", ctx, key)
  10037. return nil
  10038. }
  10039. // AggregatedList is a mock for AggregatedList.
  10040. func (m *MockBetaNetworkEndpointGroups) AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*beta.NetworkEndpointGroup, error) {
  10041. if m.AggregatedListHook != nil {
  10042. if intercept, objs, err := m.AggregatedListHook(ctx, fl, m); intercept {
  10043. klog.V(5).Infof("MockBetaNetworkEndpointGroups.AggregatedList(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  10044. return objs, err
  10045. }
  10046. }
  10047. m.Lock.Lock()
  10048. defer m.Lock.Unlock()
  10049. if m.AggregatedListError != nil {
  10050. err := *m.AggregatedListError
  10051. klog.V(5).Infof("MockBetaNetworkEndpointGroups.AggregatedList(%v, %v) = nil, %v", ctx, fl, err)
  10052. return nil, err
  10053. }
  10054. objs := map[string][]*beta.NetworkEndpointGroup{}
  10055. for _, obj := range m.Objects {
  10056. res, err := ParseResourceURL(obj.ToBeta().SelfLink)
  10057. location := res.Key.Zone
  10058. if err != nil {
  10059. klog.V(5).Infof("MockBetaNetworkEndpointGroups.AggregatedList(%v, %v) = nil, %v", ctx, fl, err)
  10060. return nil, err
  10061. }
  10062. if !fl.Match(obj.ToBeta()) {
  10063. continue
  10064. }
  10065. objs[location] = append(objs[location], obj.ToBeta())
  10066. }
  10067. klog.V(5).Infof("MockBetaNetworkEndpointGroups.AggregatedList(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  10068. return objs, nil
  10069. }
  10070. // Obj wraps the object for use in the mock.
  10071. func (m *MockBetaNetworkEndpointGroups) Obj(o *beta.NetworkEndpointGroup) *MockNetworkEndpointGroupsObj {
  10072. return &MockNetworkEndpointGroupsObj{o}
  10073. }
  10074. // AttachNetworkEndpoints is a mock for the corresponding method.
  10075. func (m *MockBetaNetworkEndpointGroups) AttachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *beta.NetworkEndpointGroupsAttachEndpointsRequest) error {
  10076. if m.AttachNetworkEndpointsHook != nil {
  10077. return m.AttachNetworkEndpointsHook(ctx, key, arg0, m)
  10078. }
  10079. return nil
  10080. }
  10081. // DetachNetworkEndpoints is a mock for the corresponding method.
  10082. func (m *MockBetaNetworkEndpointGroups) DetachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *beta.NetworkEndpointGroupsDetachEndpointsRequest) error {
  10083. if m.DetachNetworkEndpointsHook != nil {
  10084. return m.DetachNetworkEndpointsHook(ctx, key, arg0, m)
  10085. }
  10086. return nil
  10087. }
  10088. // ListNetworkEndpoints is a mock for the corresponding method.
  10089. func (m *MockBetaNetworkEndpointGroups) ListNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *beta.NetworkEndpointGroupsListEndpointsRequest, fl *filter.F) ([]*beta.NetworkEndpointWithHealthStatus, error) {
  10090. if m.ListNetworkEndpointsHook != nil {
  10091. return m.ListNetworkEndpointsHook(ctx, key, arg0, fl, m)
  10092. }
  10093. return nil, nil
  10094. }
  10095. // GCEBetaNetworkEndpointGroups is a simplifying adapter for the GCE NetworkEndpointGroups.
  10096. type GCEBetaNetworkEndpointGroups struct {
  10097. s *Service
  10098. }
  10099. // Get the NetworkEndpointGroup named by key.
  10100. func (g *GCEBetaNetworkEndpointGroups) Get(ctx context.Context, key *meta.Key) (*beta.NetworkEndpointGroup, error) {
  10101. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.Get(%v, %v): called", ctx, key)
  10102. if !key.Valid() {
  10103. klog.V(2).Infof("GCEBetaNetworkEndpointGroups.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  10104. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  10105. }
  10106. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10107. rk := &RateLimitKey{
  10108. ProjectID: projectID,
  10109. Operation: "Get",
  10110. Version: meta.Version("beta"),
  10111. Service: "NetworkEndpointGroups",
  10112. }
  10113. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10114. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10115. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  10116. return nil, err
  10117. }
  10118. call := g.s.Beta.NetworkEndpointGroups.Get(projectID, key.Zone, key.Name)
  10119. call.Context(ctx)
  10120. v, err := call.Do()
  10121. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  10122. return v, err
  10123. }
  10124. // List all NetworkEndpointGroup objects.
  10125. func (g *GCEBetaNetworkEndpointGroups) List(ctx context.Context, zone string, fl *filter.F) ([]*beta.NetworkEndpointGroup, error) {
  10126. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.List(%v, %v, %v) called", ctx, zone, fl)
  10127. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10128. rk := &RateLimitKey{
  10129. ProjectID: projectID,
  10130. Operation: "List",
  10131. Version: meta.Version("beta"),
  10132. Service: "NetworkEndpointGroups",
  10133. }
  10134. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10135. return nil, err
  10136. }
  10137. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
  10138. call := g.s.Beta.NetworkEndpointGroups.List(projectID, zone)
  10139. if fl != filter.None {
  10140. call.Filter(fl.String())
  10141. }
  10142. var all []*beta.NetworkEndpointGroup
  10143. f := func(l *beta.NetworkEndpointGroupList) error {
  10144. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.List(%v, ..., %v): page %+v", ctx, fl, l)
  10145. all = append(all, l.Items...)
  10146. return nil
  10147. }
  10148. if err := call.Pages(ctx, f); err != nil {
  10149. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  10150. return nil, err
  10151. }
  10152. if klog.V(4) {
  10153. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  10154. } else if klog.V(5) {
  10155. var asStr []string
  10156. for _, o := range all {
  10157. asStr = append(asStr, fmt.Sprintf("%+v", o))
  10158. }
  10159. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  10160. }
  10161. return all, nil
  10162. }
  10163. // Insert NetworkEndpointGroup with key of value obj.
  10164. func (g *GCEBetaNetworkEndpointGroups) Insert(ctx context.Context, key *meta.Key, obj *beta.NetworkEndpointGroup) error {
  10165. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.Insert(%v, %v, %+v): called", ctx, key, obj)
  10166. if !key.Valid() {
  10167. klog.V(2).Infof("GCEBetaNetworkEndpointGroups.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  10168. return fmt.Errorf("invalid GCE key (%+v)", key)
  10169. }
  10170. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10171. rk := &RateLimitKey{
  10172. ProjectID: projectID,
  10173. Operation: "Insert",
  10174. Version: meta.Version("beta"),
  10175. Service: "NetworkEndpointGroups",
  10176. }
  10177. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10178. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10179. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  10180. return err
  10181. }
  10182. obj.Name = key.Name
  10183. call := g.s.Beta.NetworkEndpointGroups.Insert(projectID, key.Zone, obj)
  10184. call.Context(ctx)
  10185. op, err := call.Do()
  10186. if err != nil {
  10187. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Insert(%v, %v, ...) = %+v", ctx, key, err)
  10188. return err
  10189. }
  10190. err = g.s.WaitForCompletion(ctx, op)
  10191. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  10192. return err
  10193. }
  10194. // Delete the NetworkEndpointGroup referenced by key.
  10195. func (g *GCEBetaNetworkEndpointGroups) Delete(ctx context.Context, key *meta.Key) error {
  10196. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.Delete(%v, %v): called", ctx, key)
  10197. if !key.Valid() {
  10198. klog.V(2).Infof("GCEBetaNetworkEndpointGroups.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  10199. return fmt.Errorf("invalid GCE key (%+v)", key)
  10200. }
  10201. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10202. rk := &RateLimitKey{
  10203. ProjectID: projectID,
  10204. Operation: "Delete",
  10205. Version: meta.Version("beta"),
  10206. Service: "NetworkEndpointGroups",
  10207. }
  10208. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10209. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10210. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  10211. return err
  10212. }
  10213. call := g.s.Beta.NetworkEndpointGroups.Delete(projectID, key.Zone, key.Name)
  10214. call.Context(ctx)
  10215. op, err := call.Do()
  10216. if err != nil {
  10217. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  10218. return err
  10219. }
  10220. err = g.s.WaitForCompletion(ctx, op)
  10221. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.Delete(%v, %v) = %v", ctx, key, err)
  10222. return err
  10223. }
  10224. // AggregatedList lists all resources of the given type across all locations.
  10225. func (g *GCEBetaNetworkEndpointGroups) AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*beta.NetworkEndpointGroup, error) {
  10226. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.AggregatedList(%v, %v) called", ctx, fl)
  10227. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10228. rk := &RateLimitKey{
  10229. ProjectID: projectID,
  10230. Operation: "AggregatedList",
  10231. Version: meta.Version("beta"),
  10232. Service: "NetworkEndpointGroups",
  10233. }
  10234. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.AggregatedList(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  10235. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10236. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.AggregatedList(%v, %v): RateLimiter error: %v", ctx, fl, err)
  10237. return nil, err
  10238. }
  10239. call := g.s.Beta.NetworkEndpointGroups.AggregatedList(projectID)
  10240. call.Context(ctx)
  10241. if fl != filter.None {
  10242. call.Filter(fl.String())
  10243. }
  10244. all := map[string][]*beta.NetworkEndpointGroup{}
  10245. f := func(l *beta.NetworkEndpointGroupAggregatedList) error {
  10246. for k, v := range l.Items {
  10247. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.AggregatedList(%v, %v): page[%v]%+v", ctx, fl, k, v)
  10248. all[k] = append(all[k], v.NetworkEndpointGroups...)
  10249. }
  10250. return nil
  10251. }
  10252. if err := call.Pages(ctx, f); err != nil {
  10253. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.AggregatedList(%v, %v) = %v, %v", ctx, fl, nil, err)
  10254. return nil, err
  10255. }
  10256. if klog.V(4) {
  10257. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.AggregatedList(%v, %v) = [%v items], %v", ctx, fl, len(all), nil)
  10258. } else if klog.V(5) {
  10259. var asStr []string
  10260. for _, o := range all {
  10261. asStr = append(asStr, fmt.Sprintf("%+v", o))
  10262. }
  10263. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.AggregatedList(%v, %v) = %v, %v", ctx, fl, asStr, nil)
  10264. }
  10265. return all, nil
  10266. }
  10267. // AttachNetworkEndpoints is a method on GCEBetaNetworkEndpointGroups.
  10268. func (g *GCEBetaNetworkEndpointGroups) AttachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *beta.NetworkEndpointGroupsAttachEndpointsRequest) error {
  10269. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): called", ctx, key)
  10270. if !key.Valid() {
  10271. klog.V(2).Infof("GCEBetaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  10272. return fmt.Errorf("invalid GCE key (%+v)", key)
  10273. }
  10274. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10275. rk := &RateLimitKey{
  10276. ProjectID: projectID,
  10277. Operation: "AttachNetworkEndpoints",
  10278. Version: meta.Version("beta"),
  10279. Service: "NetworkEndpointGroups",
  10280. }
  10281. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10282. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10283. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  10284. return err
  10285. }
  10286. call := g.s.Beta.NetworkEndpointGroups.AttachNetworkEndpoints(projectID, key.Zone, key.Name, arg0)
  10287. call.Context(ctx)
  10288. op, err := call.Do()
  10289. if err != nil {
  10290. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  10291. return err
  10292. }
  10293. err = g.s.WaitForCompletion(ctx, op)
  10294. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.AttachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  10295. return err
  10296. }
  10297. // DetachNetworkEndpoints is a method on GCEBetaNetworkEndpointGroups.
  10298. func (g *GCEBetaNetworkEndpointGroups) DetachNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *beta.NetworkEndpointGroupsDetachEndpointsRequest) error {
  10299. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): called", ctx, key)
  10300. if !key.Valid() {
  10301. klog.V(2).Infof("GCEBetaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  10302. return fmt.Errorf("invalid GCE key (%+v)", key)
  10303. }
  10304. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10305. rk := &RateLimitKey{
  10306. ProjectID: projectID,
  10307. Operation: "DetachNetworkEndpoints",
  10308. Version: meta.Version("beta"),
  10309. Service: "NetworkEndpointGroups",
  10310. }
  10311. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10312. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10313. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  10314. return err
  10315. }
  10316. call := g.s.Beta.NetworkEndpointGroups.DetachNetworkEndpoints(projectID, key.Zone, key.Name, arg0)
  10317. call.Context(ctx)
  10318. op, err := call.Do()
  10319. if err != nil {
  10320. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  10321. return err
  10322. }
  10323. err = g.s.WaitForCompletion(ctx, op)
  10324. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.DetachNetworkEndpoints(%v, %v, ...) = %+v", ctx, key, err)
  10325. return err
  10326. }
  10327. // ListNetworkEndpoints is a method on GCEBetaNetworkEndpointGroups.
  10328. func (g *GCEBetaNetworkEndpointGroups) ListNetworkEndpoints(ctx context.Context, key *meta.Key, arg0 *beta.NetworkEndpointGroupsListEndpointsRequest, fl *filter.F) ([]*beta.NetworkEndpointWithHealthStatus, error) {
  10329. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): called", ctx, key)
  10330. if !key.Valid() {
  10331. klog.V(2).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  10332. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  10333. }
  10334. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "NetworkEndpointGroups")
  10335. rk := &RateLimitKey{
  10336. ProjectID: projectID,
  10337. Operation: "ListNetworkEndpoints",
  10338. Version: meta.Version("beta"),
  10339. Service: "NetworkEndpointGroups",
  10340. }
  10341. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10342. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10343. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  10344. return nil, err
  10345. }
  10346. call := g.s.Beta.NetworkEndpointGroups.ListNetworkEndpoints(projectID, key.Zone, key.Name, arg0)
  10347. var all []*beta.NetworkEndpointWithHealthStatus
  10348. f := func(l *beta.NetworkEndpointGroupsListNetworkEndpoints) error {
  10349. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...): page %+v", ctx, key, l)
  10350. all = append(all, l.Items...)
  10351. return nil
  10352. }
  10353. if err := call.Pages(ctx, f); err != nil {
  10354. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...) = %v, %v", ctx, key, nil, err)
  10355. return nil, err
  10356. }
  10357. if klog.V(4) {
  10358. klog.V(4).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...) = [%v items], %v", ctx, key, len(all), nil)
  10359. } else if klog.V(5) {
  10360. var asStr []string
  10361. for _, o := range all {
  10362. asStr = append(asStr, fmt.Sprintf("%+v", o))
  10363. }
  10364. klog.V(5).Infof("GCEBetaNetworkEndpointGroups.ListNetworkEndpoints(%v, %v, ...) = %v, %v", ctx, key, asStr, nil)
  10365. }
  10366. return all, nil
  10367. }
  10368. // Projects is an interface that allows for mocking of Projects.
  10369. type Projects interface {
  10370. // ProjectsOps is an interface with additional non-CRUD type methods.
  10371. // This interface is expected to be implemented by hand (non-autogenerated).
  10372. ProjectsOps
  10373. }
  10374. // NewMockProjects returns a new mock for Projects.
  10375. func NewMockProjects(pr ProjectRouter, objs map[meta.Key]*MockProjectsObj) *MockProjects {
  10376. mock := &MockProjects{
  10377. ProjectRouter: pr,
  10378. Objects: objs,
  10379. }
  10380. return mock
  10381. }
  10382. // MockProjects is the mock for Projects.
  10383. type MockProjects struct {
  10384. Lock sync.Mutex
  10385. ProjectRouter ProjectRouter
  10386. // Objects maintained by the mock.
  10387. Objects map[meta.Key]*MockProjectsObj
  10388. // If an entry exists for the given key and operation, then the error
  10389. // will be returned instead of the operation.
  10390. // xxxHook allow you to intercept the standard processing of the mock in
  10391. // order to add your own logic. Return (true, _, _) to prevent the normal
  10392. // execution flow of the mock. Return (false, nil, nil) to continue with
  10393. // normal mock behavior/ after the hook function executes.
  10394. // X is extra state that can be used as part of the mock. Generated code
  10395. // will not use this field.
  10396. X interface{}
  10397. }
  10398. // Obj wraps the object for use in the mock.
  10399. func (m *MockProjects) Obj(o *ga.Project) *MockProjectsObj {
  10400. return &MockProjectsObj{o}
  10401. }
  10402. // GCEProjects is a simplifying adapter for the GCE Projects.
  10403. type GCEProjects struct {
  10404. s *Service
  10405. }
  10406. // Regions is an interface that allows for mocking of Regions.
  10407. type Regions interface {
  10408. Get(ctx context.Context, key *meta.Key) (*ga.Region, error)
  10409. List(ctx context.Context, fl *filter.F) ([]*ga.Region, error)
  10410. }
  10411. // NewMockRegions returns a new mock for Regions.
  10412. func NewMockRegions(pr ProjectRouter, objs map[meta.Key]*MockRegionsObj) *MockRegions {
  10413. mock := &MockRegions{
  10414. ProjectRouter: pr,
  10415. Objects: objs,
  10416. GetError: map[meta.Key]error{},
  10417. }
  10418. return mock
  10419. }
  10420. // MockRegions is the mock for Regions.
  10421. type MockRegions struct {
  10422. Lock sync.Mutex
  10423. ProjectRouter ProjectRouter
  10424. // Objects maintained by the mock.
  10425. Objects map[meta.Key]*MockRegionsObj
  10426. // If an entry exists for the given key and operation, then the error
  10427. // will be returned instead of the operation.
  10428. GetError map[meta.Key]error
  10429. ListError *error
  10430. // xxxHook allow you to intercept the standard processing of the mock in
  10431. // order to add your own logic. Return (true, _, _) to prevent the normal
  10432. // execution flow of the mock. Return (false, nil, nil) to continue with
  10433. // normal mock behavior/ after the hook function executes.
  10434. GetHook func(ctx context.Context, key *meta.Key, m *MockRegions) (bool, *ga.Region, error)
  10435. ListHook func(ctx context.Context, fl *filter.F, m *MockRegions) (bool, []*ga.Region, error)
  10436. // X is extra state that can be used as part of the mock. Generated code
  10437. // will not use this field.
  10438. X interface{}
  10439. }
  10440. // Get returns the object from the mock.
  10441. func (m *MockRegions) Get(ctx context.Context, key *meta.Key) (*ga.Region, error) {
  10442. if m.GetHook != nil {
  10443. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  10444. klog.V(5).Infof("MockRegions.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  10445. return obj, err
  10446. }
  10447. }
  10448. if !key.Valid() {
  10449. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  10450. }
  10451. m.Lock.Lock()
  10452. defer m.Lock.Unlock()
  10453. if err, ok := m.GetError[*key]; ok {
  10454. klog.V(5).Infof("MockRegions.Get(%v, %s) = nil, %v", ctx, key, err)
  10455. return nil, err
  10456. }
  10457. if obj, ok := m.Objects[*key]; ok {
  10458. typedObj := obj.ToGA()
  10459. klog.V(5).Infof("MockRegions.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  10460. return typedObj, nil
  10461. }
  10462. err := &googleapi.Error{
  10463. Code: http.StatusNotFound,
  10464. Message: fmt.Sprintf("MockRegions %v not found", key),
  10465. }
  10466. klog.V(5).Infof("MockRegions.Get(%v, %s) = nil, %v", ctx, key, err)
  10467. return nil, err
  10468. }
  10469. // List all of the objects in the mock.
  10470. func (m *MockRegions) List(ctx context.Context, fl *filter.F) ([]*ga.Region, error) {
  10471. if m.ListHook != nil {
  10472. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  10473. klog.V(5).Infof("MockRegions.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  10474. return objs, err
  10475. }
  10476. }
  10477. m.Lock.Lock()
  10478. defer m.Lock.Unlock()
  10479. if m.ListError != nil {
  10480. err := *m.ListError
  10481. klog.V(5).Infof("MockRegions.List(%v, %v) = nil, %v", ctx, fl, err)
  10482. return nil, *m.ListError
  10483. }
  10484. var objs []*ga.Region
  10485. for _, obj := range m.Objects {
  10486. if !fl.Match(obj.ToGA()) {
  10487. continue
  10488. }
  10489. objs = append(objs, obj.ToGA())
  10490. }
  10491. klog.V(5).Infof("MockRegions.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  10492. return objs, nil
  10493. }
  10494. // Obj wraps the object for use in the mock.
  10495. func (m *MockRegions) Obj(o *ga.Region) *MockRegionsObj {
  10496. return &MockRegionsObj{o}
  10497. }
  10498. // GCERegions is a simplifying adapter for the GCE Regions.
  10499. type GCERegions struct {
  10500. s *Service
  10501. }
  10502. // Get the Region named by key.
  10503. func (g *GCERegions) Get(ctx context.Context, key *meta.Key) (*ga.Region, error) {
  10504. klog.V(5).Infof("GCERegions.Get(%v, %v): called", ctx, key)
  10505. if !key.Valid() {
  10506. klog.V(2).Infof("GCERegions.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  10507. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  10508. }
  10509. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Regions")
  10510. rk := &RateLimitKey{
  10511. ProjectID: projectID,
  10512. Operation: "Get",
  10513. Version: meta.Version("ga"),
  10514. Service: "Regions",
  10515. }
  10516. klog.V(5).Infof("GCERegions.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10517. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10518. klog.V(4).Infof("GCERegions.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  10519. return nil, err
  10520. }
  10521. call := g.s.GA.Regions.Get(projectID, key.Name)
  10522. call.Context(ctx)
  10523. v, err := call.Do()
  10524. klog.V(4).Infof("GCERegions.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  10525. return v, err
  10526. }
  10527. // List all Region objects.
  10528. func (g *GCERegions) List(ctx context.Context, fl *filter.F) ([]*ga.Region, error) {
  10529. klog.V(5).Infof("GCERegions.List(%v, %v) called", ctx, fl)
  10530. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Regions")
  10531. rk := &RateLimitKey{
  10532. ProjectID: projectID,
  10533. Operation: "List",
  10534. Version: meta.Version("ga"),
  10535. Service: "Regions",
  10536. }
  10537. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10538. return nil, err
  10539. }
  10540. klog.V(5).Infof("GCERegions.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  10541. call := g.s.GA.Regions.List(projectID)
  10542. if fl != filter.None {
  10543. call.Filter(fl.String())
  10544. }
  10545. var all []*ga.Region
  10546. f := func(l *ga.RegionList) error {
  10547. klog.V(5).Infof("GCERegions.List(%v, ..., %v): page %+v", ctx, fl, l)
  10548. all = append(all, l.Items...)
  10549. return nil
  10550. }
  10551. if err := call.Pages(ctx, f); err != nil {
  10552. klog.V(4).Infof("GCERegions.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  10553. return nil, err
  10554. }
  10555. if klog.V(4) {
  10556. klog.V(4).Infof("GCERegions.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  10557. } else if klog.V(5) {
  10558. var asStr []string
  10559. for _, o := range all {
  10560. asStr = append(asStr, fmt.Sprintf("%+v", o))
  10561. }
  10562. klog.V(5).Infof("GCERegions.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  10563. }
  10564. return all, nil
  10565. }
  10566. // Routes is an interface that allows for mocking of Routes.
  10567. type Routes interface {
  10568. Get(ctx context.Context, key *meta.Key) (*ga.Route, error)
  10569. List(ctx context.Context, fl *filter.F) ([]*ga.Route, error)
  10570. Insert(ctx context.Context, key *meta.Key, obj *ga.Route) error
  10571. Delete(ctx context.Context, key *meta.Key) error
  10572. }
  10573. // NewMockRoutes returns a new mock for Routes.
  10574. func NewMockRoutes(pr ProjectRouter, objs map[meta.Key]*MockRoutesObj) *MockRoutes {
  10575. mock := &MockRoutes{
  10576. ProjectRouter: pr,
  10577. Objects: objs,
  10578. GetError: map[meta.Key]error{},
  10579. InsertError: map[meta.Key]error{},
  10580. DeleteError: map[meta.Key]error{},
  10581. }
  10582. return mock
  10583. }
  10584. // MockRoutes is the mock for Routes.
  10585. type MockRoutes struct {
  10586. Lock sync.Mutex
  10587. ProjectRouter ProjectRouter
  10588. // Objects maintained by the mock.
  10589. Objects map[meta.Key]*MockRoutesObj
  10590. // If an entry exists for the given key and operation, then the error
  10591. // will be returned instead of the operation.
  10592. GetError map[meta.Key]error
  10593. ListError *error
  10594. InsertError map[meta.Key]error
  10595. DeleteError map[meta.Key]error
  10596. // xxxHook allow you to intercept the standard processing of the mock in
  10597. // order to add your own logic. Return (true, _, _) to prevent the normal
  10598. // execution flow of the mock. Return (false, nil, nil) to continue with
  10599. // normal mock behavior/ after the hook function executes.
  10600. GetHook func(ctx context.Context, key *meta.Key, m *MockRoutes) (bool, *ga.Route, error)
  10601. ListHook func(ctx context.Context, fl *filter.F, m *MockRoutes) (bool, []*ga.Route, error)
  10602. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.Route, m *MockRoutes) (bool, error)
  10603. DeleteHook func(ctx context.Context, key *meta.Key, m *MockRoutes) (bool, error)
  10604. // X is extra state that can be used as part of the mock. Generated code
  10605. // will not use this field.
  10606. X interface{}
  10607. }
  10608. // Get returns the object from the mock.
  10609. func (m *MockRoutes) Get(ctx context.Context, key *meta.Key) (*ga.Route, error) {
  10610. if m.GetHook != nil {
  10611. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  10612. klog.V(5).Infof("MockRoutes.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  10613. return obj, err
  10614. }
  10615. }
  10616. if !key.Valid() {
  10617. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  10618. }
  10619. m.Lock.Lock()
  10620. defer m.Lock.Unlock()
  10621. if err, ok := m.GetError[*key]; ok {
  10622. klog.V(5).Infof("MockRoutes.Get(%v, %s) = nil, %v", ctx, key, err)
  10623. return nil, err
  10624. }
  10625. if obj, ok := m.Objects[*key]; ok {
  10626. typedObj := obj.ToGA()
  10627. klog.V(5).Infof("MockRoutes.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  10628. return typedObj, nil
  10629. }
  10630. err := &googleapi.Error{
  10631. Code: http.StatusNotFound,
  10632. Message: fmt.Sprintf("MockRoutes %v not found", key),
  10633. }
  10634. klog.V(5).Infof("MockRoutes.Get(%v, %s) = nil, %v", ctx, key, err)
  10635. return nil, err
  10636. }
  10637. // List all of the objects in the mock.
  10638. func (m *MockRoutes) List(ctx context.Context, fl *filter.F) ([]*ga.Route, error) {
  10639. if m.ListHook != nil {
  10640. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  10641. klog.V(5).Infof("MockRoutes.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  10642. return objs, err
  10643. }
  10644. }
  10645. m.Lock.Lock()
  10646. defer m.Lock.Unlock()
  10647. if m.ListError != nil {
  10648. err := *m.ListError
  10649. klog.V(5).Infof("MockRoutes.List(%v, %v) = nil, %v", ctx, fl, err)
  10650. return nil, *m.ListError
  10651. }
  10652. var objs []*ga.Route
  10653. for _, obj := range m.Objects {
  10654. if !fl.Match(obj.ToGA()) {
  10655. continue
  10656. }
  10657. objs = append(objs, obj.ToGA())
  10658. }
  10659. klog.V(5).Infof("MockRoutes.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  10660. return objs, nil
  10661. }
  10662. // Insert is a mock for inserting/creating a new object.
  10663. func (m *MockRoutes) Insert(ctx context.Context, key *meta.Key, obj *ga.Route) error {
  10664. if m.InsertHook != nil {
  10665. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  10666. klog.V(5).Infof("MockRoutes.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  10667. return err
  10668. }
  10669. }
  10670. if !key.Valid() {
  10671. return fmt.Errorf("invalid GCE key (%+v)", key)
  10672. }
  10673. m.Lock.Lock()
  10674. defer m.Lock.Unlock()
  10675. if err, ok := m.InsertError[*key]; ok {
  10676. klog.V(5).Infof("MockRoutes.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  10677. return err
  10678. }
  10679. if _, ok := m.Objects[*key]; ok {
  10680. err := &googleapi.Error{
  10681. Code: http.StatusConflict,
  10682. Message: fmt.Sprintf("MockRoutes %v exists", key),
  10683. }
  10684. klog.V(5).Infof("MockRoutes.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  10685. return err
  10686. }
  10687. obj.Name = key.Name
  10688. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "routes")
  10689. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "routes", key)
  10690. m.Objects[*key] = &MockRoutesObj{obj}
  10691. klog.V(5).Infof("MockRoutes.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  10692. return nil
  10693. }
  10694. // Delete is a mock for deleting the object.
  10695. func (m *MockRoutes) Delete(ctx context.Context, key *meta.Key) error {
  10696. if m.DeleteHook != nil {
  10697. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  10698. klog.V(5).Infof("MockRoutes.Delete(%v, %v) = %v", ctx, key, err)
  10699. return err
  10700. }
  10701. }
  10702. if !key.Valid() {
  10703. return fmt.Errorf("invalid GCE key (%+v)", key)
  10704. }
  10705. m.Lock.Lock()
  10706. defer m.Lock.Unlock()
  10707. if err, ok := m.DeleteError[*key]; ok {
  10708. klog.V(5).Infof("MockRoutes.Delete(%v, %v) = %v", ctx, key, err)
  10709. return err
  10710. }
  10711. if _, ok := m.Objects[*key]; !ok {
  10712. err := &googleapi.Error{
  10713. Code: http.StatusNotFound,
  10714. Message: fmt.Sprintf("MockRoutes %v not found", key),
  10715. }
  10716. klog.V(5).Infof("MockRoutes.Delete(%v, %v) = %v", ctx, key, err)
  10717. return err
  10718. }
  10719. delete(m.Objects, *key)
  10720. klog.V(5).Infof("MockRoutes.Delete(%v, %v) = nil", ctx, key)
  10721. return nil
  10722. }
  10723. // Obj wraps the object for use in the mock.
  10724. func (m *MockRoutes) Obj(o *ga.Route) *MockRoutesObj {
  10725. return &MockRoutesObj{o}
  10726. }
  10727. // GCERoutes is a simplifying adapter for the GCE Routes.
  10728. type GCERoutes struct {
  10729. s *Service
  10730. }
  10731. // Get the Route named by key.
  10732. func (g *GCERoutes) Get(ctx context.Context, key *meta.Key) (*ga.Route, error) {
  10733. klog.V(5).Infof("GCERoutes.Get(%v, %v): called", ctx, key)
  10734. if !key.Valid() {
  10735. klog.V(2).Infof("GCERoutes.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  10736. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  10737. }
  10738. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Routes")
  10739. rk := &RateLimitKey{
  10740. ProjectID: projectID,
  10741. Operation: "Get",
  10742. Version: meta.Version("ga"),
  10743. Service: "Routes",
  10744. }
  10745. klog.V(5).Infof("GCERoutes.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10746. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10747. klog.V(4).Infof("GCERoutes.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  10748. return nil, err
  10749. }
  10750. call := g.s.GA.Routes.Get(projectID, key.Name)
  10751. call.Context(ctx)
  10752. v, err := call.Do()
  10753. klog.V(4).Infof("GCERoutes.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  10754. return v, err
  10755. }
  10756. // List all Route objects.
  10757. func (g *GCERoutes) List(ctx context.Context, fl *filter.F) ([]*ga.Route, error) {
  10758. klog.V(5).Infof("GCERoutes.List(%v, %v) called", ctx, fl)
  10759. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Routes")
  10760. rk := &RateLimitKey{
  10761. ProjectID: projectID,
  10762. Operation: "List",
  10763. Version: meta.Version("ga"),
  10764. Service: "Routes",
  10765. }
  10766. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10767. return nil, err
  10768. }
  10769. klog.V(5).Infof("GCERoutes.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  10770. call := g.s.GA.Routes.List(projectID)
  10771. if fl != filter.None {
  10772. call.Filter(fl.String())
  10773. }
  10774. var all []*ga.Route
  10775. f := func(l *ga.RouteList) error {
  10776. klog.V(5).Infof("GCERoutes.List(%v, ..., %v): page %+v", ctx, fl, l)
  10777. all = append(all, l.Items...)
  10778. return nil
  10779. }
  10780. if err := call.Pages(ctx, f); err != nil {
  10781. klog.V(4).Infof("GCERoutes.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  10782. return nil, err
  10783. }
  10784. if klog.V(4) {
  10785. klog.V(4).Infof("GCERoutes.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  10786. } else if klog.V(5) {
  10787. var asStr []string
  10788. for _, o := range all {
  10789. asStr = append(asStr, fmt.Sprintf("%+v", o))
  10790. }
  10791. klog.V(5).Infof("GCERoutes.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  10792. }
  10793. return all, nil
  10794. }
  10795. // Insert Route with key of value obj.
  10796. func (g *GCERoutes) Insert(ctx context.Context, key *meta.Key, obj *ga.Route) error {
  10797. klog.V(5).Infof("GCERoutes.Insert(%v, %v, %+v): called", ctx, key, obj)
  10798. if !key.Valid() {
  10799. klog.V(2).Infof("GCERoutes.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  10800. return fmt.Errorf("invalid GCE key (%+v)", key)
  10801. }
  10802. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Routes")
  10803. rk := &RateLimitKey{
  10804. ProjectID: projectID,
  10805. Operation: "Insert",
  10806. Version: meta.Version("ga"),
  10807. Service: "Routes",
  10808. }
  10809. klog.V(5).Infof("GCERoutes.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10810. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10811. klog.V(4).Infof("GCERoutes.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  10812. return err
  10813. }
  10814. obj.Name = key.Name
  10815. call := g.s.GA.Routes.Insert(projectID, obj)
  10816. call.Context(ctx)
  10817. op, err := call.Do()
  10818. if err != nil {
  10819. klog.V(4).Infof("GCERoutes.Insert(%v, %v, ...) = %+v", ctx, key, err)
  10820. return err
  10821. }
  10822. err = g.s.WaitForCompletion(ctx, op)
  10823. klog.V(4).Infof("GCERoutes.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  10824. return err
  10825. }
  10826. // Delete the Route referenced by key.
  10827. func (g *GCERoutes) Delete(ctx context.Context, key *meta.Key) error {
  10828. klog.V(5).Infof("GCERoutes.Delete(%v, %v): called", ctx, key)
  10829. if !key.Valid() {
  10830. klog.V(2).Infof("GCERoutes.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  10831. return fmt.Errorf("invalid GCE key (%+v)", key)
  10832. }
  10833. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Routes")
  10834. rk := &RateLimitKey{
  10835. ProjectID: projectID,
  10836. Operation: "Delete",
  10837. Version: meta.Version("ga"),
  10838. Service: "Routes",
  10839. }
  10840. klog.V(5).Infof("GCERoutes.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  10841. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  10842. klog.V(4).Infof("GCERoutes.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  10843. return err
  10844. }
  10845. call := g.s.GA.Routes.Delete(projectID, key.Name)
  10846. call.Context(ctx)
  10847. op, err := call.Do()
  10848. if err != nil {
  10849. klog.V(4).Infof("GCERoutes.Delete(%v, %v) = %v", ctx, key, err)
  10850. return err
  10851. }
  10852. err = g.s.WaitForCompletion(ctx, op)
  10853. klog.V(4).Infof("GCERoutes.Delete(%v, %v) = %v", ctx, key, err)
  10854. return err
  10855. }
  10856. // BetaSecurityPolicies is an interface that allows for mocking of SecurityPolicies.
  10857. type BetaSecurityPolicies interface {
  10858. Get(ctx context.Context, key *meta.Key) (*beta.SecurityPolicy, error)
  10859. List(ctx context.Context, fl *filter.F) ([]*beta.SecurityPolicy, error)
  10860. Insert(ctx context.Context, key *meta.Key, obj *beta.SecurityPolicy) error
  10861. Delete(ctx context.Context, key *meta.Key) error
  10862. AddRule(context.Context, *meta.Key, *beta.SecurityPolicyRule) error
  10863. GetRule(context.Context, *meta.Key) (*beta.SecurityPolicyRule, error)
  10864. Patch(context.Context, *meta.Key, *beta.SecurityPolicy) error
  10865. PatchRule(context.Context, *meta.Key, *beta.SecurityPolicyRule) error
  10866. RemoveRule(context.Context, *meta.Key) error
  10867. }
  10868. // NewMockBetaSecurityPolicies returns a new mock for SecurityPolicies.
  10869. func NewMockBetaSecurityPolicies(pr ProjectRouter, objs map[meta.Key]*MockSecurityPoliciesObj) *MockBetaSecurityPolicies {
  10870. mock := &MockBetaSecurityPolicies{
  10871. ProjectRouter: pr,
  10872. Objects: objs,
  10873. GetError: map[meta.Key]error{},
  10874. InsertError: map[meta.Key]error{},
  10875. DeleteError: map[meta.Key]error{},
  10876. }
  10877. return mock
  10878. }
  10879. // MockBetaSecurityPolicies is the mock for SecurityPolicies.
  10880. type MockBetaSecurityPolicies struct {
  10881. Lock sync.Mutex
  10882. ProjectRouter ProjectRouter
  10883. // Objects maintained by the mock.
  10884. Objects map[meta.Key]*MockSecurityPoliciesObj
  10885. // If an entry exists for the given key and operation, then the error
  10886. // will be returned instead of the operation.
  10887. GetError map[meta.Key]error
  10888. ListError *error
  10889. InsertError map[meta.Key]error
  10890. DeleteError map[meta.Key]error
  10891. // xxxHook allow you to intercept the standard processing of the mock in
  10892. // order to add your own logic. Return (true, _, _) to prevent the normal
  10893. // execution flow of the mock. Return (false, nil, nil) to continue with
  10894. // normal mock behavior/ after the hook function executes.
  10895. GetHook func(ctx context.Context, key *meta.Key, m *MockBetaSecurityPolicies) (bool, *beta.SecurityPolicy, error)
  10896. ListHook func(ctx context.Context, fl *filter.F, m *MockBetaSecurityPolicies) (bool, []*beta.SecurityPolicy, error)
  10897. InsertHook func(ctx context.Context, key *meta.Key, obj *beta.SecurityPolicy, m *MockBetaSecurityPolicies) (bool, error)
  10898. DeleteHook func(ctx context.Context, key *meta.Key, m *MockBetaSecurityPolicies) (bool, error)
  10899. AddRuleHook func(context.Context, *meta.Key, *beta.SecurityPolicyRule, *MockBetaSecurityPolicies) error
  10900. GetRuleHook func(context.Context, *meta.Key, *MockBetaSecurityPolicies) (*beta.SecurityPolicyRule, error)
  10901. PatchHook func(context.Context, *meta.Key, *beta.SecurityPolicy, *MockBetaSecurityPolicies) error
  10902. PatchRuleHook func(context.Context, *meta.Key, *beta.SecurityPolicyRule, *MockBetaSecurityPolicies) error
  10903. RemoveRuleHook func(context.Context, *meta.Key, *MockBetaSecurityPolicies) error
  10904. // X is extra state that can be used as part of the mock. Generated code
  10905. // will not use this field.
  10906. X interface{}
  10907. }
  10908. // Get returns the object from the mock.
  10909. func (m *MockBetaSecurityPolicies) Get(ctx context.Context, key *meta.Key) (*beta.SecurityPolicy, error) {
  10910. if m.GetHook != nil {
  10911. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  10912. klog.V(5).Infof("MockBetaSecurityPolicies.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  10913. return obj, err
  10914. }
  10915. }
  10916. if !key.Valid() {
  10917. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  10918. }
  10919. m.Lock.Lock()
  10920. defer m.Lock.Unlock()
  10921. if err, ok := m.GetError[*key]; ok {
  10922. klog.V(5).Infof("MockBetaSecurityPolicies.Get(%v, %s) = nil, %v", ctx, key, err)
  10923. return nil, err
  10924. }
  10925. if obj, ok := m.Objects[*key]; ok {
  10926. typedObj := obj.ToBeta()
  10927. klog.V(5).Infof("MockBetaSecurityPolicies.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  10928. return typedObj, nil
  10929. }
  10930. err := &googleapi.Error{
  10931. Code: http.StatusNotFound,
  10932. Message: fmt.Sprintf("MockBetaSecurityPolicies %v not found", key),
  10933. }
  10934. klog.V(5).Infof("MockBetaSecurityPolicies.Get(%v, %s) = nil, %v", ctx, key, err)
  10935. return nil, err
  10936. }
  10937. // List all of the objects in the mock.
  10938. func (m *MockBetaSecurityPolicies) List(ctx context.Context, fl *filter.F) ([]*beta.SecurityPolicy, error) {
  10939. if m.ListHook != nil {
  10940. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  10941. klog.V(5).Infof("MockBetaSecurityPolicies.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  10942. return objs, err
  10943. }
  10944. }
  10945. m.Lock.Lock()
  10946. defer m.Lock.Unlock()
  10947. if m.ListError != nil {
  10948. err := *m.ListError
  10949. klog.V(5).Infof("MockBetaSecurityPolicies.List(%v, %v) = nil, %v", ctx, fl, err)
  10950. return nil, *m.ListError
  10951. }
  10952. var objs []*beta.SecurityPolicy
  10953. for _, obj := range m.Objects {
  10954. if !fl.Match(obj.ToBeta()) {
  10955. continue
  10956. }
  10957. objs = append(objs, obj.ToBeta())
  10958. }
  10959. klog.V(5).Infof("MockBetaSecurityPolicies.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  10960. return objs, nil
  10961. }
  10962. // Insert is a mock for inserting/creating a new object.
  10963. func (m *MockBetaSecurityPolicies) Insert(ctx context.Context, key *meta.Key, obj *beta.SecurityPolicy) error {
  10964. if m.InsertHook != nil {
  10965. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  10966. klog.V(5).Infof("MockBetaSecurityPolicies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  10967. return err
  10968. }
  10969. }
  10970. if !key.Valid() {
  10971. return fmt.Errorf("invalid GCE key (%+v)", key)
  10972. }
  10973. m.Lock.Lock()
  10974. defer m.Lock.Unlock()
  10975. if err, ok := m.InsertError[*key]; ok {
  10976. klog.V(5).Infof("MockBetaSecurityPolicies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  10977. return err
  10978. }
  10979. if _, ok := m.Objects[*key]; ok {
  10980. err := &googleapi.Error{
  10981. Code: http.StatusConflict,
  10982. Message: fmt.Sprintf("MockBetaSecurityPolicies %v exists", key),
  10983. }
  10984. klog.V(5).Infof("MockBetaSecurityPolicies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  10985. return err
  10986. }
  10987. obj.Name = key.Name
  10988. projectID := m.ProjectRouter.ProjectID(ctx, "beta", "securityPolicies")
  10989. obj.SelfLink = SelfLink(meta.VersionBeta, projectID, "securityPolicies", key)
  10990. m.Objects[*key] = &MockSecurityPoliciesObj{obj}
  10991. klog.V(5).Infof("MockBetaSecurityPolicies.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  10992. return nil
  10993. }
  10994. // Delete is a mock for deleting the object.
  10995. func (m *MockBetaSecurityPolicies) Delete(ctx context.Context, key *meta.Key) error {
  10996. if m.DeleteHook != nil {
  10997. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  10998. klog.V(5).Infof("MockBetaSecurityPolicies.Delete(%v, %v) = %v", ctx, key, err)
  10999. return err
  11000. }
  11001. }
  11002. if !key.Valid() {
  11003. return fmt.Errorf("invalid GCE key (%+v)", key)
  11004. }
  11005. m.Lock.Lock()
  11006. defer m.Lock.Unlock()
  11007. if err, ok := m.DeleteError[*key]; ok {
  11008. klog.V(5).Infof("MockBetaSecurityPolicies.Delete(%v, %v) = %v", ctx, key, err)
  11009. return err
  11010. }
  11011. if _, ok := m.Objects[*key]; !ok {
  11012. err := &googleapi.Error{
  11013. Code: http.StatusNotFound,
  11014. Message: fmt.Sprintf("MockBetaSecurityPolicies %v not found", key),
  11015. }
  11016. klog.V(5).Infof("MockBetaSecurityPolicies.Delete(%v, %v) = %v", ctx, key, err)
  11017. return err
  11018. }
  11019. delete(m.Objects, *key)
  11020. klog.V(5).Infof("MockBetaSecurityPolicies.Delete(%v, %v) = nil", ctx, key)
  11021. return nil
  11022. }
  11023. // Obj wraps the object for use in the mock.
  11024. func (m *MockBetaSecurityPolicies) Obj(o *beta.SecurityPolicy) *MockSecurityPoliciesObj {
  11025. return &MockSecurityPoliciesObj{o}
  11026. }
  11027. // AddRule is a mock for the corresponding method.
  11028. func (m *MockBetaSecurityPolicies) AddRule(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicyRule) error {
  11029. if m.AddRuleHook != nil {
  11030. return m.AddRuleHook(ctx, key, arg0, m)
  11031. }
  11032. return nil
  11033. }
  11034. // GetRule is a mock for the corresponding method.
  11035. func (m *MockBetaSecurityPolicies) GetRule(ctx context.Context, key *meta.Key) (*beta.SecurityPolicyRule, error) {
  11036. if m.GetRuleHook != nil {
  11037. return m.GetRuleHook(ctx, key, m)
  11038. }
  11039. return nil, fmt.Errorf("GetRuleHook must be set")
  11040. }
  11041. // Patch is a mock for the corresponding method.
  11042. func (m *MockBetaSecurityPolicies) Patch(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicy) error {
  11043. if m.PatchHook != nil {
  11044. return m.PatchHook(ctx, key, arg0, m)
  11045. }
  11046. return nil
  11047. }
  11048. // PatchRule is a mock for the corresponding method.
  11049. func (m *MockBetaSecurityPolicies) PatchRule(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicyRule) error {
  11050. if m.PatchRuleHook != nil {
  11051. return m.PatchRuleHook(ctx, key, arg0, m)
  11052. }
  11053. return nil
  11054. }
  11055. // RemoveRule is a mock for the corresponding method.
  11056. func (m *MockBetaSecurityPolicies) RemoveRule(ctx context.Context, key *meta.Key) error {
  11057. if m.RemoveRuleHook != nil {
  11058. return m.RemoveRuleHook(ctx, key, m)
  11059. }
  11060. return nil
  11061. }
  11062. // GCEBetaSecurityPolicies is a simplifying adapter for the GCE SecurityPolicies.
  11063. type GCEBetaSecurityPolicies struct {
  11064. s *Service
  11065. }
  11066. // Get the SecurityPolicy named by key.
  11067. func (g *GCEBetaSecurityPolicies) Get(ctx context.Context, key *meta.Key) (*beta.SecurityPolicy, error) {
  11068. klog.V(5).Infof("GCEBetaSecurityPolicies.Get(%v, %v): called", ctx, key)
  11069. if !key.Valid() {
  11070. klog.V(2).Infof("GCEBetaSecurityPolicies.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  11071. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  11072. }
  11073. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11074. rk := &RateLimitKey{
  11075. ProjectID: projectID,
  11076. Operation: "Get",
  11077. Version: meta.Version("beta"),
  11078. Service: "SecurityPolicies",
  11079. }
  11080. klog.V(5).Infof("GCEBetaSecurityPolicies.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11081. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11082. klog.V(4).Infof("GCEBetaSecurityPolicies.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  11083. return nil, err
  11084. }
  11085. call := g.s.Beta.SecurityPolicies.Get(projectID, key.Name)
  11086. call.Context(ctx)
  11087. v, err := call.Do()
  11088. klog.V(4).Infof("GCEBetaSecurityPolicies.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  11089. return v, err
  11090. }
  11091. // List all SecurityPolicy objects.
  11092. func (g *GCEBetaSecurityPolicies) List(ctx context.Context, fl *filter.F) ([]*beta.SecurityPolicy, error) {
  11093. klog.V(5).Infof("GCEBetaSecurityPolicies.List(%v, %v) called", ctx, fl)
  11094. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11095. rk := &RateLimitKey{
  11096. ProjectID: projectID,
  11097. Operation: "List",
  11098. Version: meta.Version("beta"),
  11099. Service: "SecurityPolicies",
  11100. }
  11101. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11102. return nil, err
  11103. }
  11104. klog.V(5).Infof("GCEBetaSecurityPolicies.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  11105. call := g.s.Beta.SecurityPolicies.List(projectID)
  11106. if fl != filter.None {
  11107. call.Filter(fl.String())
  11108. }
  11109. var all []*beta.SecurityPolicy
  11110. f := func(l *beta.SecurityPolicyList) error {
  11111. klog.V(5).Infof("GCEBetaSecurityPolicies.List(%v, ..., %v): page %+v", ctx, fl, l)
  11112. all = append(all, l.Items...)
  11113. return nil
  11114. }
  11115. if err := call.Pages(ctx, f); err != nil {
  11116. klog.V(4).Infof("GCEBetaSecurityPolicies.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  11117. return nil, err
  11118. }
  11119. if klog.V(4) {
  11120. klog.V(4).Infof("GCEBetaSecurityPolicies.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  11121. } else if klog.V(5) {
  11122. var asStr []string
  11123. for _, o := range all {
  11124. asStr = append(asStr, fmt.Sprintf("%+v", o))
  11125. }
  11126. klog.V(5).Infof("GCEBetaSecurityPolicies.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  11127. }
  11128. return all, nil
  11129. }
  11130. // Insert SecurityPolicy with key of value obj.
  11131. func (g *GCEBetaSecurityPolicies) Insert(ctx context.Context, key *meta.Key, obj *beta.SecurityPolicy) error {
  11132. klog.V(5).Infof("GCEBetaSecurityPolicies.Insert(%v, %v, %+v): called", ctx, key, obj)
  11133. if !key.Valid() {
  11134. klog.V(2).Infof("GCEBetaSecurityPolicies.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11135. return fmt.Errorf("invalid GCE key (%+v)", key)
  11136. }
  11137. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11138. rk := &RateLimitKey{
  11139. ProjectID: projectID,
  11140. Operation: "Insert",
  11141. Version: meta.Version("beta"),
  11142. Service: "SecurityPolicies",
  11143. }
  11144. klog.V(5).Infof("GCEBetaSecurityPolicies.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11145. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11146. klog.V(4).Infof("GCEBetaSecurityPolicies.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11147. return err
  11148. }
  11149. obj.Name = key.Name
  11150. call := g.s.Beta.SecurityPolicies.Insert(projectID, obj)
  11151. call.Context(ctx)
  11152. op, err := call.Do()
  11153. if err != nil {
  11154. klog.V(4).Infof("GCEBetaSecurityPolicies.Insert(%v, %v, ...) = %+v", ctx, key, err)
  11155. return err
  11156. }
  11157. err = g.s.WaitForCompletion(ctx, op)
  11158. klog.V(4).Infof("GCEBetaSecurityPolicies.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  11159. return err
  11160. }
  11161. // Delete the SecurityPolicy referenced by key.
  11162. func (g *GCEBetaSecurityPolicies) Delete(ctx context.Context, key *meta.Key) error {
  11163. klog.V(5).Infof("GCEBetaSecurityPolicies.Delete(%v, %v): called", ctx, key)
  11164. if !key.Valid() {
  11165. klog.V(2).Infof("GCEBetaSecurityPolicies.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  11166. return fmt.Errorf("invalid GCE key (%+v)", key)
  11167. }
  11168. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11169. rk := &RateLimitKey{
  11170. ProjectID: projectID,
  11171. Operation: "Delete",
  11172. Version: meta.Version("beta"),
  11173. Service: "SecurityPolicies",
  11174. }
  11175. klog.V(5).Infof("GCEBetaSecurityPolicies.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11176. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11177. klog.V(4).Infof("GCEBetaSecurityPolicies.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  11178. return err
  11179. }
  11180. call := g.s.Beta.SecurityPolicies.Delete(projectID, key.Name)
  11181. call.Context(ctx)
  11182. op, err := call.Do()
  11183. if err != nil {
  11184. klog.V(4).Infof("GCEBetaSecurityPolicies.Delete(%v, %v) = %v", ctx, key, err)
  11185. return err
  11186. }
  11187. err = g.s.WaitForCompletion(ctx, op)
  11188. klog.V(4).Infof("GCEBetaSecurityPolicies.Delete(%v, %v) = %v", ctx, key, err)
  11189. return err
  11190. }
  11191. // AddRule is a method on GCEBetaSecurityPolicies.
  11192. func (g *GCEBetaSecurityPolicies) AddRule(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicyRule) error {
  11193. klog.V(5).Infof("GCEBetaSecurityPolicies.AddRule(%v, %v, ...): called", ctx, key)
  11194. if !key.Valid() {
  11195. klog.V(2).Infof("GCEBetaSecurityPolicies.AddRule(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11196. return fmt.Errorf("invalid GCE key (%+v)", key)
  11197. }
  11198. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11199. rk := &RateLimitKey{
  11200. ProjectID: projectID,
  11201. Operation: "AddRule",
  11202. Version: meta.Version("beta"),
  11203. Service: "SecurityPolicies",
  11204. }
  11205. klog.V(5).Infof("GCEBetaSecurityPolicies.AddRule(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11206. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11207. klog.V(4).Infof("GCEBetaSecurityPolicies.AddRule(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11208. return err
  11209. }
  11210. call := g.s.Beta.SecurityPolicies.AddRule(projectID, key.Name, arg0)
  11211. call.Context(ctx)
  11212. op, err := call.Do()
  11213. if err != nil {
  11214. klog.V(4).Infof("GCEBetaSecurityPolicies.AddRule(%v, %v, ...) = %+v", ctx, key, err)
  11215. return err
  11216. }
  11217. err = g.s.WaitForCompletion(ctx, op)
  11218. klog.V(4).Infof("GCEBetaSecurityPolicies.AddRule(%v, %v, ...) = %+v", ctx, key, err)
  11219. return err
  11220. }
  11221. // GetRule is a method on GCEBetaSecurityPolicies.
  11222. func (g *GCEBetaSecurityPolicies) GetRule(ctx context.Context, key *meta.Key) (*beta.SecurityPolicyRule, error) {
  11223. klog.V(5).Infof("GCEBetaSecurityPolicies.GetRule(%v, %v, ...): called", ctx, key)
  11224. if !key.Valid() {
  11225. klog.V(2).Infof("GCEBetaSecurityPolicies.GetRule(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11226. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  11227. }
  11228. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11229. rk := &RateLimitKey{
  11230. ProjectID: projectID,
  11231. Operation: "GetRule",
  11232. Version: meta.Version("beta"),
  11233. Service: "SecurityPolicies",
  11234. }
  11235. klog.V(5).Infof("GCEBetaSecurityPolicies.GetRule(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11236. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11237. klog.V(4).Infof("GCEBetaSecurityPolicies.GetRule(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11238. return nil, err
  11239. }
  11240. call := g.s.Beta.SecurityPolicies.GetRule(projectID, key.Name)
  11241. call.Context(ctx)
  11242. v, err := call.Do()
  11243. klog.V(4).Infof("GCEBetaSecurityPolicies.GetRule(%v, %v, ...) = %+v, %v", ctx, key, v, err)
  11244. return v, err
  11245. }
  11246. // Patch is a method on GCEBetaSecurityPolicies.
  11247. func (g *GCEBetaSecurityPolicies) Patch(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicy) error {
  11248. klog.V(5).Infof("GCEBetaSecurityPolicies.Patch(%v, %v, ...): called", ctx, key)
  11249. if !key.Valid() {
  11250. klog.V(2).Infof("GCEBetaSecurityPolicies.Patch(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11251. return fmt.Errorf("invalid GCE key (%+v)", key)
  11252. }
  11253. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11254. rk := &RateLimitKey{
  11255. ProjectID: projectID,
  11256. Operation: "Patch",
  11257. Version: meta.Version("beta"),
  11258. Service: "SecurityPolicies",
  11259. }
  11260. klog.V(5).Infof("GCEBetaSecurityPolicies.Patch(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11261. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11262. klog.V(4).Infof("GCEBetaSecurityPolicies.Patch(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11263. return err
  11264. }
  11265. call := g.s.Beta.SecurityPolicies.Patch(projectID, key.Name, arg0)
  11266. call.Context(ctx)
  11267. op, err := call.Do()
  11268. if err != nil {
  11269. klog.V(4).Infof("GCEBetaSecurityPolicies.Patch(%v, %v, ...) = %+v", ctx, key, err)
  11270. return err
  11271. }
  11272. err = g.s.WaitForCompletion(ctx, op)
  11273. klog.V(4).Infof("GCEBetaSecurityPolicies.Patch(%v, %v, ...) = %+v", ctx, key, err)
  11274. return err
  11275. }
  11276. // PatchRule is a method on GCEBetaSecurityPolicies.
  11277. func (g *GCEBetaSecurityPolicies) PatchRule(ctx context.Context, key *meta.Key, arg0 *beta.SecurityPolicyRule) error {
  11278. klog.V(5).Infof("GCEBetaSecurityPolicies.PatchRule(%v, %v, ...): called", ctx, key)
  11279. if !key.Valid() {
  11280. klog.V(2).Infof("GCEBetaSecurityPolicies.PatchRule(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11281. return fmt.Errorf("invalid GCE key (%+v)", key)
  11282. }
  11283. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11284. rk := &RateLimitKey{
  11285. ProjectID: projectID,
  11286. Operation: "PatchRule",
  11287. Version: meta.Version("beta"),
  11288. Service: "SecurityPolicies",
  11289. }
  11290. klog.V(5).Infof("GCEBetaSecurityPolicies.PatchRule(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11291. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11292. klog.V(4).Infof("GCEBetaSecurityPolicies.PatchRule(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11293. return err
  11294. }
  11295. call := g.s.Beta.SecurityPolicies.PatchRule(projectID, key.Name, arg0)
  11296. call.Context(ctx)
  11297. op, err := call.Do()
  11298. if err != nil {
  11299. klog.V(4).Infof("GCEBetaSecurityPolicies.PatchRule(%v, %v, ...) = %+v", ctx, key, err)
  11300. return err
  11301. }
  11302. err = g.s.WaitForCompletion(ctx, op)
  11303. klog.V(4).Infof("GCEBetaSecurityPolicies.PatchRule(%v, %v, ...) = %+v", ctx, key, err)
  11304. return err
  11305. }
  11306. // RemoveRule is a method on GCEBetaSecurityPolicies.
  11307. func (g *GCEBetaSecurityPolicies) RemoveRule(ctx context.Context, key *meta.Key) error {
  11308. klog.V(5).Infof("GCEBetaSecurityPolicies.RemoveRule(%v, %v, ...): called", ctx, key)
  11309. if !key.Valid() {
  11310. klog.V(2).Infof("GCEBetaSecurityPolicies.RemoveRule(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11311. return fmt.Errorf("invalid GCE key (%+v)", key)
  11312. }
  11313. projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "SecurityPolicies")
  11314. rk := &RateLimitKey{
  11315. ProjectID: projectID,
  11316. Operation: "RemoveRule",
  11317. Version: meta.Version("beta"),
  11318. Service: "SecurityPolicies",
  11319. }
  11320. klog.V(5).Infof("GCEBetaSecurityPolicies.RemoveRule(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11321. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11322. klog.V(4).Infof("GCEBetaSecurityPolicies.RemoveRule(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11323. return err
  11324. }
  11325. call := g.s.Beta.SecurityPolicies.RemoveRule(projectID, key.Name)
  11326. call.Context(ctx)
  11327. op, err := call.Do()
  11328. if err != nil {
  11329. klog.V(4).Infof("GCEBetaSecurityPolicies.RemoveRule(%v, %v, ...) = %+v", ctx, key, err)
  11330. return err
  11331. }
  11332. err = g.s.WaitForCompletion(ctx, op)
  11333. klog.V(4).Infof("GCEBetaSecurityPolicies.RemoveRule(%v, %v, ...) = %+v", ctx, key, err)
  11334. return err
  11335. }
  11336. // SslCertificates is an interface that allows for mocking of SslCertificates.
  11337. type SslCertificates interface {
  11338. Get(ctx context.Context, key *meta.Key) (*ga.SslCertificate, error)
  11339. List(ctx context.Context, fl *filter.F) ([]*ga.SslCertificate, error)
  11340. Insert(ctx context.Context, key *meta.Key, obj *ga.SslCertificate) error
  11341. Delete(ctx context.Context, key *meta.Key) error
  11342. }
  11343. // NewMockSslCertificates returns a new mock for SslCertificates.
  11344. func NewMockSslCertificates(pr ProjectRouter, objs map[meta.Key]*MockSslCertificatesObj) *MockSslCertificates {
  11345. mock := &MockSslCertificates{
  11346. ProjectRouter: pr,
  11347. Objects: objs,
  11348. GetError: map[meta.Key]error{},
  11349. InsertError: map[meta.Key]error{},
  11350. DeleteError: map[meta.Key]error{},
  11351. }
  11352. return mock
  11353. }
  11354. // MockSslCertificates is the mock for SslCertificates.
  11355. type MockSslCertificates struct {
  11356. Lock sync.Mutex
  11357. ProjectRouter ProjectRouter
  11358. // Objects maintained by the mock.
  11359. Objects map[meta.Key]*MockSslCertificatesObj
  11360. // If an entry exists for the given key and operation, then the error
  11361. // will be returned instead of the operation.
  11362. GetError map[meta.Key]error
  11363. ListError *error
  11364. InsertError map[meta.Key]error
  11365. DeleteError map[meta.Key]error
  11366. // xxxHook allow you to intercept the standard processing of the mock in
  11367. // order to add your own logic. Return (true, _, _) to prevent the normal
  11368. // execution flow of the mock. Return (false, nil, nil) to continue with
  11369. // normal mock behavior/ after the hook function executes.
  11370. GetHook func(ctx context.Context, key *meta.Key, m *MockSslCertificates) (bool, *ga.SslCertificate, error)
  11371. ListHook func(ctx context.Context, fl *filter.F, m *MockSslCertificates) (bool, []*ga.SslCertificate, error)
  11372. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.SslCertificate, m *MockSslCertificates) (bool, error)
  11373. DeleteHook func(ctx context.Context, key *meta.Key, m *MockSslCertificates) (bool, error)
  11374. // X is extra state that can be used as part of the mock. Generated code
  11375. // will not use this field.
  11376. X interface{}
  11377. }
  11378. // Get returns the object from the mock.
  11379. func (m *MockSslCertificates) Get(ctx context.Context, key *meta.Key) (*ga.SslCertificate, error) {
  11380. if m.GetHook != nil {
  11381. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  11382. klog.V(5).Infof("MockSslCertificates.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  11383. return obj, err
  11384. }
  11385. }
  11386. if !key.Valid() {
  11387. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  11388. }
  11389. m.Lock.Lock()
  11390. defer m.Lock.Unlock()
  11391. if err, ok := m.GetError[*key]; ok {
  11392. klog.V(5).Infof("MockSslCertificates.Get(%v, %s) = nil, %v", ctx, key, err)
  11393. return nil, err
  11394. }
  11395. if obj, ok := m.Objects[*key]; ok {
  11396. typedObj := obj.ToGA()
  11397. klog.V(5).Infof("MockSslCertificates.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  11398. return typedObj, nil
  11399. }
  11400. err := &googleapi.Error{
  11401. Code: http.StatusNotFound,
  11402. Message: fmt.Sprintf("MockSslCertificates %v not found", key),
  11403. }
  11404. klog.V(5).Infof("MockSslCertificates.Get(%v, %s) = nil, %v", ctx, key, err)
  11405. return nil, err
  11406. }
  11407. // List all of the objects in the mock.
  11408. func (m *MockSslCertificates) List(ctx context.Context, fl *filter.F) ([]*ga.SslCertificate, error) {
  11409. if m.ListHook != nil {
  11410. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  11411. klog.V(5).Infof("MockSslCertificates.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  11412. return objs, err
  11413. }
  11414. }
  11415. m.Lock.Lock()
  11416. defer m.Lock.Unlock()
  11417. if m.ListError != nil {
  11418. err := *m.ListError
  11419. klog.V(5).Infof("MockSslCertificates.List(%v, %v) = nil, %v", ctx, fl, err)
  11420. return nil, *m.ListError
  11421. }
  11422. var objs []*ga.SslCertificate
  11423. for _, obj := range m.Objects {
  11424. if !fl.Match(obj.ToGA()) {
  11425. continue
  11426. }
  11427. objs = append(objs, obj.ToGA())
  11428. }
  11429. klog.V(5).Infof("MockSslCertificates.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  11430. return objs, nil
  11431. }
  11432. // Insert is a mock for inserting/creating a new object.
  11433. func (m *MockSslCertificates) Insert(ctx context.Context, key *meta.Key, obj *ga.SslCertificate) error {
  11434. if m.InsertHook != nil {
  11435. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  11436. klog.V(5).Infof("MockSslCertificates.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  11437. return err
  11438. }
  11439. }
  11440. if !key.Valid() {
  11441. return fmt.Errorf("invalid GCE key (%+v)", key)
  11442. }
  11443. m.Lock.Lock()
  11444. defer m.Lock.Unlock()
  11445. if err, ok := m.InsertError[*key]; ok {
  11446. klog.V(5).Infof("MockSslCertificates.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  11447. return err
  11448. }
  11449. if _, ok := m.Objects[*key]; ok {
  11450. err := &googleapi.Error{
  11451. Code: http.StatusConflict,
  11452. Message: fmt.Sprintf("MockSslCertificates %v exists", key),
  11453. }
  11454. klog.V(5).Infof("MockSslCertificates.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  11455. return err
  11456. }
  11457. obj.Name = key.Name
  11458. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "sslCertificates")
  11459. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "sslCertificates", key)
  11460. m.Objects[*key] = &MockSslCertificatesObj{obj}
  11461. klog.V(5).Infof("MockSslCertificates.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  11462. return nil
  11463. }
  11464. // Delete is a mock for deleting the object.
  11465. func (m *MockSslCertificates) Delete(ctx context.Context, key *meta.Key) error {
  11466. if m.DeleteHook != nil {
  11467. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  11468. klog.V(5).Infof("MockSslCertificates.Delete(%v, %v) = %v", ctx, key, err)
  11469. return err
  11470. }
  11471. }
  11472. if !key.Valid() {
  11473. return fmt.Errorf("invalid GCE key (%+v)", key)
  11474. }
  11475. m.Lock.Lock()
  11476. defer m.Lock.Unlock()
  11477. if err, ok := m.DeleteError[*key]; ok {
  11478. klog.V(5).Infof("MockSslCertificates.Delete(%v, %v) = %v", ctx, key, err)
  11479. return err
  11480. }
  11481. if _, ok := m.Objects[*key]; !ok {
  11482. err := &googleapi.Error{
  11483. Code: http.StatusNotFound,
  11484. Message: fmt.Sprintf("MockSslCertificates %v not found", key),
  11485. }
  11486. klog.V(5).Infof("MockSslCertificates.Delete(%v, %v) = %v", ctx, key, err)
  11487. return err
  11488. }
  11489. delete(m.Objects, *key)
  11490. klog.V(5).Infof("MockSslCertificates.Delete(%v, %v) = nil", ctx, key)
  11491. return nil
  11492. }
  11493. // Obj wraps the object for use in the mock.
  11494. func (m *MockSslCertificates) Obj(o *ga.SslCertificate) *MockSslCertificatesObj {
  11495. return &MockSslCertificatesObj{o}
  11496. }
  11497. // GCESslCertificates is a simplifying adapter for the GCE SslCertificates.
  11498. type GCESslCertificates struct {
  11499. s *Service
  11500. }
  11501. // Get the SslCertificate named by key.
  11502. func (g *GCESslCertificates) Get(ctx context.Context, key *meta.Key) (*ga.SslCertificate, error) {
  11503. klog.V(5).Infof("GCESslCertificates.Get(%v, %v): called", ctx, key)
  11504. if !key.Valid() {
  11505. klog.V(2).Infof("GCESslCertificates.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  11506. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  11507. }
  11508. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "SslCertificates")
  11509. rk := &RateLimitKey{
  11510. ProjectID: projectID,
  11511. Operation: "Get",
  11512. Version: meta.Version("ga"),
  11513. Service: "SslCertificates",
  11514. }
  11515. klog.V(5).Infof("GCESslCertificates.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11516. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11517. klog.V(4).Infof("GCESslCertificates.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  11518. return nil, err
  11519. }
  11520. call := g.s.GA.SslCertificates.Get(projectID, key.Name)
  11521. call.Context(ctx)
  11522. v, err := call.Do()
  11523. klog.V(4).Infof("GCESslCertificates.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  11524. return v, err
  11525. }
  11526. // List all SslCertificate objects.
  11527. func (g *GCESslCertificates) List(ctx context.Context, fl *filter.F) ([]*ga.SslCertificate, error) {
  11528. klog.V(5).Infof("GCESslCertificates.List(%v, %v) called", ctx, fl)
  11529. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "SslCertificates")
  11530. rk := &RateLimitKey{
  11531. ProjectID: projectID,
  11532. Operation: "List",
  11533. Version: meta.Version("ga"),
  11534. Service: "SslCertificates",
  11535. }
  11536. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11537. return nil, err
  11538. }
  11539. klog.V(5).Infof("GCESslCertificates.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  11540. call := g.s.GA.SslCertificates.List(projectID)
  11541. if fl != filter.None {
  11542. call.Filter(fl.String())
  11543. }
  11544. var all []*ga.SslCertificate
  11545. f := func(l *ga.SslCertificateList) error {
  11546. klog.V(5).Infof("GCESslCertificates.List(%v, ..., %v): page %+v", ctx, fl, l)
  11547. all = append(all, l.Items...)
  11548. return nil
  11549. }
  11550. if err := call.Pages(ctx, f); err != nil {
  11551. klog.V(4).Infof("GCESslCertificates.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  11552. return nil, err
  11553. }
  11554. if klog.V(4) {
  11555. klog.V(4).Infof("GCESslCertificates.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  11556. } else if klog.V(5) {
  11557. var asStr []string
  11558. for _, o := range all {
  11559. asStr = append(asStr, fmt.Sprintf("%+v", o))
  11560. }
  11561. klog.V(5).Infof("GCESslCertificates.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  11562. }
  11563. return all, nil
  11564. }
  11565. // Insert SslCertificate with key of value obj.
  11566. func (g *GCESslCertificates) Insert(ctx context.Context, key *meta.Key, obj *ga.SslCertificate) error {
  11567. klog.V(5).Infof("GCESslCertificates.Insert(%v, %v, %+v): called", ctx, key, obj)
  11568. if !key.Valid() {
  11569. klog.V(2).Infof("GCESslCertificates.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11570. return fmt.Errorf("invalid GCE key (%+v)", key)
  11571. }
  11572. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "SslCertificates")
  11573. rk := &RateLimitKey{
  11574. ProjectID: projectID,
  11575. Operation: "Insert",
  11576. Version: meta.Version("ga"),
  11577. Service: "SslCertificates",
  11578. }
  11579. klog.V(5).Infof("GCESslCertificates.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11580. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11581. klog.V(4).Infof("GCESslCertificates.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11582. return err
  11583. }
  11584. obj.Name = key.Name
  11585. call := g.s.GA.SslCertificates.Insert(projectID, obj)
  11586. call.Context(ctx)
  11587. op, err := call.Do()
  11588. if err != nil {
  11589. klog.V(4).Infof("GCESslCertificates.Insert(%v, %v, ...) = %+v", ctx, key, err)
  11590. return err
  11591. }
  11592. err = g.s.WaitForCompletion(ctx, op)
  11593. klog.V(4).Infof("GCESslCertificates.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  11594. return err
  11595. }
  11596. // Delete the SslCertificate referenced by key.
  11597. func (g *GCESslCertificates) Delete(ctx context.Context, key *meta.Key) error {
  11598. klog.V(5).Infof("GCESslCertificates.Delete(%v, %v): called", ctx, key)
  11599. if !key.Valid() {
  11600. klog.V(2).Infof("GCESslCertificates.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  11601. return fmt.Errorf("invalid GCE key (%+v)", key)
  11602. }
  11603. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "SslCertificates")
  11604. rk := &RateLimitKey{
  11605. ProjectID: projectID,
  11606. Operation: "Delete",
  11607. Version: meta.Version("ga"),
  11608. Service: "SslCertificates",
  11609. }
  11610. klog.V(5).Infof("GCESslCertificates.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11611. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11612. klog.V(4).Infof("GCESslCertificates.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  11613. return err
  11614. }
  11615. call := g.s.GA.SslCertificates.Delete(projectID, key.Name)
  11616. call.Context(ctx)
  11617. op, err := call.Do()
  11618. if err != nil {
  11619. klog.V(4).Infof("GCESslCertificates.Delete(%v, %v) = %v", ctx, key, err)
  11620. return err
  11621. }
  11622. err = g.s.WaitForCompletion(ctx, op)
  11623. klog.V(4).Infof("GCESslCertificates.Delete(%v, %v) = %v", ctx, key, err)
  11624. return err
  11625. }
  11626. // TargetHttpProxies is an interface that allows for mocking of TargetHttpProxies.
  11627. type TargetHttpProxies interface {
  11628. Get(ctx context.Context, key *meta.Key) (*ga.TargetHttpProxy, error)
  11629. List(ctx context.Context, fl *filter.F) ([]*ga.TargetHttpProxy, error)
  11630. Insert(ctx context.Context, key *meta.Key, obj *ga.TargetHttpProxy) error
  11631. Delete(ctx context.Context, key *meta.Key) error
  11632. SetUrlMap(context.Context, *meta.Key, *ga.UrlMapReference) error
  11633. }
  11634. // NewMockTargetHttpProxies returns a new mock for TargetHttpProxies.
  11635. func NewMockTargetHttpProxies(pr ProjectRouter, objs map[meta.Key]*MockTargetHttpProxiesObj) *MockTargetHttpProxies {
  11636. mock := &MockTargetHttpProxies{
  11637. ProjectRouter: pr,
  11638. Objects: objs,
  11639. GetError: map[meta.Key]error{},
  11640. InsertError: map[meta.Key]error{},
  11641. DeleteError: map[meta.Key]error{},
  11642. }
  11643. return mock
  11644. }
  11645. // MockTargetHttpProxies is the mock for TargetHttpProxies.
  11646. type MockTargetHttpProxies struct {
  11647. Lock sync.Mutex
  11648. ProjectRouter ProjectRouter
  11649. // Objects maintained by the mock.
  11650. Objects map[meta.Key]*MockTargetHttpProxiesObj
  11651. // If an entry exists for the given key and operation, then the error
  11652. // will be returned instead of the operation.
  11653. GetError map[meta.Key]error
  11654. ListError *error
  11655. InsertError map[meta.Key]error
  11656. DeleteError map[meta.Key]error
  11657. // xxxHook allow you to intercept the standard processing of the mock in
  11658. // order to add your own logic. Return (true, _, _) to prevent the normal
  11659. // execution flow of the mock. Return (false, nil, nil) to continue with
  11660. // normal mock behavior/ after the hook function executes.
  11661. GetHook func(ctx context.Context, key *meta.Key, m *MockTargetHttpProxies) (bool, *ga.TargetHttpProxy, error)
  11662. ListHook func(ctx context.Context, fl *filter.F, m *MockTargetHttpProxies) (bool, []*ga.TargetHttpProxy, error)
  11663. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.TargetHttpProxy, m *MockTargetHttpProxies) (bool, error)
  11664. DeleteHook func(ctx context.Context, key *meta.Key, m *MockTargetHttpProxies) (bool, error)
  11665. SetUrlMapHook func(context.Context, *meta.Key, *ga.UrlMapReference, *MockTargetHttpProxies) error
  11666. // X is extra state that can be used as part of the mock. Generated code
  11667. // will not use this field.
  11668. X interface{}
  11669. }
  11670. // Get returns the object from the mock.
  11671. func (m *MockTargetHttpProxies) Get(ctx context.Context, key *meta.Key) (*ga.TargetHttpProxy, error) {
  11672. if m.GetHook != nil {
  11673. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  11674. klog.V(5).Infof("MockTargetHttpProxies.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  11675. return obj, err
  11676. }
  11677. }
  11678. if !key.Valid() {
  11679. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  11680. }
  11681. m.Lock.Lock()
  11682. defer m.Lock.Unlock()
  11683. if err, ok := m.GetError[*key]; ok {
  11684. klog.V(5).Infof("MockTargetHttpProxies.Get(%v, %s) = nil, %v", ctx, key, err)
  11685. return nil, err
  11686. }
  11687. if obj, ok := m.Objects[*key]; ok {
  11688. typedObj := obj.ToGA()
  11689. klog.V(5).Infof("MockTargetHttpProxies.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  11690. return typedObj, nil
  11691. }
  11692. err := &googleapi.Error{
  11693. Code: http.StatusNotFound,
  11694. Message: fmt.Sprintf("MockTargetHttpProxies %v not found", key),
  11695. }
  11696. klog.V(5).Infof("MockTargetHttpProxies.Get(%v, %s) = nil, %v", ctx, key, err)
  11697. return nil, err
  11698. }
  11699. // List all of the objects in the mock.
  11700. func (m *MockTargetHttpProxies) List(ctx context.Context, fl *filter.F) ([]*ga.TargetHttpProxy, error) {
  11701. if m.ListHook != nil {
  11702. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  11703. klog.V(5).Infof("MockTargetHttpProxies.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  11704. return objs, err
  11705. }
  11706. }
  11707. m.Lock.Lock()
  11708. defer m.Lock.Unlock()
  11709. if m.ListError != nil {
  11710. err := *m.ListError
  11711. klog.V(5).Infof("MockTargetHttpProxies.List(%v, %v) = nil, %v", ctx, fl, err)
  11712. return nil, *m.ListError
  11713. }
  11714. var objs []*ga.TargetHttpProxy
  11715. for _, obj := range m.Objects {
  11716. if !fl.Match(obj.ToGA()) {
  11717. continue
  11718. }
  11719. objs = append(objs, obj.ToGA())
  11720. }
  11721. klog.V(5).Infof("MockTargetHttpProxies.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  11722. return objs, nil
  11723. }
  11724. // Insert is a mock for inserting/creating a new object.
  11725. func (m *MockTargetHttpProxies) Insert(ctx context.Context, key *meta.Key, obj *ga.TargetHttpProxy) error {
  11726. if m.InsertHook != nil {
  11727. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  11728. klog.V(5).Infof("MockTargetHttpProxies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  11729. return err
  11730. }
  11731. }
  11732. if !key.Valid() {
  11733. return fmt.Errorf("invalid GCE key (%+v)", key)
  11734. }
  11735. m.Lock.Lock()
  11736. defer m.Lock.Unlock()
  11737. if err, ok := m.InsertError[*key]; ok {
  11738. klog.V(5).Infof("MockTargetHttpProxies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  11739. return err
  11740. }
  11741. if _, ok := m.Objects[*key]; ok {
  11742. err := &googleapi.Error{
  11743. Code: http.StatusConflict,
  11744. Message: fmt.Sprintf("MockTargetHttpProxies %v exists", key),
  11745. }
  11746. klog.V(5).Infof("MockTargetHttpProxies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  11747. return err
  11748. }
  11749. obj.Name = key.Name
  11750. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "targetHttpProxies")
  11751. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "targetHttpProxies", key)
  11752. m.Objects[*key] = &MockTargetHttpProxiesObj{obj}
  11753. klog.V(5).Infof("MockTargetHttpProxies.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  11754. return nil
  11755. }
  11756. // Delete is a mock for deleting the object.
  11757. func (m *MockTargetHttpProxies) Delete(ctx context.Context, key *meta.Key) error {
  11758. if m.DeleteHook != nil {
  11759. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  11760. klog.V(5).Infof("MockTargetHttpProxies.Delete(%v, %v) = %v", ctx, key, err)
  11761. return err
  11762. }
  11763. }
  11764. if !key.Valid() {
  11765. return fmt.Errorf("invalid GCE key (%+v)", key)
  11766. }
  11767. m.Lock.Lock()
  11768. defer m.Lock.Unlock()
  11769. if err, ok := m.DeleteError[*key]; ok {
  11770. klog.V(5).Infof("MockTargetHttpProxies.Delete(%v, %v) = %v", ctx, key, err)
  11771. return err
  11772. }
  11773. if _, ok := m.Objects[*key]; !ok {
  11774. err := &googleapi.Error{
  11775. Code: http.StatusNotFound,
  11776. Message: fmt.Sprintf("MockTargetHttpProxies %v not found", key),
  11777. }
  11778. klog.V(5).Infof("MockTargetHttpProxies.Delete(%v, %v) = %v", ctx, key, err)
  11779. return err
  11780. }
  11781. delete(m.Objects, *key)
  11782. klog.V(5).Infof("MockTargetHttpProxies.Delete(%v, %v) = nil", ctx, key)
  11783. return nil
  11784. }
  11785. // Obj wraps the object for use in the mock.
  11786. func (m *MockTargetHttpProxies) Obj(o *ga.TargetHttpProxy) *MockTargetHttpProxiesObj {
  11787. return &MockTargetHttpProxiesObj{o}
  11788. }
  11789. // SetUrlMap is a mock for the corresponding method.
  11790. func (m *MockTargetHttpProxies) SetUrlMap(ctx context.Context, key *meta.Key, arg0 *ga.UrlMapReference) error {
  11791. if m.SetUrlMapHook != nil {
  11792. return m.SetUrlMapHook(ctx, key, arg0, m)
  11793. }
  11794. return nil
  11795. }
  11796. // GCETargetHttpProxies is a simplifying adapter for the GCE TargetHttpProxies.
  11797. type GCETargetHttpProxies struct {
  11798. s *Service
  11799. }
  11800. // Get the TargetHttpProxy named by key.
  11801. func (g *GCETargetHttpProxies) Get(ctx context.Context, key *meta.Key) (*ga.TargetHttpProxy, error) {
  11802. klog.V(5).Infof("GCETargetHttpProxies.Get(%v, %v): called", ctx, key)
  11803. if !key.Valid() {
  11804. klog.V(2).Infof("GCETargetHttpProxies.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  11805. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  11806. }
  11807. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpProxies")
  11808. rk := &RateLimitKey{
  11809. ProjectID: projectID,
  11810. Operation: "Get",
  11811. Version: meta.Version("ga"),
  11812. Service: "TargetHttpProxies",
  11813. }
  11814. klog.V(5).Infof("GCETargetHttpProxies.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11815. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11816. klog.V(4).Infof("GCETargetHttpProxies.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  11817. return nil, err
  11818. }
  11819. call := g.s.GA.TargetHttpProxies.Get(projectID, key.Name)
  11820. call.Context(ctx)
  11821. v, err := call.Do()
  11822. klog.V(4).Infof("GCETargetHttpProxies.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  11823. return v, err
  11824. }
  11825. // List all TargetHttpProxy objects.
  11826. func (g *GCETargetHttpProxies) List(ctx context.Context, fl *filter.F) ([]*ga.TargetHttpProxy, error) {
  11827. klog.V(5).Infof("GCETargetHttpProxies.List(%v, %v) called", ctx, fl)
  11828. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpProxies")
  11829. rk := &RateLimitKey{
  11830. ProjectID: projectID,
  11831. Operation: "List",
  11832. Version: meta.Version("ga"),
  11833. Service: "TargetHttpProxies",
  11834. }
  11835. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11836. return nil, err
  11837. }
  11838. klog.V(5).Infof("GCETargetHttpProxies.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  11839. call := g.s.GA.TargetHttpProxies.List(projectID)
  11840. if fl != filter.None {
  11841. call.Filter(fl.String())
  11842. }
  11843. var all []*ga.TargetHttpProxy
  11844. f := func(l *ga.TargetHttpProxyList) error {
  11845. klog.V(5).Infof("GCETargetHttpProxies.List(%v, ..., %v): page %+v", ctx, fl, l)
  11846. all = append(all, l.Items...)
  11847. return nil
  11848. }
  11849. if err := call.Pages(ctx, f); err != nil {
  11850. klog.V(4).Infof("GCETargetHttpProxies.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  11851. return nil, err
  11852. }
  11853. if klog.V(4) {
  11854. klog.V(4).Infof("GCETargetHttpProxies.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  11855. } else if klog.V(5) {
  11856. var asStr []string
  11857. for _, o := range all {
  11858. asStr = append(asStr, fmt.Sprintf("%+v", o))
  11859. }
  11860. klog.V(5).Infof("GCETargetHttpProxies.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  11861. }
  11862. return all, nil
  11863. }
  11864. // Insert TargetHttpProxy with key of value obj.
  11865. func (g *GCETargetHttpProxies) Insert(ctx context.Context, key *meta.Key, obj *ga.TargetHttpProxy) error {
  11866. klog.V(5).Infof("GCETargetHttpProxies.Insert(%v, %v, %+v): called", ctx, key, obj)
  11867. if !key.Valid() {
  11868. klog.V(2).Infof("GCETargetHttpProxies.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11869. return fmt.Errorf("invalid GCE key (%+v)", key)
  11870. }
  11871. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpProxies")
  11872. rk := &RateLimitKey{
  11873. ProjectID: projectID,
  11874. Operation: "Insert",
  11875. Version: meta.Version("ga"),
  11876. Service: "TargetHttpProxies",
  11877. }
  11878. klog.V(5).Infof("GCETargetHttpProxies.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11879. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11880. klog.V(4).Infof("GCETargetHttpProxies.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11881. return err
  11882. }
  11883. obj.Name = key.Name
  11884. call := g.s.GA.TargetHttpProxies.Insert(projectID, obj)
  11885. call.Context(ctx)
  11886. op, err := call.Do()
  11887. if err != nil {
  11888. klog.V(4).Infof("GCETargetHttpProxies.Insert(%v, %v, ...) = %+v", ctx, key, err)
  11889. return err
  11890. }
  11891. err = g.s.WaitForCompletion(ctx, op)
  11892. klog.V(4).Infof("GCETargetHttpProxies.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  11893. return err
  11894. }
  11895. // Delete the TargetHttpProxy referenced by key.
  11896. func (g *GCETargetHttpProxies) Delete(ctx context.Context, key *meta.Key) error {
  11897. klog.V(5).Infof("GCETargetHttpProxies.Delete(%v, %v): called", ctx, key)
  11898. if !key.Valid() {
  11899. klog.V(2).Infof("GCETargetHttpProxies.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  11900. return fmt.Errorf("invalid GCE key (%+v)", key)
  11901. }
  11902. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpProxies")
  11903. rk := &RateLimitKey{
  11904. ProjectID: projectID,
  11905. Operation: "Delete",
  11906. Version: meta.Version("ga"),
  11907. Service: "TargetHttpProxies",
  11908. }
  11909. klog.V(5).Infof("GCETargetHttpProxies.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11910. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11911. klog.V(4).Infof("GCETargetHttpProxies.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  11912. return err
  11913. }
  11914. call := g.s.GA.TargetHttpProxies.Delete(projectID, key.Name)
  11915. call.Context(ctx)
  11916. op, err := call.Do()
  11917. if err != nil {
  11918. klog.V(4).Infof("GCETargetHttpProxies.Delete(%v, %v) = %v", ctx, key, err)
  11919. return err
  11920. }
  11921. err = g.s.WaitForCompletion(ctx, op)
  11922. klog.V(4).Infof("GCETargetHttpProxies.Delete(%v, %v) = %v", ctx, key, err)
  11923. return err
  11924. }
  11925. // SetUrlMap is a method on GCETargetHttpProxies.
  11926. func (g *GCETargetHttpProxies) SetUrlMap(ctx context.Context, key *meta.Key, arg0 *ga.UrlMapReference) error {
  11927. klog.V(5).Infof("GCETargetHttpProxies.SetUrlMap(%v, %v, ...): called", ctx, key)
  11928. if !key.Valid() {
  11929. klog.V(2).Infof("GCETargetHttpProxies.SetUrlMap(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  11930. return fmt.Errorf("invalid GCE key (%+v)", key)
  11931. }
  11932. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpProxies")
  11933. rk := &RateLimitKey{
  11934. ProjectID: projectID,
  11935. Operation: "SetUrlMap",
  11936. Version: meta.Version("ga"),
  11937. Service: "TargetHttpProxies",
  11938. }
  11939. klog.V(5).Infof("GCETargetHttpProxies.SetUrlMap(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  11940. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  11941. klog.V(4).Infof("GCETargetHttpProxies.SetUrlMap(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  11942. return err
  11943. }
  11944. call := g.s.GA.TargetHttpProxies.SetUrlMap(projectID, key.Name, arg0)
  11945. call.Context(ctx)
  11946. op, err := call.Do()
  11947. if err != nil {
  11948. klog.V(4).Infof("GCETargetHttpProxies.SetUrlMap(%v, %v, ...) = %+v", ctx, key, err)
  11949. return err
  11950. }
  11951. err = g.s.WaitForCompletion(ctx, op)
  11952. klog.V(4).Infof("GCETargetHttpProxies.SetUrlMap(%v, %v, ...) = %+v", ctx, key, err)
  11953. return err
  11954. }
  11955. // TargetHttpsProxies is an interface that allows for mocking of TargetHttpsProxies.
  11956. type TargetHttpsProxies interface {
  11957. Get(ctx context.Context, key *meta.Key) (*ga.TargetHttpsProxy, error)
  11958. List(ctx context.Context, fl *filter.F) ([]*ga.TargetHttpsProxy, error)
  11959. Insert(ctx context.Context, key *meta.Key, obj *ga.TargetHttpsProxy) error
  11960. Delete(ctx context.Context, key *meta.Key) error
  11961. SetSslCertificates(context.Context, *meta.Key, *ga.TargetHttpsProxiesSetSslCertificatesRequest) error
  11962. SetUrlMap(context.Context, *meta.Key, *ga.UrlMapReference) error
  11963. }
  11964. // NewMockTargetHttpsProxies returns a new mock for TargetHttpsProxies.
  11965. func NewMockTargetHttpsProxies(pr ProjectRouter, objs map[meta.Key]*MockTargetHttpsProxiesObj) *MockTargetHttpsProxies {
  11966. mock := &MockTargetHttpsProxies{
  11967. ProjectRouter: pr,
  11968. Objects: objs,
  11969. GetError: map[meta.Key]error{},
  11970. InsertError: map[meta.Key]error{},
  11971. DeleteError: map[meta.Key]error{},
  11972. }
  11973. return mock
  11974. }
  11975. // MockTargetHttpsProxies is the mock for TargetHttpsProxies.
  11976. type MockTargetHttpsProxies struct {
  11977. Lock sync.Mutex
  11978. ProjectRouter ProjectRouter
  11979. // Objects maintained by the mock.
  11980. Objects map[meta.Key]*MockTargetHttpsProxiesObj
  11981. // If an entry exists for the given key and operation, then the error
  11982. // will be returned instead of the operation.
  11983. GetError map[meta.Key]error
  11984. ListError *error
  11985. InsertError map[meta.Key]error
  11986. DeleteError map[meta.Key]error
  11987. // xxxHook allow you to intercept the standard processing of the mock in
  11988. // order to add your own logic. Return (true, _, _) to prevent the normal
  11989. // execution flow of the mock. Return (false, nil, nil) to continue with
  11990. // normal mock behavior/ after the hook function executes.
  11991. GetHook func(ctx context.Context, key *meta.Key, m *MockTargetHttpsProxies) (bool, *ga.TargetHttpsProxy, error)
  11992. ListHook func(ctx context.Context, fl *filter.F, m *MockTargetHttpsProxies) (bool, []*ga.TargetHttpsProxy, error)
  11993. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.TargetHttpsProxy, m *MockTargetHttpsProxies) (bool, error)
  11994. DeleteHook func(ctx context.Context, key *meta.Key, m *MockTargetHttpsProxies) (bool, error)
  11995. SetSslCertificatesHook func(context.Context, *meta.Key, *ga.TargetHttpsProxiesSetSslCertificatesRequest, *MockTargetHttpsProxies) error
  11996. SetUrlMapHook func(context.Context, *meta.Key, *ga.UrlMapReference, *MockTargetHttpsProxies) error
  11997. // X is extra state that can be used as part of the mock. Generated code
  11998. // will not use this field.
  11999. X interface{}
  12000. }
  12001. // Get returns the object from the mock.
  12002. func (m *MockTargetHttpsProxies) Get(ctx context.Context, key *meta.Key) (*ga.TargetHttpsProxy, error) {
  12003. if m.GetHook != nil {
  12004. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  12005. klog.V(5).Infof("MockTargetHttpsProxies.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  12006. return obj, err
  12007. }
  12008. }
  12009. if !key.Valid() {
  12010. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  12011. }
  12012. m.Lock.Lock()
  12013. defer m.Lock.Unlock()
  12014. if err, ok := m.GetError[*key]; ok {
  12015. klog.V(5).Infof("MockTargetHttpsProxies.Get(%v, %s) = nil, %v", ctx, key, err)
  12016. return nil, err
  12017. }
  12018. if obj, ok := m.Objects[*key]; ok {
  12019. typedObj := obj.ToGA()
  12020. klog.V(5).Infof("MockTargetHttpsProxies.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  12021. return typedObj, nil
  12022. }
  12023. err := &googleapi.Error{
  12024. Code: http.StatusNotFound,
  12025. Message: fmt.Sprintf("MockTargetHttpsProxies %v not found", key),
  12026. }
  12027. klog.V(5).Infof("MockTargetHttpsProxies.Get(%v, %s) = nil, %v", ctx, key, err)
  12028. return nil, err
  12029. }
  12030. // List all of the objects in the mock.
  12031. func (m *MockTargetHttpsProxies) List(ctx context.Context, fl *filter.F) ([]*ga.TargetHttpsProxy, error) {
  12032. if m.ListHook != nil {
  12033. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  12034. klog.V(5).Infof("MockTargetHttpsProxies.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  12035. return objs, err
  12036. }
  12037. }
  12038. m.Lock.Lock()
  12039. defer m.Lock.Unlock()
  12040. if m.ListError != nil {
  12041. err := *m.ListError
  12042. klog.V(5).Infof("MockTargetHttpsProxies.List(%v, %v) = nil, %v", ctx, fl, err)
  12043. return nil, *m.ListError
  12044. }
  12045. var objs []*ga.TargetHttpsProxy
  12046. for _, obj := range m.Objects {
  12047. if !fl.Match(obj.ToGA()) {
  12048. continue
  12049. }
  12050. objs = append(objs, obj.ToGA())
  12051. }
  12052. klog.V(5).Infof("MockTargetHttpsProxies.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  12053. return objs, nil
  12054. }
  12055. // Insert is a mock for inserting/creating a new object.
  12056. func (m *MockTargetHttpsProxies) Insert(ctx context.Context, key *meta.Key, obj *ga.TargetHttpsProxy) error {
  12057. if m.InsertHook != nil {
  12058. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  12059. klog.V(5).Infof("MockTargetHttpsProxies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12060. return err
  12061. }
  12062. }
  12063. if !key.Valid() {
  12064. return fmt.Errorf("invalid GCE key (%+v)", key)
  12065. }
  12066. m.Lock.Lock()
  12067. defer m.Lock.Unlock()
  12068. if err, ok := m.InsertError[*key]; ok {
  12069. klog.V(5).Infof("MockTargetHttpsProxies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12070. return err
  12071. }
  12072. if _, ok := m.Objects[*key]; ok {
  12073. err := &googleapi.Error{
  12074. Code: http.StatusConflict,
  12075. Message: fmt.Sprintf("MockTargetHttpsProxies %v exists", key),
  12076. }
  12077. klog.V(5).Infof("MockTargetHttpsProxies.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12078. return err
  12079. }
  12080. obj.Name = key.Name
  12081. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "targetHttpsProxies")
  12082. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "targetHttpsProxies", key)
  12083. m.Objects[*key] = &MockTargetHttpsProxiesObj{obj}
  12084. klog.V(5).Infof("MockTargetHttpsProxies.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  12085. return nil
  12086. }
  12087. // Delete is a mock for deleting the object.
  12088. func (m *MockTargetHttpsProxies) Delete(ctx context.Context, key *meta.Key) error {
  12089. if m.DeleteHook != nil {
  12090. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  12091. klog.V(5).Infof("MockTargetHttpsProxies.Delete(%v, %v) = %v", ctx, key, err)
  12092. return err
  12093. }
  12094. }
  12095. if !key.Valid() {
  12096. return fmt.Errorf("invalid GCE key (%+v)", key)
  12097. }
  12098. m.Lock.Lock()
  12099. defer m.Lock.Unlock()
  12100. if err, ok := m.DeleteError[*key]; ok {
  12101. klog.V(5).Infof("MockTargetHttpsProxies.Delete(%v, %v) = %v", ctx, key, err)
  12102. return err
  12103. }
  12104. if _, ok := m.Objects[*key]; !ok {
  12105. err := &googleapi.Error{
  12106. Code: http.StatusNotFound,
  12107. Message: fmt.Sprintf("MockTargetHttpsProxies %v not found", key),
  12108. }
  12109. klog.V(5).Infof("MockTargetHttpsProxies.Delete(%v, %v) = %v", ctx, key, err)
  12110. return err
  12111. }
  12112. delete(m.Objects, *key)
  12113. klog.V(5).Infof("MockTargetHttpsProxies.Delete(%v, %v) = nil", ctx, key)
  12114. return nil
  12115. }
  12116. // Obj wraps the object for use in the mock.
  12117. func (m *MockTargetHttpsProxies) Obj(o *ga.TargetHttpsProxy) *MockTargetHttpsProxiesObj {
  12118. return &MockTargetHttpsProxiesObj{o}
  12119. }
  12120. // SetSslCertificates is a mock for the corresponding method.
  12121. func (m *MockTargetHttpsProxies) SetSslCertificates(ctx context.Context, key *meta.Key, arg0 *ga.TargetHttpsProxiesSetSslCertificatesRequest) error {
  12122. if m.SetSslCertificatesHook != nil {
  12123. return m.SetSslCertificatesHook(ctx, key, arg0, m)
  12124. }
  12125. return nil
  12126. }
  12127. // SetUrlMap is a mock for the corresponding method.
  12128. func (m *MockTargetHttpsProxies) SetUrlMap(ctx context.Context, key *meta.Key, arg0 *ga.UrlMapReference) error {
  12129. if m.SetUrlMapHook != nil {
  12130. return m.SetUrlMapHook(ctx, key, arg0, m)
  12131. }
  12132. return nil
  12133. }
  12134. // GCETargetHttpsProxies is a simplifying adapter for the GCE TargetHttpsProxies.
  12135. type GCETargetHttpsProxies struct {
  12136. s *Service
  12137. }
  12138. // Get the TargetHttpsProxy named by key.
  12139. func (g *GCETargetHttpsProxies) Get(ctx context.Context, key *meta.Key) (*ga.TargetHttpsProxy, error) {
  12140. klog.V(5).Infof("GCETargetHttpsProxies.Get(%v, %v): called", ctx, key)
  12141. if !key.Valid() {
  12142. klog.V(2).Infof("GCETargetHttpsProxies.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  12143. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  12144. }
  12145. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpsProxies")
  12146. rk := &RateLimitKey{
  12147. ProjectID: projectID,
  12148. Operation: "Get",
  12149. Version: meta.Version("ga"),
  12150. Service: "TargetHttpsProxies",
  12151. }
  12152. klog.V(5).Infof("GCETargetHttpsProxies.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12153. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12154. klog.V(4).Infof("GCETargetHttpsProxies.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  12155. return nil, err
  12156. }
  12157. call := g.s.GA.TargetHttpsProxies.Get(projectID, key.Name)
  12158. call.Context(ctx)
  12159. v, err := call.Do()
  12160. klog.V(4).Infof("GCETargetHttpsProxies.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  12161. return v, err
  12162. }
  12163. // List all TargetHttpsProxy objects.
  12164. func (g *GCETargetHttpsProxies) List(ctx context.Context, fl *filter.F) ([]*ga.TargetHttpsProxy, error) {
  12165. klog.V(5).Infof("GCETargetHttpsProxies.List(%v, %v) called", ctx, fl)
  12166. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpsProxies")
  12167. rk := &RateLimitKey{
  12168. ProjectID: projectID,
  12169. Operation: "List",
  12170. Version: meta.Version("ga"),
  12171. Service: "TargetHttpsProxies",
  12172. }
  12173. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12174. return nil, err
  12175. }
  12176. klog.V(5).Infof("GCETargetHttpsProxies.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  12177. call := g.s.GA.TargetHttpsProxies.List(projectID)
  12178. if fl != filter.None {
  12179. call.Filter(fl.String())
  12180. }
  12181. var all []*ga.TargetHttpsProxy
  12182. f := func(l *ga.TargetHttpsProxyList) error {
  12183. klog.V(5).Infof("GCETargetHttpsProxies.List(%v, ..., %v): page %+v", ctx, fl, l)
  12184. all = append(all, l.Items...)
  12185. return nil
  12186. }
  12187. if err := call.Pages(ctx, f); err != nil {
  12188. klog.V(4).Infof("GCETargetHttpsProxies.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  12189. return nil, err
  12190. }
  12191. if klog.V(4) {
  12192. klog.V(4).Infof("GCETargetHttpsProxies.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  12193. } else if klog.V(5) {
  12194. var asStr []string
  12195. for _, o := range all {
  12196. asStr = append(asStr, fmt.Sprintf("%+v", o))
  12197. }
  12198. klog.V(5).Infof("GCETargetHttpsProxies.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  12199. }
  12200. return all, nil
  12201. }
  12202. // Insert TargetHttpsProxy with key of value obj.
  12203. func (g *GCETargetHttpsProxies) Insert(ctx context.Context, key *meta.Key, obj *ga.TargetHttpsProxy) error {
  12204. klog.V(5).Infof("GCETargetHttpsProxies.Insert(%v, %v, %+v): called", ctx, key, obj)
  12205. if !key.Valid() {
  12206. klog.V(2).Infof("GCETargetHttpsProxies.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12207. return fmt.Errorf("invalid GCE key (%+v)", key)
  12208. }
  12209. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpsProxies")
  12210. rk := &RateLimitKey{
  12211. ProjectID: projectID,
  12212. Operation: "Insert",
  12213. Version: meta.Version("ga"),
  12214. Service: "TargetHttpsProxies",
  12215. }
  12216. klog.V(5).Infof("GCETargetHttpsProxies.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12217. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12218. klog.V(4).Infof("GCETargetHttpsProxies.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  12219. return err
  12220. }
  12221. obj.Name = key.Name
  12222. call := g.s.GA.TargetHttpsProxies.Insert(projectID, obj)
  12223. call.Context(ctx)
  12224. op, err := call.Do()
  12225. if err != nil {
  12226. klog.V(4).Infof("GCETargetHttpsProxies.Insert(%v, %v, ...) = %+v", ctx, key, err)
  12227. return err
  12228. }
  12229. err = g.s.WaitForCompletion(ctx, op)
  12230. klog.V(4).Infof("GCETargetHttpsProxies.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  12231. return err
  12232. }
  12233. // Delete the TargetHttpsProxy referenced by key.
  12234. func (g *GCETargetHttpsProxies) Delete(ctx context.Context, key *meta.Key) error {
  12235. klog.V(5).Infof("GCETargetHttpsProxies.Delete(%v, %v): called", ctx, key)
  12236. if !key.Valid() {
  12237. klog.V(2).Infof("GCETargetHttpsProxies.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  12238. return fmt.Errorf("invalid GCE key (%+v)", key)
  12239. }
  12240. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpsProxies")
  12241. rk := &RateLimitKey{
  12242. ProjectID: projectID,
  12243. Operation: "Delete",
  12244. Version: meta.Version("ga"),
  12245. Service: "TargetHttpsProxies",
  12246. }
  12247. klog.V(5).Infof("GCETargetHttpsProxies.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12248. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12249. klog.V(4).Infof("GCETargetHttpsProxies.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  12250. return err
  12251. }
  12252. call := g.s.GA.TargetHttpsProxies.Delete(projectID, key.Name)
  12253. call.Context(ctx)
  12254. op, err := call.Do()
  12255. if err != nil {
  12256. klog.V(4).Infof("GCETargetHttpsProxies.Delete(%v, %v) = %v", ctx, key, err)
  12257. return err
  12258. }
  12259. err = g.s.WaitForCompletion(ctx, op)
  12260. klog.V(4).Infof("GCETargetHttpsProxies.Delete(%v, %v) = %v", ctx, key, err)
  12261. return err
  12262. }
  12263. // SetSslCertificates is a method on GCETargetHttpsProxies.
  12264. func (g *GCETargetHttpsProxies) SetSslCertificates(ctx context.Context, key *meta.Key, arg0 *ga.TargetHttpsProxiesSetSslCertificatesRequest) error {
  12265. klog.V(5).Infof("GCETargetHttpsProxies.SetSslCertificates(%v, %v, ...): called", ctx, key)
  12266. if !key.Valid() {
  12267. klog.V(2).Infof("GCETargetHttpsProxies.SetSslCertificates(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12268. return fmt.Errorf("invalid GCE key (%+v)", key)
  12269. }
  12270. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpsProxies")
  12271. rk := &RateLimitKey{
  12272. ProjectID: projectID,
  12273. Operation: "SetSslCertificates",
  12274. Version: meta.Version("ga"),
  12275. Service: "TargetHttpsProxies",
  12276. }
  12277. klog.V(5).Infof("GCETargetHttpsProxies.SetSslCertificates(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12278. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12279. klog.V(4).Infof("GCETargetHttpsProxies.SetSslCertificates(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  12280. return err
  12281. }
  12282. call := g.s.GA.TargetHttpsProxies.SetSslCertificates(projectID, key.Name, arg0)
  12283. call.Context(ctx)
  12284. op, err := call.Do()
  12285. if err != nil {
  12286. klog.V(4).Infof("GCETargetHttpsProxies.SetSslCertificates(%v, %v, ...) = %+v", ctx, key, err)
  12287. return err
  12288. }
  12289. err = g.s.WaitForCompletion(ctx, op)
  12290. klog.V(4).Infof("GCETargetHttpsProxies.SetSslCertificates(%v, %v, ...) = %+v", ctx, key, err)
  12291. return err
  12292. }
  12293. // SetUrlMap is a method on GCETargetHttpsProxies.
  12294. func (g *GCETargetHttpsProxies) SetUrlMap(ctx context.Context, key *meta.Key, arg0 *ga.UrlMapReference) error {
  12295. klog.V(5).Infof("GCETargetHttpsProxies.SetUrlMap(%v, %v, ...): called", ctx, key)
  12296. if !key.Valid() {
  12297. klog.V(2).Infof("GCETargetHttpsProxies.SetUrlMap(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12298. return fmt.Errorf("invalid GCE key (%+v)", key)
  12299. }
  12300. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetHttpsProxies")
  12301. rk := &RateLimitKey{
  12302. ProjectID: projectID,
  12303. Operation: "SetUrlMap",
  12304. Version: meta.Version("ga"),
  12305. Service: "TargetHttpsProxies",
  12306. }
  12307. klog.V(5).Infof("GCETargetHttpsProxies.SetUrlMap(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12308. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12309. klog.V(4).Infof("GCETargetHttpsProxies.SetUrlMap(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  12310. return err
  12311. }
  12312. call := g.s.GA.TargetHttpsProxies.SetUrlMap(projectID, key.Name, arg0)
  12313. call.Context(ctx)
  12314. op, err := call.Do()
  12315. if err != nil {
  12316. klog.V(4).Infof("GCETargetHttpsProxies.SetUrlMap(%v, %v, ...) = %+v", ctx, key, err)
  12317. return err
  12318. }
  12319. err = g.s.WaitForCompletion(ctx, op)
  12320. klog.V(4).Infof("GCETargetHttpsProxies.SetUrlMap(%v, %v, ...) = %+v", ctx, key, err)
  12321. return err
  12322. }
  12323. // TargetPools is an interface that allows for mocking of TargetPools.
  12324. type TargetPools interface {
  12325. Get(ctx context.Context, key *meta.Key) (*ga.TargetPool, error)
  12326. List(ctx context.Context, region string, fl *filter.F) ([]*ga.TargetPool, error)
  12327. Insert(ctx context.Context, key *meta.Key, obj *ga.TargetPool) error
  12328. Delete(ctx context.Context, key *meta.Key) error
  12329. AddInstance(context.Context, *meta.Key, *ga.TargetPoolsAddInstanceRequest) error
  12330. RemoveInstance(context.Context, *meta.Key, *ga.TargetPoolsRemoveInstanceRequest) error
  12331. }
  12332. // NewMockTargetPools returns a new mock for TargetPools.
  12333. func NewMockTargetPools(pr ProjectRouter, objs map[meta.Key]*MockTargetPoolsObj) *MockTargetPools {
  12334. mock := &MockTargetPools{
  12335. ProjectRouter: pr,
  12336. Objects: objs,
  12337. GetError: map[meta.Key]error{},
  12338. InsertError: map[meta.Key]error{},
  12339. DeleteError: map[meta.Key]error{},
  12340. }
  12341. return mock
  12342. }
  12343. // MockTargetPools is the mock for TargetPools.
  12344. type MockTargetPools struct {
  12345. Lock sync.Mutex
  12346. ProjectRouter ProjectRouter
  12347. // Objects maintained by the mock.
  12348. Objects map[meta.Key]*MockTargetPoolsObj
  12349. // If an entry exists for the given key and operation, then the error
  12350. // will be returned instead of the operation.
  12351. GetError map[meta.Key]error
  12352. ListError *error
  12353. InsertError map[meta.Key]error
  12354. DeleteError map[meta.Key]error
  12355. // xxxHook allow you to intercept the standard processing of the mock in
  12356. // order to add your own logic. Return (true, _, _) to prevent the normal
  12357. // execution flow of the mock. Return (false, nil, nil) to continue with
  12358. // normal mock behavior/ after the hook function executes.
  12359. GetHook func(ctx context.Context, key *meta.Key, m *MockTargetPools) (bool, *ga.TargetPool, error)
  12360. ListHook func(ctx context.Context, region string, fl *filter.F, m *MockTargetPools) (bool, []*ga.TargetPool, error)
  12361. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.TargetPool, m *MockTargetPools) (bool, error)
  12362. DeleteHook func(ctx context.Context, key *meta.Key, m *MockTargetPools) (bool, error)
  12363. AddInstanceHook func(context.Context, *meta.Key, *ga.TargetPoolsAddInstanceRequest, *MockTargetPools) error
  12364. RemoveInstanceHook func(context.Context, *meta.Key, *ga.TargetPoolsRemoveInstanceRequest, *MockTargetPools) error
  12365. // X is extra state that can be used as part of the mock. Generated code
  12366. // will not use this field.
  12367. X interface{}
  12368. }
  12369. // Get returns the object from the mock.
  12370. func (m *MockTargetPools) Get(ctx context.Context, key *meta.Key) (*ga.TargetPool, error) {
  12371. if m.GetHook != nil {
  12372. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  12373. klog.V(5).Infof("MockTargetPools.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  12374. return obj, err
  12375. }
  12376. }
  12377. if !key.Valid() {
  12378. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  12379. }
  12380. m.Lock.Lock()
  12381. defer m.Lock.Unlock()
  12382. if err, ok := m.GetError[*key]; ok {
  12383. klog.V(5).Infof("MockTargetPools.Get(%v, %s) = nil, %v", ctx, key, err)
  12384. return nil, err
  12385. }
  12386. if obj, ok := m.Objects[*key]; ok {
  12387. typedObj := obj.ToGA()
  12388. klog.V(5).Infof("MockTargetPools.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  12389. return typedObj, nil
  12390. }
  12391. err := &googleapi.Error{
  12392. Code: http.StatusNotFound,
  12393. Message: fmt.Sprintf("MockTargetPools %v not found", key),
  12394. }
  12395. klog.V(5).Infof("MockTargetPools.Get(%v, %s) = nil, %v", ctx, key, err)
  12396. return nil, err
  12397. }
  12398. // List all of the objects in the mock in the given region.
  12399. func (m *MockTargetPools) List(ctx context.Context, region string, fl *filter.F) ([]*ga.TargetPool, error) {
  12400. if m.ListHook != nil {
  12401. if intercept, objs, err := m.ListHook(ctx, region, fl, m); intercept {
  12402. klog.V(5).Infof("MockTargetPools.List(%v, %q, %v) = [%v items], %v", ctx, region, fl, len(objs), err)
  12403. return objs, err
  12404. }
  12405. }
  12406. m.Lock.Lock()
  12407. defer m.Lock.Unlock()
  12408. if m.ListError != nil {
  12409. err := *m.ListError
  12410. klog.V(5).Infof("MockTargetPools.List(%v, %q, %v) = nil, %v", ctx, region, fl, err)
  12411. return nil, *m.ListError
  12412. }
  12413. var objs []*ga.TargetPool
  12414. for key, obj := range m.Objects {
  12415. if key.Region != region {
  12416. continue
  12417. }
  12418. if !fl.Match(obj.ToGA()) {
  12419. continue
  12420. }
  12421. objs = append(objs, obj.ToGA())
  12422. }
  12423. klog.V(5).Infof("MockTargetPools.List(%v, %q, %v) = [%v items], nil", ctx, region, fl, len(objs))
  12424. return objs, nil
  12425. }
  12426. // Insert is a mock for inserting/creating a new object.
  12427. func (m *MockTargetPools) Insert(ctx context.Context, key *meta.Key, obj *ga.TargetPool) error {
  12428. if m.InsertHook != nil {
  12429. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  12430. klog.V(5).Infof("MockTargetPools.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12431. return err
  12432. }
  12433. }
  12434. if !key.Valid() {
  12435. return fmt.Errorf("invalid GCE key (%+v)", key)
  12436. }
  12437. m.Lock.Lock()
  12438. defer m.Lock.Unlock()
  12439. if err, ok := m.InsertError[*key]; ok {
  12440. klog.V(5).Infof("MockTargetPools.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12441. return err
  12442. }
  12443. if _, ok := m.Objects[*key]; ok {
  12444. err := &googleapi.Error{
  12445. Code: http.StatusConflict,
  12446. Message: fmt.Sprintf("MockTargetPools %v exists", key),
  12447. }
  12448. klog.V(5).Infof("MockTargetPools.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12449. return err
  12450. }
  12451. obj.Name = key.Name
  12452. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "targetPools")
  12453. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "targetPools", key)
  12454. m.Objects[*key] = &MockTargetPoolsObj{obj}
  12455. klog.V(5).Infof("MockTargetPools.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  12456. return nil
  12457. }
  12458. // Delete is a mock for deleting the object.
  12459. func (m *MockTargetPools) Delete(ctx context.Context, key *meta.Key) error {
  12460. if m.DeleteHook != nil {
  12461. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  12462. klog.V(5).Infof("MockTargetPools.Delete(%v, %v) = %v", ctx, key, err)
  12463. return err
  12464. }
  12465. }
  12466. if !key.Valid() {
  12467. return fmt.Errorf("invalid GCE key (%+v)", key)
  12468. }
  12469. m.Lock.Lock()
  12470. defer m.Lock.Unlock()
  12471. if err, ok := m.DeleteError[*key]; ok {
  12472. klog.V(5).Infof("MockTargetPools.Delete(%v, %v) = %v", ctx, key, err)
  12473. return err
  12474. }
  12475. if _, ok := m.Objects[*key]; !ok {
  12476. err := &googleapi.Error{
  12477. Code: http.StatusNotFound,
  12478. Message: fmt.Sprintf("MockTargetPools %v not found", key),
  12479. }
  12480. klog.V(5).Infof("MockTargetPools.Delete(%v, %v) = %v", ctx, key, err)
  12481. return err
  12482. }
  12483. delete(m.Objects, *key)
  12484. klog.V(5).Infof("MockTargetPools.Delete(%v, %v) = nil", ctx, key)
  12485. return nil
  12486. }
  12487. // Obj wraps the object for use in the mock.
  12488. func (m *MockTargetPools) Obj(o *ga.TargetPool) *MockTargetPoolsObj {
  12489. return &MockTargetPoolsObj{o}
  12490. }
  12491. // AddInstance is a mock for the corresponding method.
  12492. func (m *MockTargetPools) AddInstance(ctx context.Context, key *meta.Key, arg0 *ga.TargetPoolsAddInstanceRequest) error {
  12493. if m.AddInstanceHook != nil {
  12494. return m.AddInstanceHook(ctx, key, arg0, m)
  12495. }
  12496. return nil
  12497. }
  12498. // RemoveInstance is a mock for the corresponding method.
  12499. func (m *MockTargetPools) RemoveInstance(ctx context.Context, key *meta.Key, arg0 *ga.TargetPoolsRemoveInstanceRequest) error {
  12500. if m.RemoveInstanceHook != nil {
  12501. return m.RemoveInstanceHook(ctx, key, arg0, m)
  12502. }
  12503. return nil
  12504. }
  12505. // GCETargetPools is a simplifying adapter for the GCE TargetPools.
  12506. type GCETargetPools struct {
  12507. s *Service
  12508. }
  12509. // Get the TargetPool named by key.
  12510. func (g *GCETargetPools) Get(ctx context.Context, key *meta.Key) (*ga.TargetPool, error) {
  12511. klog.V(5).Infof("GCETargetPools.Get(%v, %v): called", ctx, key)
  12512. if !key.Valid() {
  12513. klog.V(2).Infof("GCETargetPools.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  12514. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  12515. }
  12516. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetPools")
  12517. rk := &RateLimitKey{
  12518. ProjectID: projectID,
  12519. Operation: "Get",
  12520. Version: meta.Version("ga"),
  12521. Service: "TargetPools",
  12522. }
  12523. klog.V(5).Infof("GCETargetPools.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12524. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12525. klog.V(4).Infof("GCETargetPools.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  12526. return nil, err
  12527. }
  12528. call := g.s.GA.TargetPools.Get(projectID, key.Region, key.Name)
  12529. call.Context(ctx)
  12530. v, err := call.Do()
  12531. klog.V(4).Infof("GCETargetPools.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  12532. return v, err
  12533. }
  12534. // List all TargetPool objects.
  12535. func (g *GCETargetPools) List(ctx context.Context, region string, fl *filter.F) ([]*ga.TargetPool, error) {
  12536. klog.V(5).Infof("GCETargetPools.List(%v, %v, %v) called", ctx, region, fl)
  12537. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetPools")
  12538. rk := &RateLimitKey{
  12539. ProjectID: projectID,
  12540. Operation: "List",
  12541. Version: meta.Version("ga"),
  12542. Service: "TargetPools",
  12543. }
  12544. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12545. return nil, err
  12546. }
  12547. klog.V(5).Infof("GCETargetPools.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
  12548. call := g.s.GA.TargetPools.List(projectID, region)
  12549. if fl != filter.None {
  12550. call.Filter(fl.String())
  12551. }
  12552. var all []*ga.TargetPool
  12553. f := func(l *ga.TargetPoolList) error {
  12554. klog.V(5).Infof("GCETargetPools.List(%v, ..., %v): page %+v", ctx, fl, l)
  12555. all = append(all, l.Items...)
  12556. return nil
  12557. }
  12558. if err := call.Pages(ctx, f); err != nil {
  12559. klog.V(4).Infof("GCETargetPools.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  12560. return nil, err
  12561. }
  12562. if klog.V(4) {
  12563. klog.V(4).Infof("GCETargetPools.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  12564. } else if klog.V(5) {
  12565. var asStr []string
  12566. for _, o := range all {
  12567. asStr = append(asStr, fmt.Sprintf("%+v", o))
  12568. }
  12569. klog.V(5).Infof("GCETargetPools.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  12570. }
  12571. return all, nil
  12572. }
  12573. // Insert TargetPool with key of value obj.
  12574. func (g *GCETargetPools) Insert(ctx context.Context, key *meta.Key, obj *ga.TargetPool) error {
  12575. klog.V(5).Infof("GCETargetPools.Insert(%v, %v, %+v): called", ctx, key, obj)
  12576. if !key.Valid() {
  12577. klog.V(2).Infof("GCETargetPools.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12578. return fmt.Errorf("invalid GCE key (%+v)", key)
  12579. }
  12580. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetPools")
  12581. rk := &RateLimitKey{
  12582. ProjectID: projectID,
  12583. Operation: "Insert",
  12584. Version: meta.Version("ga"),
  12585. Service: "TargetPools",
  12586. }
  12587. klog.V(5).Infof("GCETargetPools.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12588. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12589. klog.V(4).Infof("GCETargetPools.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  12590. return err
  12591. }
  12592. obj.Name = key.Name
  12593. call := g.s.GA.TargetPools.Insert(projectID, key.Region, obj)
  12594. call.Context(ctx)
  12595. op, err := call.Do()
  12596. if err != nil {
  12597. klog.V(4).Infof("GCETargetPools.Insert(%v, %v, ...) = %+v", ctx, key, err)
  12598. return err
  12599. }
  12600. err = g.s.WaitForCompletion(ctx, op)
  12601. klog.V(4).Infof("GCETargetPools.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  12602. return err
  12603. }
  12604. // Delete the TargetPool referenced by key.
  12605. func (g *GCETargetPools) Delete(ctx context.Context, key *meta.Key) error {
  12606. klog.V(5).Infof("GCETargetPools.Delete(%v, %v): called", ctx, key)
  12607. if !key.Valid() {
  12608. klog.V(2).Infof("GCETargetPools.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  12609. return fmt.Errorf("invalid GCE key (%+v)", key)
  12610. }
  12611. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetPools")
  12612. rk := &RateLimitKey{
  12613. ProjectID: projectID,
  12614. Operation: "Delete",
  12615. Version: meta.Version("ga"),
  12616. Service: "TargetPools",
  12617. }
  12618. klog.V(5).Infof("GCETargetPools.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12619. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12620. klog.V(4).Infof("GCETargetPools.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  12621. return err
  12622. }
  12623. call := g.s.GA.TargetPools.Delete(projectID, key.Region, key.Name)
  12624. call.Context(ctx)
  12625. op, err := call.Do()
  12626. if err != nil {
  12627. klog.V(4).Infof("GCETargetPools.Delete(%v, %v) = %v", ctx, key, err)
  12628. return err
  12629. }
  12630. err = g.s.WaitForCompletion(ctx, op)
  12631. klog.V(4).Infof("GCETargetPools.Delete(%v, %v) = %v", ctx, key, err)
  12632. return err
  12633. }
  12634. // AddInstance is a method on GCETargetPools.
  12635. func (g *GCETargetPools) AddInstance(ctx context.Context, key *meta.Key, arg0 *ga.TargetPoolsAddInstanceRequest) error {
  12636. klog.V(5).Infof("GCETargetPools.AddInstance(%v, %v, ...): called", ctx, key)
  12637. if !key.Valid() {
  12638. klog.V(2).Infof("GCETargetPools.AddInstance(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12639. return fmt.Errorf("invalid GCE key (%+v)", key)
  12640. }
  12641. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetPools")
  12642. rk := &RateLimitKey{
  12643. ProjectID: projectID,
  12644. Operation: "AddInstance",
  12645. Version: meta.Version("ga"),
  12646. Service: "TargetPools",
  12647. }
  12648. klog.V(5).Infof("GCETargetPools.AddInstance(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12649. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12650. klog.V(4).Infof("GCETargetPools.AddInstance(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  12651. return err
  12652. }
  12653. call := g.s.GA.TargetPools.AddInstance(projectID, key.Region, key.Name, arg0)
  12654. call.Context(ctx)
  12655. op, err := call.Do()
  12656. if err != nil {
  12657. klog.V(4).Infof("GCETargetPools.AddInstance(%v, %v, ...) = %+v", ctx, key, err)
  12658. return err
  12659. }
  12660. err = g.s.WaitForCompletion(ctx, op)
  12661. klog.V(4).Infof("GCETargetPools.AddInstance(%v, %v, ...) = %+v", ctx, key, err)
  12662. return err
  12663. }
  12664. // RemoveInstance is a method on GCETargetPools.
  12665. func (g *GCETargetPools) RemoveInstance(ctx context.Context, key *meta.Key, arg0 *ga.TargetPoolsRemoveInstanceRequest) error {
  12666. klog.V(5).Infof("GCETargetPools.RemoveInstance(%v, %v, ...): called", ctx, key)
  12667. if !key.Valid() {
  12668. klog.V(2).Infof("GCETargetPools.RemoveInstance(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12669. return fmt.Errorf("invalid GCE key (%+v)", key)
  12670. }
  12671. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "TargetPools")
  12672. rk := &RateLimitKey{
  12673. ProjectID: projectID,
  12674. Operation: "RemoveInstance",
  12675. Version: meta.Version("ga"),
  12676. Service: "TargetPools",
  12677. }
  12678. klog.V(5).Infof("GCETargetPools.RemoveInstance(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12679. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12680. klog.V(4).Infof("GCETargetPools.RemoveInstance(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  12681. return err
  12682. }
  12683. call := g.s.GA.TargetPools.RemoveInstance(projectID, key.Region, key.Name, arg0)
  12684. call.Context(ctx)
  12685. op, err := call.Do()
  12686. if err != nil {
  12687. klog.V(4).Infof("GCETargetPools.RemoveInstance(%v, %v, ...) = %+v", ctx, key, err)
  12688. return err
  12689. }
  12690. err = g.s.WaitForCompletion(ctx, op)
  12691. klog.V(4).Infof("GCETargetPools.RemoveInstance(%v, %v, ...) = %+v", ctx, key, err)
  12692. return err
  12693. }
  12694. // UrlMaps is an interface that allows for mocking of UrlMaps.
  12695. type UrlMaps interface {
  12696. Get(ctx context.Context, key *meta.Key) (*ga.UrlMap, error)
  12697. List(ctx context.Context, fl *filter.F) ([]*ga.UrlMap, error)
  12698. Insert(ctx context.Context, key *meta.Key, obj *ga.UrlMap) error
  12699. Delete(ctx context.Context, key *meta.Key) error
  12700. Update(context.Context, *meta.Key, *ga.UrlMap) error
  12701. }
  12702. // NewMockUrlMaps returns a new mock for UrlMaps.
  12703. func NewMockUrlMaps(pr ProjectRouter, objs map[meta.Key]*MockUrlMapsObj) *MockUrlMaps {
  12704. mock := &MockUrlMaps{
  12705. ProjectRouter: pr,
  12706. Objects: objs,
  12707. GetError: map[meta.Key]error{},
  12708. InsertError: map[meta.Key]error{},
  12709. DeleteError: map[meta.Key]error{},
  12710. }
  12711. return mock
  12712. }
  12713. // MockUrlMaps is the mock for UrlMaps.
  12714. type MockUrlMaps struct {
  12715. Lock sync.Mutex
  12716. ProjectRouter ProjectRouter
  12717. // Objects maintained by the mock.
  12718. Objects map[meta.Key]*MockUrlMapsObj
  12719. // If an entry exists for the given key and operation, then the error
  12720. // will be returned instead of the operation.
  12721. GetError map[meta.Key]error
  12722. ListError *error
  12723. InsertError map[meta.Key]error
  12724. DeleteError map[meta.Key]error
  12725. // xxxHook allow you to intercept the standard processing of the mock in
  12726. // order to add your own logic. Return (true, _, _) to prevent the normal
  12727. // execution flow of the mock. Return (false, nil, nil) to continue with
  12728. // normal mock behavior/ after the hook function executes.
  12729. GetHook func(ctx context.Context, key *meta.Key, m *MockUrlMaps) (bool, *ga.UrlMap, error)
  12730. ListHook func(ctx context.Context, fl *filter.F, m *MockUrlMaps) (bool, []*ga.UrlMap, error)
  12731. InsertHook func(ctx context.Context, key *meta.Key, obj *ga.UrlMap, m *MockUrlMaps) (bool, error)
  12732. DeleteHook func(ctx context.Context, key *meta.Key, m *MockUrlMaps) (bool, error)
  12733. UpdateHook func(context.Context, *meta.Key, *ga.UrlMap, *MockUrlMaps) error
  12734. // X is extra state that can be used as part of the mock. Generated code
  12735. // will not use this field.
  12736. X interface{}
  12737. }
  12738. // Get returns the object from the mock.
  12739. func (m *MockUrlMaps) Get(ctx context.Context, key *meta.Key) (*ga.UrlMap, error) {
  12740. if m.GetHook != nil {
  12741. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  12742. klog.V(5).Infof("MockUrlMaps.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  12743. return obj, err
  12744. }
  12745. }
  12746. if !key.Valid() {
  12747. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  12748. }
  12749. m.Lock.Lock()
  12750. defer m.Lock.Unlock()
  12751. if err, ok := m.GetError[*key]; ok {
  12752. klog.V(5).Infof("MockUrlMaps.Get(%v, %s) = nil, %v", ctx, key, err)
  12753. return nil, err
  12754. }
  12755. if obj, ok := m.Objects[*key]; ok {
  12756. typedObj := obj.ToGA()
  12757. klog.V(5).Infof("MockUrlMaps.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  12758. return typedObj, nil
  12759. }
  12760. err := &googleapi.Error{
  12761. Code: http.StatusNotFound,
  12762. Message: fmt.Sprintf("MockUrlMaps %v not found", key),
  12763. }
  12764. klog.V(5).Infof("MockUrlMaps.Get(%v, %s) = nil, %v", ctx, key, err)
  12765. return nil, err
  12766. }
  12767. // List all of the objects in the mock.
  12768. func (m *MockUrlMaps) List(ctx context.Context, fl *filter.F) ([]*ga.UrlMap, error) {
  12769. if m.ListHook != nil {
  12770. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  12771. klog.V(5).Infof("MockUrlMaps.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  12772. return objs, err
  12773. }
  12774. }
  12775. m.Lock.Lock()
  12776. defer m.Lock.Unlock()
  12777. if m.ListError != nil {
  12778. err := *m.ListError
  12779. klog.V(5).Infof("MockUrlMaps.List(%v, %v) = nil, %v", ctx, fl, err)
  12780. return nil, *m.ListError
  12781. }
  12782. var objs []*ga.UrlMap
  12783. for _, obj := range m.Objects {
  12784. if !fl.Match(obj.ToGA()) {
  12785. continue
  12786. }
  12787. objs = append(objs, obj.ToGA())
  12788. }
  12789. klog.V(5).Infof("MockUrlMaps.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  12790. return objs, nil
  12791. }
  12792. // Insert is a mock for inserting/creating a new object.
  12793. func (m *MockUrlMaps) Insert(ctx context.Context, key *meta.Key, obj *ga.UrlMap) error {
  12794. if m.InsertHook != nil {
  12795. if intercept, err := m.InsertHook(ctx, key, obj, m); intercept {
  12796. klog.V(5).Infof("MockUrlMaps.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12797. return err
  12798. }
  12799. }
  12800. if !key.Valid() {
  12801. return fmt.Errorf("invalid GCE key (%+v)", key)
  12802. }
  12803. m.Lock.Lock()
  12804. defer m.Lock.Unlock()
  12805. if err, ok := m.InsertError[*key]; ok {
  12806. klog.V(5).Infof("MockUrlMaps.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12807. return err
  12808. }
  12809. if _, ok := m.Objects[*key]; ok {
  12810. err := &googleapi.Error{
  12811. Code: http.StatusConflict,
  12812. Message: fmt.Sprintf("MockUrlMaps %v exists", key),
  12813. }
  12814. klog.V(5).Infof("MockUrlMaps.Insert(%v, %v, %+v) = %v", ctx, key, obj, err)
  12815. return err
  12816. }
  12817. obj.Name = key.Name
  12818. projectID := m.ProjectRouter.ProjectID(ctx, "ga", "urlMaps")
  12819. obj.SelfLink = SelfLink(meta.VersionGA, projectID, "urlMaps", key)
  12820. m.Objects[*key] = &MockUrlMapsObj{obj}
  12821. klog.V(5).Infof("MockUrlMaps.Insert(%v, %v, %+v) = nil", ctx, key, obj)
  12822. return nil
  12823. }
  12824. // Delete is a mock for deleting the object.
  12825. func (m *MockUrlMaps) Delete(ctx context.Context, key *meta.Key) error {
  12826. if m.DeleteHook != nil {
  12827. if intercept, err := m.DeleteHook(ctx, key, m); intercept {
  12828. klog.V(5).Infof("MockUrlMaps.Delete(%v, %v) = %v", ctx, key, err)
  12829. return err
  12830. }
  12831. }
  12832. if !key.Valid() {
  12833. return fmt.Errorf("invalid GCE key (%+v)", key)
  12834. }
  12835. m.Lock.Lock()
  12836. defer m.Lock.Unlock()
  12837. if err, ok := m.DeleteError[*key]; ok {
  12838. klog.V(5).Infof("MockUrlMaps.Delete(%v, %v) = %v", ctx, key, err)
  12839. return err
  12840. }
  12841. if _, ok := m.Objects[*key]; !ok {
  12842. err := &googleapi.Error{
  12843. Code: http.StatusNotFound,
  12844. Message: fmt.Sprintf("MockUrlMaps %v not found", key),
  12845. }
  12846. klog.V(5).Infof("MockUrlMaps.Delete(%v, %v) = %v", ctx, key, err)
  12847. return err
  12848. }
  12849. delete(m.Objects, *key)
  12850. klog.V(5).Infof("MockUrlMaps.Delete(%v, %v) = nil", ctx, key)
  12851. return nil
  12852. }
  12853. // Obj wraps the object for use in the mock.
  12854. func (m *MockUrlMaps) Obj(o *ga.UrlMap) *MockUrlMapsObj {
  12855. return &MockUrlMapsObj{o}
  12856. }
  12857. // Update is a mock for the corresponding method.
  12858. func (m *MockUrlMaps) Update(ctx context.Context, key *meta.Key, arg0 *ga.UrlMap) error {
  12859. if m.UpdateHook != nil {
  12860. return m.UpdateHook(ctx, key, arg0, m)
  12861. }
  12862. return nil
  12863. }
  12864. // GCEUrlMaps is a simplifying adapter for the GCE UrlMaps.
  12865. type GCEUrlMaps struct {
  12866. s *Service
  12867. }
  12868. // Get the UrlMap named by key.
  12869. func (g *GCEUrlMaps) Get(ctx context.Context, key *meta.Key) (*ga.UrlMap, error) {
  12870. klog.V(5).Infof("GCEUrlMaps.Get(%v, %v): called", ctx, key)
  12871. if !key.Valid() {
  12872. klog.V(2).Infof("GCEUrlMaps.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  12873. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  12874. }
  12875. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "UrlMaps")
  12876. rk := &RateLimitKey{
  12877. ProjectID: projectID,
  12878. Operation: "Get",
  12879. Version: meta.Version("ga"),
  12880. Service: "UrlMaps",
  12881. }
  12882. klog.V(5).Infof("GCEUrlMaps.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12883. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12884. klog.V(4).Infof("GCEUrlMaps.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  12885. return nil, err
  12886. }
  12887. call := g.s.GA.UrlMaps.Get(projectID, key.Name)
  12888. call.Context(ctx)
  12889. v, err := call.Do()
  12890. klog.V(4).Infof("GCEUrlMaps.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  12891. return v, err
  12892. }
  12893. // List all UrlMap objects.
  12894. func (g *GCEUrlMaps) List(ctx context.Context, fl *filter.F) ([]*ga.UrlMap, error) {
  12895. klog.V(5).Infof("GCEUrlMaps.List(%v, %v) called", ctx, fl)
  12896. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "UrlMaps")
  12897. rk := &RateLimitKey{
  12898. ProjectID: projectID,
  12899. Operation: "List",
  12900. Version: meta.Version("ga"),
  12901. Service: "UrlMaps",
  12902. }
  12903. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12904. return nil, err
  12905. }
  12906. klog.V(5).Infof("GCEUrlMaps.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  12907. call := g.s.GA.UrlMaps.List(projectID)
  12908. if fl != filter.None {
  12909. call.Filter(fl.String())
  12910. }
  12911. var all []*ga.UrlMap
  12912. f := func(l *ga.UrlMapList) error {
  12913. klog.V(5).Infof("GCEUrlMaps.List(%v, ..., %v): page %+v", ctx, fl, l)
  12914. all = append(all, l.Items...)
  12915. return nil
  12916. }
  12917. if err := call.Pages(ctx, f); err != nil {
  12918. klog.V(4).Infof("GCEUrlMaps.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  12919. return nil, err
  12920. }
  12921. if klog.V(4) {
  12922. klog.V(4).Infof("GCEUrlMaps.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  12923. } else if klog.V(5) {
  12924. var asStr []string
  12925. for _, o := range all {
  12926. asStr = append(asStr, fmt.Sprintf("%+v", o))
  12927. }
  12928. klog.V(5).Infof("GCEUrlMaps.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  12929. }
  12930. return all, nil
  12931. }
  12932. // Insert UrlMap with key of value obj.
  12933. func (g *GCEUrlMaps) Insert(ctx context.Context, key *meta.Key, obj *ga.UrlMap) error {
  12934. klog.V(5).Infof("GCEUrlMaps.Insert(%v, %v, %+v): called", ctx, key, obj)
  12935. if !key.Valid() {
  12936. klog.V(2).Infof("GCEUrlMaps.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12937. return fmt.Errorf("invalid GCE key (%+v)", key)
  12938. }
  12939. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "UrlMaps")
  12940. rk := &RateLimitKey{
  12941. ProjectID: projectID,
  12942. Operation: "Insert",
  12943. Version: meta.Version("ga"),
  12944. Service: "UrlMaps",
  12945. }
  12946. klog.V(5).Infof("GCEUrlMaps.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12947. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12948. klog.V(4).Infof("GCEUrlMaps.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  12949. return err
  12950. }
  12951. obj.Name = key.Name
  12952. call := g.s.GA.UrlMaps.Insert(projectID, obj)
  12953. call.Context(ctx)
  12954. op, err := call.Do()
  12955. if err != nil {
  12956. klog.V(4).Infof("GCEUrlMaps.Insert(%v, %v, ...) = %+v", ctx, key, err)
  12957. return err
  12958. }
  12959. err = g.s.WaitForCompletion(ctx, op)
  12960. klog.V(4).Infof("GCEUrlMaps.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
  12961. return err
  12962. }
  12963. // Delete the UrlMap referenced by key.
  12964. func (g *GCEUrlMaps) Delete(ctx context.Context, key *meta.Key) error {
  12965. klog.V(5).Infof("GCEUrlMaps.Delete(%v, %v): called", ctx, key)
  12966. if !key.Valid() {
  12967. klog.V(2).Infof("GCEUrlMaps.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
  12968. return fmt.Errorf("invalid GCE key (%+v)", key)
  12969. }
  12970. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "UrlMaps")
  12971. rk := &RateLimitKey{
  12972. ProjectID: projectID,
  12973. Operation: "Delete",
  12974. Version: meta.Version("ga"),
  12975. Service: "UrlMaps",
  12976. }
  12977. klog.V(5).Infof("GCEUrlMaps.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  12978. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  12979. klog.V(4).Infof("GCEUrlMaps.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
  12980. return err
  12981. }
  12982. call := g.s.GA.UrlMaps.Delete(projectID, key.Name)
  12983. call.Context(ctx)
  12984. op, err := call.Do()
  12985. if err != nil {
  12986. klog.V(4).Infof("GCEUrlMaps.Delete(%v, %v) = %v", ctx, key, err)
  12987. return err
  12988. }
  12989. err = g.s.WaitForCompletion(ctx, op)
  12990. klog.V(4).Infof("GCEUrlMaps.Delete(%v, %v) = %v", ctx, key, err)
  12991. return err
  12992. }
  12993. // Update is a method on GCEUrlMaps.
  12994. func (g *GCEUrlMaps) Update(ctx context.Context, key *meta.Key, arg0 *ga.UrlMap) error {
  12995. klog.V(5).Infof("GCEUrlMaps.Update(%v, %v, ...): called", ctx, key)
  12996. if !key.Valid() {
  12997. klog.V(2).Infof("GCEUrlMaps.Update(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
  12998. return fmt.Errorf("invalid GCE key (%+v)", key)
  12999. }
  13000. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "UrlMaps")
  13001. rk := &RateLimitKey{
  13002. ProjectID: projectID,
  13003. Operation: "Update",
  13004. Version: meta.Version("ga"),
  13005. Service: "UrlMaps",
  13006. }
  13007. klog.V(5).Infof("GCEUrlMaps.Update(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  13008. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  13009. klog.V(4).Infof("GCEUrlMaps.Update(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
  13010. return err
  13011. }
  13012. call := g.s.GA.UrlMaps.Update(projectID, key.Name, arg0)
  13013. call.Context(ctx)
  13014. op, err := call.Do()
  13015. if err != nil {
  13016. klog.V(4).Infof("GCEUrlMaps.Update(%v, %v, ...) = %+v", ctx, key, err)
  13017. return err
  13018. }
  13019. err = g.s.WaitForCompletion(ctx, op)
  13020. klog.V(4).Infof("GCEUrlMaps.Update(%v, %v, ...) = %+v", ctx, key, err)
  13021. return err
  13022. }
  13023. // Zones is an interface that allows for mocking of Zones.
  13024. type Zones interface {
  13025. Get(ctx context.Context, key *meta.Key) (*ga.Zone, error)
  13026. List(ctx context.Context, fl *filter.F) ([]*ga.Zone, error)
  13027. }
  13028. // NewMockZones returns a new mock for Zones.
  13029. func NewMockZones(pr ProjectRouter, objs map[meta.Key]*MockZonesObj) *MockZones {
  13030. mock := &MockZones{
  13031. ProjectRouter: pr,
  13032. Objects: objs,
  13033. GetError: map[meta.Key]error{},
  13034. }
  13035. return mock
  13036. }
  13037. // MockZones is the mock for Zones.
  13038. type MockZones struct {
  13039. Lock sync.Mutex
  13040. ProjectRouter ProjectRouter
  13041. // Objects maintained by the mock.
  13042. Objects map[meta.Key]*MockZonesObj
  13043. // If an entry exists for the given key and operation, then the error
  13044. // will be returned instead of the operation.
  13045. GetError map[meta.Key]error
  13046. ListError *error
  13047. // xxxHook allow you to intercept the standard processing of the mock in
  13048. // order to add your own logic. Return (true, _, _) to prevent the normal
  13049. // execution flow of the mock. Return (false, nil, nil) to continue with
  13050. // normal mock behavior/ after the hook function executes.
  13051. GetHook func(ctx context.Context, key *meta.Key, m *MockZones) (bool, *ga.Zone, error)
  13052. ListHook func(ctx context.Context, fl *filter.F, m *MockZones) (bool, []*ga.Zone, error)
  13053. // X is extra state that can be used as part of the mock. Generated code
  13054. // will not use this field.
  13055. X interface{}
  13056. }
  13057. // Get returns the object from the mock.
  13058. func (m *MockZones) Get(ctx context.Context, key *meta.Key) (*ga.Zone, error) {
  13059. if m.GetHook != nil {
  13060. if intercept, obj, err := m.GetHook(ctx, key, m); intercept {
  13061. klog.V(5).Infof("MockZones.Get(%v, %s) = %+v, %v", ctx, key, obj, err)
  13062. return obj, err
  13063. }
  13064. }
  13065. if !key.Valid() {
  13066. return nil, fmt.Errorf("invalid GCE key (%+v)", key)
  13067. }
  13068. m.Lock.Lock()
  13069. defer m.Lock.Unlock()
  13070. if err, ok := m.GetError[*key]; ok {
  13071. klog.V(5).Infof("MockZones.Get(%v, %s) = nil, %v", ctx, key, err)
  13072. return nil, err
  13073. }
  13074. if obj, ok := m.Objects[*key]; ok {
  13075. typedObj := obj.ToGA()
  13076. klog.V(5).Infof("MockZones.Get(%v, %s) = %+v, nil", ctx, key, typedObj)
  13077. return typedObj, nil
  13078. }
  13079. err := &googleapi.Error{
  13080. Code: http.StatusNotFound,
  13081. Message: fmt.Sprintf("MockZones %v not found", key),
  13082. }
  13083. klog.V(5).Infof("MockZones.Get(%v, %s) = nil, %v", ctx, key, err)
  13084. return nil, err
  13085. }
  13086. // List all of the objects in the mock.
  13087. func (m *MockZones) List(ctx context.Context, fl *filter.F) ([]*ga.Zone, error) {
  13088. if m.ListHook != nil {
  13089. if intercept, objs, err := m.ListHook(ctx, fl, m); intercept {
  13090. klog.V(5).Infof("MockZones.List(%v, %v) = [%v items], %v", ctx, fl, len(objs), err)
  13091. return objs, err
  13092. }
  13093. }
  13094. m.Lock.Lock()
  13095. defer m.Lock.Unlock()
  13096. if m.ListError != nil {
  13097. err := *m.ListError
  13098. klog.V(5).Infof("MockZones.List(%v, %v) = nil, %v", ctx, fl, err)
  13099. return nil, *m.ListError
  13100. }
  13101. var objs []*ga.Zone
  13102. for _, obj := range m.Objects {
  13103. if !fl.Match(obj.ToGA()) {
  13104. continue
  13105. }
  13106. objs = append(objs, obj.ToGA())
  13107. }
  13108. klog.V(5).Infof("MockZones.List(%v, %v) = [%v items], nil", ctx, fl, len(objs))
  13109. return objs, nil
  13110. }
  13111. // Obj wraps the object for use in the mock.
  13112. func (m *MockZones) Obj(o *ga.Zone) *MockZonesObj {
  13113. return &MockZonesObj{o}
  13114. }
  13115. // GCEZones is a simplifying adapter for the GCE Zones.
  13116. type GCEZones struct {
  13117. s *Service
  13118. }
  13119. // Get the Zone named by key.
  13120. func (g *GCEZones) Get(ctx context.Context, key *meta.Key) (*ga.Zone, error) {
  13121. klog.V(5).Infof("GCEZones.Get(%v, %v): called", ctx, key)
  13122. if !key.Valid() {
  13123. klog.V(2).Infof("GCEZones.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
  13124. return nil, fmt.Errorf("invalid GCE key (%#v)", key)
  13125. }
  13126. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Zones")
  13127. rk := &RateLimitKey{
  13128. ProjectID: projectID,
  13129. Operation: "Get",
  13130. Version: meta.Version("ga"),
  13131. Service: "Zones",
  13132. }
  13133. klog.V(5).Infof("GCEZones.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
  13134. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  13135. klog.V(4).Infof("GCEZones.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
  13136. return nil, err
  13137. }
  13138. call := g.s.GA.Zones.Get(projectID, key.Name)
  13139. call.Context(ctx)
  13140. v, err := call.Do()
  13141. klog.V(4).Infof("GCEZones.Get(%v, %v) = %+v, %v", ctx, key, v, err)
  13142. return v, err
  13143. }
  13144. // List all Zone objects.
  13145. func (g *GCEZones) List(ctx context.Context, fl *filter.F) ([]*ga.Zone, error) {
  13146. klog.V(5).Infof("GCEZones.List(%v, %v) called", ctx, fl)
  13147. projectID := g.s.ProjectRouter.ProjectID(ctx, "ga", "Zones")
  13148. rk := &RateLimitKey{
  13149. ProjectID: projectID,
  13150. Operation: "List",
  13151. Version: meta.Version("ga"),
  13152. Service: "Zones",
  13153. }
  13154. if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
  13155. return nil, err
  13156. }
  13157. klog.V(5).Infof("GCEZones.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
  13158. call := g.s.GA.Zones.List(projectID)
  13159. if fl != filter.None {
  13160. call.Filter(fl.String())
  13161. }
  13162. var all []*ga.Zone
  13163. f := func(l *ga.ZoneList) error {
  13164. klog.V(5).Infof("GCEZones.List(%v, ..., %v): page %+v", ctx, fl, l)
  13165. all = append(all, l.Items...)
  13166. return nil
  13167. }
  13168. if err := call.Pages(ctx, f); err != nil {
  13169. klog.V(4).Infof("GCEZones.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
  13170. return nil, err
  13171. }
  13172. if klog.V(4) {
  13173. klog.V(4).Infof("GCEZones.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
  13174. } else if klog.V(5) {
  13175. var asStr []string
  13176. for _, o := range all {
  13177. asStr = append(asStr, fmt.Sprintf("%+v", o))
  13178. }
  13179. klog.V(5).Infof("GCEZones.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
  13180. }
  13181. return all, nil
  13182. }
  13183. // NewAddressesResourceID creates a ResourceID for the Addresses resource.
  13184. func NewAddressesResourceID(project, region, name string) *ResourceID {
  13185. key := meta.RegionalKey(name, region)
  13186. return &ResourceID{project, "addresses", key}
  13187. }
  13188. // NewBackendServicesResourceID creates a ResourceID for the BackendServices resource.
  13189. func NewBackendServicesResourceID(project, name string) *ResourceID {
  13190. key := meta.GlobalKey(name)
  13191. return &ResourceID{project, "backendServices", key}
  13192. }
  13193. // NewDisksResourceID creates a ResourceID for the Disks resource.
  13194. func NewDisksResourceID(project, zone, name string) *ResourceID {
  13195. key := meta.ZonalKey(name, zone)
  13196. return &ResourceID{project, "disks", key}
  13197. }
  13198. // NewFirewallsResourceID creates a ResourceID for the Firewalls resource.
  13199. func NewFirewallsResourceID(project, name string) *ResourceID {
  13200. key := meta.GlobalKey(name)
  13201. return &ResourceID{project, "firewalls", key}
  13202. }
  13203. // NewForwardingRulesResourceID creates a ResourceID for the ForwardingRules resource.
  13204. func NewForwardingRulesResourceID(project, region, name string) *ResourceID {
  13205. key := meta.RegionalKey(name, region)
  13206. return &ResourceID{project, "forwardingRules", key}
  13207. }
  13208. // NewGlobalAddressesResourceID creates a ResourceID for the GlobalAddresses resource.
  13209. func NewGlobalAddressesResourceID(project, name string) *ResourceID {
  13210. key := meta.GlobalKey(name)
  13211. return &ResourceID{project, "addresses", key}
  13212. }
  13213. // NewGlobalForwardingRulesResourceID creates a ResourceID for the GlobalForwardingRules resource.
  13214. func NewGlobalForwardingRulesResourceID(project, name string) *ResourceID {
  13215. key := meta.GlobalKey(name)
  13216. return &ResourceID{project, "forwardingRules", key}
  13217. }
  13218. // NewHealthChecksResourceID creates a ResourceID for the HealthChecks resource.
  13219. func NewHealthChecksResourceID(project, name string) *ResourceID {
  13220. key := meta.GlobalKey(name)
  13221. return &ResourceID{project, "healthChecks", key}
  13222. }
  13223. // NewHttpHealthChecksResourceID creates a ResourceID for the HttpHealthChecks resource.
  13224. func NewHttpHealthChecksResourceID(project, name string) *ResourceID {
  13225. key := meta.GlobalKey(name)
  13226. return &ResourceID{project, "httpHealthChecks", key}
  13227. }
  13228. // NewHttpsHealthChecksResourceID creates a ResourceID for the HttpsHealthChecks resource.
  13229. func NewHttpsHealthChecksResourceID(project, name string) *ResourceID {
  13230. key := meta.GlobalKey(name)
  13231. return &ResourceID{project, "httpsHealthChecks", key}
  13232. }
  13233. // NewInstanceGroupsResourceID creates a ResourceID for the InstanceGroups resource.
  13234. func NewInstanceGroupsResourceID(project, zone, name string) *ResourceID {
  13235. key := meta.ZonalKey(name, zone)
  13236. return &ResourceID{project, "instanceGroups", key}
  13237. }
  13238. // NewInstancesResourceID creates a ResourceID for the Instances resource.
  13239. func NewInstancesResourceID(project, zone, name string) *ResourceID {
  13240. key := meta.ZonalKey(name, zone)
  13241. return &ResourceID{project, "instances", key}
  13242. }
  13243. // NewNetworkEndpointGroupsResourceID creates a ResourceID for the NetworkEndpointGroups resource.
  13244. func NewNetworkEndpointGroupsResourceID(project, zone, name string) *ResourceID {
  13245. key := meta.ZonalKey(name, zone)
  13246. return &ResourceID{project, "networkEndpointGroups", key}
  13247. }
  13248. // NewProjectsResourceID creates a ResourceID for the Projects resource.
  13249. func NewProjectsResourceID(project string) *ResourceID {
  13250. var key *meta.Key
  13251. return &ResourceID{project, "projects", key}
  13252. }
  13253. // NewRegionBackendServicesResourceID creates a ResourceID for the RegionBackendServices resource.
  13254. func NewRegionBackendServicesResourceID(project, region, name string) *ResourceID {
  13255. key := meta.RegionalKey(name, region)
  13256. return &ResourceID{project, "backendServices", key}
  13257. }
  13258. // NewRegionDisksResourceID creates a ResourceID for the RegionDisks resource.
  13259. func NewRegionDisksResourceID(project, region, name string) *ResourceID {
  13260. key := meta.RegionalKey(name, region)
  13261. return &ResourceID{project, "disks", key}
  13262. }
  13263. // NewRegionsResourceID creates a ResourceID for the Regions resource.
  13264. func NewRegionsResourceID(project, name string) *ResourceID {
  13265. key := meta.GlobalKey(name)
  13266. return &ResourceID{project, "regions", key}
  13267. }
  13268. // NewRoutesResourceID creates a ResourceID for the Routes resource.
  13269. func NewRoutesResourceID(project, name string) *ResourceID {
  13270. key := meta.GlobalKey(name)
  13271. return &ResourceID{project, "routes", key}
  13272. }
  13273. // NewSecurityPoliciesResourceID creates a ResourceID for the SecurityPolicies resource.
  13274. func NewSecurityPoliciesResourceID(project, name string) *ResourceID {
  13275. key := meta.GlobalKey(name)
  13276. return &ResourceID{project, "securityPolicies", key}
  13277. }
  13278. // NewSslCertificatesResourceID creates a ResourceID for the SslCertificates resource.
  13279. func NewSslCertificatesResourceID(project, name string) *ResourceID {
  13280. key := meta.GlobalKey(name)
  13281. return &ResourceID{project, "sslCertificates", key}
  13282. }
  13283. // NewTargetHttpProxiesResourceID creates a ResourceID for the TargetHttpProxies resource.
  13284. func NewTargetHttpProxiesResourceID(project, name string) *ResourceID {
  13285. key := meta.GlobalKey(name)
  13286. return &ResourceID{project, "targetHttpProxies", key}
  13287. }
  13288. // NewTargetHttpsProxiesResourceID creates a ResourceID for the TargetHttpsProxies resource.
  13289. func NewTargetHttpsProxiesResourceID(project, name string) *ResourceID {
  13290. key := meta.GlobalKey(name)
  13291. return &ResourceID{project, "targetHttpsProxies", key}
  13292. }
  13293. // NewTargetPoolsResourceID creates a ResourceID for the TargetPools resource.
  13294. func NewTargetPoolsResourceID(project, region, name string) *ResourceID {
  13295. key := meta.RegionalKey(name, region)
  13296. return &ResourceID{project, "targetPools", key}
  13297. }
  13298. // NewUrlMapsResourceID creates a ResourceID for the UrlMaps resource.
  13299. func NewUrlMapsResourceID(project, name string) *ResourceID {
  13300. key := meta.GlobalKey(name)
  13301. return &ResourceID{project, "urlMaps", key}
  13302. }
  13303. // NewZonesResourceID creates a ResourceID for the Zones resource.
  13304. func NewZonesResourceID(project, name string) *ResourceID {
  13305. key := meta.GlobalKey(name)
  13306. return &ResourceID{project, "zones", key}
  13307. }