123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499 |
- package azblob_test
- import (
- "bytes"
- "context"
- "crypto/md5"
- "errors"
- "fmt"
- "io/ioutil"
- "net/url"
- "os"
- "runtime"
- "strconv"
- "strings"
- "testing"
- "time"
- chk "gopkg.in/check.v1"
- "github.com/Azure/azure-pipeline-go/pipeline"
- "github.com/Azure/azure-storage-blob-go/2016-05-31/azblob"
- )
- /*func finalizer(c azblob.ContainerURL) {
- c.Delete(context.Background(), azblob.ContainerAccessConditions{})
- }
- // Put in Test Main
- var defaultContainerURL *azblob.ContainerURL = createDefaultContainerURL()
- func createDefaultContainerURL() *azblob.ContainerURL {
- u, _ := url.Parse("")
- su := azblob.NewServiceURL(*u, azblob.NewPipeline())
- c := &su.NewContainerURL(generateContainerName())
- runtime.SetFinalizer(c, finalizer)
- return c
- }
- func getDefaultContainerURL() azblob.ContainerURL {
- // Call in all tests. No need to defer. Generally eliminates need for getBSU()
- return *c
- }
- func createContainer(c *chk.C, su *azblob.ServiceURL) (azblob.ContainerURL, func()){
- // Create container and
- // If service url not nil, use it. If nil, use default
- return containerURL, func(){ containerURL.Delete() }
- }*/
- // Hookup to the testing framework
- func Test(t *testing.T) { chk.TestingT(t) }
- type aztestsSuite struct{}
- var _ = chk.Suite(&aztestsSuite{})
- const (
- containerPrefix = "go"
- blobPrefix = "gotestblob"
- blockBlobDefaultData = "GoBlockBlobData"
- validationErrorSubstring = "validation failed"
- )
- var ctx = context.Background()
- var basicHeaders = azblob.BlobHTTPHeaders{ContentType: "my_type", ContentDisposition: "my_disposition",
- CacheControl: "control", ContentMD5: md5.Sum([]byte("")), ContentLanguage: "my_language", ContentEncoding: "my_encoding"}
- var basicMetadata = azblob.Metadata{"foo": "bar"}
- type testPipeline struct{}
- const testPipelineMessage string = "Test factory invoked"
- func (tm testPipeline) Do(ctx context.Context, methodFactory pipeline.Factory, request pipeline.Request) (pipeline.Response, error) {
- return nil, errors.New(testPipelineMessage)
- }
- // This function generates an entity name by concatenating the passed prefix,
- // the name of the test requesting the entity name, and the minute, second, and nanoseconds of the call.
- // This should make it easy to associate the entities with their test, uniquely identify
- // them, and determine the order in which they were created.
- // Note that this imposes a restriction on the length of test names
- func generateName(prefix string) string {
- // These next lines up through the for loop are obtaining and walking up the stack
- // trace to extrat the test name, which is stored in name
- pc := make([]uintptr, 10)
- runtime.Callers(0, pc)
- f := runtime.FuncForPC(pc[0])
- name := f.Name()
- for i := 0; !strings.Contains(name, "Suite"); i++ { // The tests are all scoped to the suite, so this ensures getting the actual test name
- f = runtime.FuncForPC(pc[i])
- name = f.Name()
- }
- funcNameStart := strings.Index(name, "Test")
- name = name[funcNameStart+len("Test"):] // Just get the name of the test and not any of the garbage at the beginning
- name = strings.ToLower(name) // Ensure it is a valid resource name
- currentTime := time.Now()
- name = fmt.Sprintf("%s%s%d%d%d", prefix, strings.ToLower(name), currentTime.Minute(), currentTime.Second(), currentTime.Nanosecond())
- return name
- }
- func generateContainerName() string {
- return generateName(containerPrefix)
- }
- func generateBlobName() string {
- return generateName(blobPrefix)
- }
- func getContainerURL(c *chk.C, bsu azblob.ServiceURL) (container azblob.ContainerURL, name string) {
- name = generateContainerName()
- container = bsu.NewContainerURL(name)
- return container, name
- }
- func getBlockBlobURL(c *chk.C, container azblob.ContainerURL) (blob azblob.BlockBlobURL, name string) {
- name = generateBlobName()
- blob = container.NewBlockBlobURL(name)
- return blob, name
- }
- func getAppendBlobURL(c *chk.C, container azblob.ContainerURL) (blob azblob.AppendBlobURL, name string) {
- name = generateBlobName()
- blob = container.NewAppendBlobURL(name)
- return blob, name
- }
- func getPageBlobURL(c *chk.C, container azblob.ContainerURL) (blob azblob.PageBlobURL, name string) {
- name = generateBlobName()
- blob = container.NewPageBlobURL(name)
- return
- }
- func createNewContainer(c *chk.C, bsu azblob.ServiceURL) (container azblob.ContainerURL, name string) {
- container, name = getContainerURL(c, bsu)
- cResp, err := container.Create(ctx, nil, azblob.PublicAccessBlob)
- c.Assert(err, chk.IsNil)
- c.Assert(cResp.StatusCode(), chk.Equals, 201)
- return container, name
- }
- func createNewContainerWithSuffix(c *chk.C, bsu azblob.ServiceURL, suffix string) (container azblob.ContainerURL, name string) {
- // The goal of adding the suffix is to be able to predetermine what order the containers will be in when listed.
- // We still need the container prefix to come first, though, to ensure only containers as a part of this test
- // are listed at all.
- name = generateName(containerPrefix + suffix)
- container = bsu.NewContainerURL(name)
- cResp, err := container.Create(ctx, nil, azblob.PublicAccessBlob)
- c.Assert(err, chk.IsNil)
- c.Assert(cResp.StatusCode(), chk.Equals, 201)
- return container, name
- }
- func createNewBlockBlob(c *chk.C, container azblob.ContainerURL) (blob azblob.BlockBlobURL, name string) {
- blob, name = getBlockBlobURL(c, container)
- cResp, err := blob.PutBlob(ctx, strings.NewReader(blockBlobDefaultData), azblob.BlobHTTPHeaders{},
- nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(cResp.StatusCode(), chk.Equals, 201)
- return
- }
- func createNewAppendBlob(c *chk.C, container azblob.ContainerURL) (blob azblob.AppendBlobURL, name string) {
- blob, name = getAppendBlobURL(c, container)
- resp, err := blob.Create(ctx, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.StatusCode(), chk.Equals, 201)
- return
- }
- func createNewPageBlob(c *chk.C, container azblob.ContainerURL) (blob azblob.PageBlobURL, name string) {
- blob, name = getPageBlobURL(c, container)
- resp, err := blob.Create(ctx, azblob.PageBlobPageBytes*10, 0, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.StatusCode(), chk.Equals, 201)
- return
- }
- func createBlockBlobWithPrefix(c *chk.C, container azblob.ContainerURL, prefix string) (blob azblob.BlockBlobURL, name string) {
- name = prefix + generateName(blobPrefix)
- blob = container.NewBlockBlobURL(name)
- cResp, err := blob.PutBlob(ctx, strings.NewReader(blockBlobDefaultData), azblob.BlobHTTPHeaders{},
- nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(cResp.StatusCode(), chk.Equals, 201)
- return
- }
- func deleteContainer(c *chk.C, container azblob.ContainerURL) {
- resp, err := container.Delete(ctx, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.StatusCode(), chk.Equals, 202)
- }
- func getBSU() azblob.ServiceURL {
- name := os.Getenv("ACCOUNT_NAME")
- key := os.Getenv("ACCOUNT_KEY")
- if name == "" || key == "" {
- panic("ACCOUNT_NAME and ACCOUNT_KEY environment vars must be set before running tests")
- }
- u, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net/", name))
- credential := azblob.NewSharedKeyCredential(name, key)
- pipeline := azblob.NewPipeline(credential, azblob.PipelineOptions{})
- return azblob.NewServiceURL(*u, pipeline)
- }
- func getAlternateBSU() (azblob.ServiceURL, error) {
- secondaryAccountName, secondaryAccountKey := os.Getenv("SECONDARY_ACCOUNT_NAME"), os.Getenv("SECONDARY_ACCOUNT_KEY")
- if secondaryAccountName == "" || secondaryAccountKey == "" {
- return azblob.ServiceURL{}, errors.New("SECONDARY_ACCOUNT_NAME and/or SECONDARY_ACCOUNT_KEY environment variables not specified.")
- }
- credentials := azblob.NewSharedKeyCredential(secondaryAccountName, secondaryAccountKey)
- pipeline := azblob.NewPipeline(credentials, azblob.PipelineOptions{ /*Log: pipeline.NewLogWrapper(pipeline.LogInfo, log.New(os.Stderr, "", log.LstdFlags))*/ })
- blobPrimaryURL, _ := url.Parse("https://" + secondaryAccountName + ".blob.core.windows.net/")
- return azblob.NewServiceURL(*blobPrimaryURL, pipeline), nil
- }
- func validateStorageError(c *chk.C, err error, code azblob.ServiceCodeType) {
- serr, _ := err.(azblob.StorageError)
- c.Assert(serr.ServiceCode(), chk.Equals, code)
- }
- func getRelativeTimeGMT(amount time.Duration) time.Time {
- currentTime := time.Now().In(time.FixedZone("GMT", 0))
- currentTime = currentTime.Add(amount * time.Second)
- return currentTime
- }
- func (s *aztestsSuite) TestAccountListContainersEmptyPrefix(c *chk.C) {
- bsu := getBSU()
- containerURL1, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL1)
- containerURL2, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL2)
- response, err := bsu.ListContainers(ctx, azblob.Marker{}, azblob.ListContainersOptions{})
- c.Assert(err, chk.IsNil)
- c.Assert(len(response.Containers) >= 2, chk.Equals, true) // The response should contain at least the two created containers. Probably many more
- }
- func (s *aztestsSuite) TestAccountListContainersIncludeTypeMetadata(c *chk.C) {
- bsu := getBSU()
- containerURLNoMetadata, nameNoMetadata := createNewContainerWithSuffix(c, bsu, "a")
- defer deleteContainer(c, containerURLNoMetadata)
- containerURLMetadata, nameMetadata := createNewContainerWithSuffix(c, bsu, "b")
- defer deleteContainer(c, containerURLMetadata)
- // Test on containers with and without metadata
- _, err := containerURLMetadata.SetMetadata(ctx, basicMetadata, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- // Also validates not specifying MaxResults
- response, err := bsu.ListContainers(ctx, azblob.Marker{},
- azblob.ListContainersOptions{Prefix: containerPrefix, Detail: azblob.ListContainersDetail{Metadata: true}})
- c.Assert(err, chk.IsNil)
- c.Assert(response.Containers[0].Name, chk.Equals, nameNoMetadata)
- c.Assert(response.Containers[0].Metadata, chk.HasLen, 0)
- c.Assert(response.Containers[1].Name, chk.Equals, nameMetadata)
- c.Assert(response.Containers[1].Metadata, chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestAccountListContainersMaxResultsNegative(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- // The library should panic if MaxResults < -1
- defer func() {
- recover()
- }()
- bsu.ListContainers(ctx,
- azblob.Marker{}, *(&azblob.ListContainersOptions{Prefix: containerPrefix, MaxResults: -2}))
- c.Fail() // If the list call doesn't panic, we fail
- }
- func (s *aztestsSuite) TestAccountListContainersMaxResultsZero(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- // Max Results = 0 means the value will be ignored, the header not set, and the server default used
- resp, err := bsu.ListContainers(ctx,
- azblob.Marker{}, *(&azblob.ListContainersOptions{Prefix: containerPrefix, MaxResults: 0}))
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Containers, chk.HasLen, 1)
- }
- func (s *aztestsSuite) TestAccountListContainersMaxResultsExact(c *chk.C) {
- // If this test fails, ensure there are no extra containers prefixed with go in the account. These may be left over if a test is interrupted.
- bsu := getBSU()
- containerURL1, containerName1 := createNewContainerWithSuffix(c, bsu, "a")
- defer deleteContainer(c, containerURL1)
- containerURL2, containerName2 := createNewContainerWithSuffix(c, bsu, "b")
- defer deleteContainer(c, containerURL2)
- response, err := bsu.ListContainers(ctx,
- azblob.Marker{}, *(&azblob.ListContainersOptions{Prefix: containerPrefix, MaxResults: 2}))
- c.Assert(err, chk.IsNil)
- c.Assert(response.Containers, chk.HasLen, 2)
- c.Assert(response.Containers[0].Name, chk.Equals, containerName1)
- c.Assert(response.Containers[1].Name, chk.Equals, containerName2)
- }
- func (s *aztestsSuite) TestAccountListContainersMaxResultsInsufficient(c *chk.C) {
- bsu := getBSU()
- containerURL1, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL1)
- containerURL2, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL2)
- response, err := bsu.ListContainers(ctx, azblob.Marker{},
- *(&azblob.ListContainersOptions{Prefix: containerPrefix, MaxResults: 1}))
- c.Assert(err, chk.IsNil)
- c.Assert(len(response.Containers), chk.Equals, 1)
- }
- func (s *aztestsSuite) TestAccountListContainersMaxResultsSufficient(c *chk.C) {
- bsu := getBSU()
- containerURL1, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL1)
- containerURL2, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL2)
- response, err := bsu.ListContainers(ctx, azblob.Marker{},
- *(&azblob.ListContainersOptions{Prefix: containerPrefix, MaxResults: 3}))
- c.Assert(err, chk.IsNil)
- c.Assert(len(response.Containers), chk.Equals, 2)
- }
- func (s *aztestsSuite) TestNewContainerURLValidName(c *chk.C) {
- bsu := getBSU()
- testURL := bsu.NewContainerURL(containerPrefix)
- correctURL := "https://" + os.Getenv("ACCOUNT_NAME") + ".blob.core.windows.net/" + containerPrefix
- temp := testURL.URL()
- c.Assert(temp.String(), chk.Equals, correctURL)
- }
- func (s *aztestsSuite) TestCreateRootContainerURL(c *chk.C) {
- bsu := getBSU()
- testURL := bsu.NewRootContainerURL()
- correctURL := "https://" + os.Getenv("ACCOUNT_NAME") + ".blob.core.windows.net/$root"
- temp := testURL.URL()
- c.Assert(temp.String(), chk.Equals, correctURL)
- }
- func (s *aztestsSuite) TestCreateBlobURL(c *chk.C) {
- bsu := getBSU()
- containerURL, containerName := getContainerURL(c, bsu)
- testURL, testName := getBlockBlobURL(c, containerURL)
- parts := azblob.NewBlobURLParts(testURL.URL())
- c.Assert(parts.BlobName, chk.Equals, testName)
- c.Assert(parts.ContainerName, chk.Equals, containerName)
- correctURL := "https://" + os.Getenv("ACCOUNT_NAME") + ".blob.core.windows.net/" + containerName + "/" + testName
- temp := testURL.URL()
- c.Assert(temp.String(), chk.Equals, correctURL)
- }
- func (s *aztestsSuite) TestCreateBlobURLWithSnapshotAndSAS(c *chk.C) {
- bsu := getBSU()
- containerURL, containerName := getContainerURL(c, bsu)
- blobURL, blobName := getBlockBlobURL(c, containerURL)
- currentTime := time.Now().UTC()
- credential := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY"))
- sasQueryParams := azblob.AccountSASSignatureValues{
- Protocol: azblob.SASProtocolHTTPS,
- ExpiryTime: currentTime.Add(48 * time.Hour),
- Permissions: azblob.AccountSASPermissions{Read: true, List: true}.String(),
- Services: azblob.AccountSASServices{Blob: true}.String(),
- ResourceTypes: azblob.AccountSASResourceTypes{Container: true, Object: true}.String(),
- }.NewSASQueryParameters(credential)
- parts := azblob.NewBlobURLParts(blobURL.URL())
- parts.SAS = sasQueryParams
- parts.Snapshot = currentTime
- testURL := parts.URL()
- // The snapshot format string is taken from the snapshotTimeFormat value in parsing_urls.go. The field is not public, so
- // it is copied here
- correctURL := "https://" + os.Getenv("ACCOUNT_NAME") + ".blob.core.windows.net/" + containerName + "/" + blobName +
- "?" + "snapshot=" + currentTime.Format("2006-01-02T15:04:05.0000000Z07:00") + "&" + sasQueryParams.Encode()
- c.Assert(testURL.String(), chk.Equals, correctURL)
- }
- func (s *aztestsSuite) TestAccountWithPipeline(c *chk.C) {
- bsu := getBSU()
- bsu = bsu.WithPipeline(testPipeline{}) // testPipeline returns an identifying message as an error
- containerURL := bsu.NewContainerURL("name")
- _, err := containerURL.Create(ctx, azblob.Metadata{}, azblob.PublicAccessBlob)
- c.Assert(err.Error(), chk.Equals, testPipelineMessage)
- }
- func (s *aztestsSuite) TestContainerCreateInvalidName(c *chk.C) {
- bsu := getBSU()
- containerURL := bsu.NewContainerURL("foo bar")
- _, err := containerURL.Create(ctx, azblob.Metadata{}, azblob.PublicAccessBlob)
- validateStorageError(c, err, azblob.ServiceCodeInvalidResourceName)
- }
- func (s *aztestsSuite) TestContainerCreateEmptyName(c *chk.C) {
- bsu := getBSU()
- containerURL := bsu.NewContainerURL("")
- _, err := containerURL.Create(ctx, azblob.Metadata{}, azblob.PublicAccessBlob)
- validateStorageError(c, err, azblob.ServiceCodeInvalidQueryParameterValue)
- }
- func (s *aztestsSuite) TestContainerCreateNameCollision(c *chk.C) {
- bsu := getBSU()
- containerURL, containerName := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- containerURL = bsu.NewContainerURL(containerName)
- _, err := containerURL.Create(ctx, azblob.Metadata{}, azblob.PublicAccessBlob)
- validateStorageError(c, err, azblob.ServiceCodeContainerAlreadyExists)
- }
- func (s *aztestsSuite) TestContainerCreateInvalidMetadata(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, azblob.Metadata{"1 foo": "bar"}, azblob.PublicAccessBlob)
- c.Assert(err, chk.NotNil)
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func (s *aztestsSuite) TestContainerCreateNilMetadata(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, nil, azblob.PublicAccessBlob)
- defer deleteContainer(c, containerURL)
- c.Assert(err, chk.IsNil)
- response, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(response.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestContainerCreateEmptyMetadata(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, azblob.Metadata{}, azblob.PublicAccessBlob)
- defer deleteContainer(c, containerURL)
- c.Assert(err, chk.IsNil)
- response, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(response.NewMetadata(), chk.HasLen, 0)
- }
- // Note that for all tests that create blobs, deleting the container also deletes any blobs within that container, thus we
- // simply delete the whole container after the test
- func (s *aztestsSuite) TestContainerCreateAccessContainer(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, nil, azblob.PublicAccessContainer)
- defer deleteContainer(c, containerURL)
- c.Assert(err, chk.IsNil)
- blobURL := containerURL.NewBlockBlobURL(blobPrefix)
- blobURL.PutBlob(ctx, bytes.NewReader([]byte("Content")), azblob.BlobHTTPHeaders{},
- basicMetadata, azblob.BlobAccessConditions{})
- // Anonymous enumeration should be valid with container access
- containerURL2 := azblob.NewContainerURL(containerURL.URL(), azblob.NewPipeline(azblob.NewAnonymousCredential(), azblob.PipelineOptions{}))
- response, err := containerURL2.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{})
- c.Assert(err, chk.IsNil)
- c.Assert(response.Blobs.Blob[0].Name, chk.Equals, blobPrefix)
- // Getting blob data anonymously should still be valid with container access
- blobURL2 := containerURL2.NewBlockBlobURL(blobPrefix)
- resp, err := blobURL2.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestContainerCreateAccessBlob(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, nil, azblob.PublicAccessBlob)
- defer deleteContainer(c, containerURL)
- c.Assert(err, chk.IsNil)
- blobURL := containerURL.NewBlockBlobURL(blobPrefix)
- blobURL.PutBlob(ctx, bytes.NewReader([]byte("Content")), azblob.BlobHTTPHeaders{},
- basicMetadata, azblob.BlobAccessConditions{})
- // Reference the same container URL but with anonymous credentials
- containerURL2 := azblob.NewContainerURL(containerURL.URL(), azblob.NewPipeline(azblob.NewAnonymousCredential(), azblob.PipelineOptions{}))
- _, err = containerURL2.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{})
- validateStorageError(c, err, azblob.ServiceCodeResourceNotFound) // Listing blobs is not publicly accessible
- // Accessing blob specific data should be public
- blobURL2 := containerURL2.NewBlockBlobURL(blobPrefix)
- resp, err := blobURL2.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestContainerCreateAccessNone(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, nil, azblob.PublicAccessNone)
- defer deleteContainer(c, containerURL)
- blobURL := containerURL.NewBlockBlobURL(blobPrefix)
- blobURL.PutBlob(ctx, bytes.NewReader([]byte("Content")), azblob.BlobHTTPHeaders{},
- basicMetadata, azblob.BlobAccessConditions{})
- // Reference the same container URL but with anonymous credentials
- containerURL2 := azblob.NewContainerURL(containerURL.URL(), azblob.NewPipeline(azblob.NewAnonymousCredential(), azblob.PipelineOptions{}))
- // Listing blobs is not public
- _, err = containerURL2.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{})
- validateStorageError(c, err, azblob.ServiceCodeResourceNotFound)
- // Blob data is not public
- blobURL2 := containerURL2.NewBlockBlobURL(blobPrefix)
- _, err = blobURL2.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.NotNil)
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 404) // HEAD request does not return a status code
- }
- func validateContainerDeleted(c *chk.C, containerURL azblob.ContainerURL) {
- _, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeContainerNotFound)
- }
- func (s *aztestsSuite) TestContainerDelete(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- _, err := containerURL.Delete(ctx, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- validateContainerDeleted(c, containerURL)
- }
- func (s *aztestsSuite) TestContainerDeleteNonExistant(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Delete(ctx, azblob.ContainerAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeContainerNotFound)
- }
- func (s *aztestsSuite) TestContainerDeleteIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10) // Ensure the requests occur at different times
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.Delete(ctx,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateContainerDeleted(c, containerURL)
- }
- func (s *aztestsSuite) TestContainerDeleteIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := containerURL.Delete(ctx,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestContainerDeleteIfUnModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := containerURL.Delete(ctx,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateContainerDeleted(c, containerURL)
- }
- func (s *aztestsSuite) TestContainerDeleteIfUnModifiedSinceFalse(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10) // Ensure the requests occur at different times
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.Delete(ctx,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestContainerAccessConditionsUnsupportedConditions(c *chk.C) {
- // This test defines that the library will not stop you from adding conditional headers
- // that will be ignored by the service
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- defer func() { // The library should panic if it sees If(None)Match ETAG access condition
- recover()
- }()
- invalidEtag := azblob.ETag("invalid")
- containerURL.SetMetadata(ctx, basicMetadata,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: invalidEtag}})
- c.Fail() // If the method panics (as expected), then we shouldn't get here
- /*
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- */
- }
- func (s *aztestsSuite) TestContainerListBlobsNonexistantPrefix(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- createNewBlockBlob(c, containerURL)
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{Prefix: blobPrefix + blobPrefix})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestContainerListBlobsSpecificValidPrefix(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, blobName := createNewBlockBlob(c, containerURL)
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{Prefix: blobPrefix})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 1)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- }
- func (s *aztestsSuite) TestContainerListBlobsValidDelimiter(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- createBlockBlobWithPrefix(c, containerURL, "a/1")
- createBlockBlobWithPrefix(c, containerURL, "a/2")
- createBlockBlobWithPrefix(c, containerURL, "b/1")
- _, blobName := createBlockBlobWithPrefix(c, containerURL, "blob")
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{Delimiter: "/"})
- c.Assert(err, chk.IsNil)
- c.Assert(len(resp.Blobs.Blob), chk.Equals, 1)
- c.Assert(len(resp.Blobs.BlobPrefix), chk.Equals, 2)
- c.Assert(resp.Blobs.BlobPrefix[0].Name, chk.Equals, "a/")
- c.Assert(resp.Blobs.BlobPrefix[1].Name, chk.Equals, "b/")
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- }
- func (s *aztestsSuite) TestContainerListBlobsInvalidDelimiter(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- createBlockBlobWithPrefix(c, containerURL, "a/1")
- createBlockBlobWithPrefix(c, containerURL, "a/2")
- createBlockBlobWithPrefix(c, containerURL, "b/1")
- createBlockBlobWithPrefix(c, containerURL, "blob")
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{Delimiter: "^"})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 4)
- }
- func (s *aztestsSuite) TestContainerListBlobsIncludeTypeMetadata(c *chk.C) {
- bsu := getBSU()
- container, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, container)
- _, blobNameNoMetadata := createBlockBlobWithPrefix(c, container, "a")
- blobMetadata, blobNameMetadata := createBlockBlobWithPrefix(c, container, "b")
- _, err := blobMetadata.SetMetadata(ctx, azblob.Metadata{"field": "value"}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := container.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{Details: azblob.BlobListingDetails{Metadata: true}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobNameNoMetadata)
- c.Assert(resp.Blobs.Blob[0].Metadata, chk.HasLen, 0)
- c.Assert(resp.Blobs.Blob[1].Name, chk.Equals, blobNameMetadata)
- c.Assert(resp.Blobs.Blob[1].Metadata["field"], chk.Equals, "value")
- }
- func (s *aztestsSuite) TestContainerListBlobsIncludeTypeSnapshots(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blob, blobName := createNewBlockBlob(c, containerURL)
- _, err := blob.CreateSnapshot(ctx, azblob.Metadata{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{},
- azblob.ListBlobsOptions{Details: azblob.BlobListingDetails{Snapshots: true}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 2)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- c.Assert(resp.Blobs.Blob[0].Snapshot, chk.NotNil)
- c.Assert(resp.Blobs.Blob[1].Name, chk.Equals, blobName)
- c.Assert(resp.Blobs.Blob[1].Snapshot.IsZero(), chk.Equals, true)
- }
- func (s *aztestsSuite) TestContainerListBlobsIncludeTypeCopy(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, blobName := createNewBlockBlob(c, containerURL)
- blobCopyURL, blobCopyName := createBlockBlobWithPrefix(c, containerURL, "copy")
- _, err := blobCopyURL.StartCopy(ctx, blobURL.URL(), azblob.Metadata{}, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{},
- azblob.ListBlobsOptions{Details: azblob.BlobListingDetails{Copy: true}})
- // These are sufficient to show that the blob copy was in fact included
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 2)
- c.Assert(resp.Blobs.Blob[1].Name, chk.Equals, blobName)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobCopyName)
- c.Assert(*resp.Blobs.Blob[0].Properties.ContentLength, chk.Equals, int64(len(blockBlobDefaultData)))
- temp := blobURL.URL()
- c.Assert(*resp.Blobs.Blob[0].Properties.CopySource, chk.Equals, temp.String())
- c.Assert(resp.Blobs.Blob[0].Properties.CopyStatus, chk.Equals, azblob.CopyStatusSuccess)
- }
- func (s *aztestsSuite) TestContainerListBlobsIncludeTypeUncommitted(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, blobName := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{},
- azblob.ListBlobsOptions{Details: azblob.BlobListingDetails{UncommittedBlobs: true}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 1)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- }
- func (s *aztestsSuite) TestContainerListBlobsIncludeMultiple(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, blobName := createNewBlockBlob(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, azblob.Metadata{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- blobURL2, blobName2 := createBlockBlobWithPrefix(c, containerURL, "copy")
- _, err = blobURL2.StartCopy(ctx, blobURL.URL(), azblob.Metadata{}, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{},
- azblob.ListBlobsOptions{Details: azblob.BlobListingDetails{Snapshots: true, Copy: true}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 3)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName2)
- c.Assert(resp.Blobs.Blob[1].Name, chk.Equals, blobName)
- c.Assert(resp.Blobs.Blob[1].Snapshot, chk.NotNil)
- c.Assert(resp.Blobs.Blob[2].Name, chk.Equals, blobName)
- }
- func (s *aztestsSuite) TestContainerListBlobsMaxResultsNegative(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- // If ListBlobs panics, as it should, this function will be called and recover from the panic, allowing the test to pass
- defer func() {
- recover()
- }()
- containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{MaxResults: -2})
- // We will only reach this if we did not panic
- c.Fail()
- }
- func (s *aztestsSuite) TestContainerListBlobsMaxResultsZero(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- createNewBlockBlob(c, containerURL)
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{MaxResults: 0})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 1)
- }
- func (s *aztestsSuite) TestContainerListBlobsMaxResultsInsufficient(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, blobName := createBlockBlobWithPrefix(c, containerURL, "a")
- createBlockBlobWithPrefix(c, containerURL, "b")
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{MaxResults: 1})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 1)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- }
- func (s *aztestsSuite) TestContainerListBlobsMaxResultsExact(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, blobName := createBlockBlobWithPrefix(c, containerURL, "a")
- _, blobName2 := createBlockBlobWithPrefix(c, containerURL, "b")
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{MaxResults: 2})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 2)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- c.Assert(resp.Blobs.Blob[1].Name, chk.Equals, blobName2)
- }
- func (s *aztestsSuite) TestContainerListBlobsMaxResultsSufficient(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, blobName := createBlockBlobWithPrefix(c, containerURL, "a")
- _, blobName2 := createBlockBlobWithPrefix(c, containerURL, "b")
- resp, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{MaxResults: 3})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob, chk.HasLen, 2)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- c.Assert(resp.Blobs.Blob[1].Name, chk.Equals, blobName2)
- }
- func (s *aztestsSuite) TestContainerListBlobsNonExistentContainer(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{})
- c.Assert(err, chk.NotNil)
- }
- func (s *aztestsSuite) TestContainerWithNewPipeline(c *chk.C) {
- bsu := getBSU()
- pipeline := testPipeline{}
- containerURL, _ := getContainerURL(c, bsu)
- containerURL = containerURL.WithPipeline(pipeline)
- _, err := containerURL.Create(ctx, azblob.Metadata{}, azblob.PublicAccessBlob)
- c.Assert(err, chk.NotNil)
- c.Assert(err.Error(), chk.Equals, testPipelineMessage)
- }
- func (s *aztestsSuite) TestContainerGetSetPermissionsMultiplePolicies(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- // Define the policies
- start := time.Now().UTC()
- expiry := start.Add(5 * time.Minute).UTC()
- expiry2 := start.Add(time.Minute).UTC()
- permissions := []azblob.SignedIdentifier{
- {ID: "0000",
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry,
- Permission: azblob.AccessPolicyPermission{Read: true, Write: true}.String(),
- },
- },
- {ID: "0001",
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry2,
- Permission: azblob.AccessPolicyPermission{Read: true}.String(),
- },
- },
- }
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, permissions,
- azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Value, chk.DeepEquals, permissions)
- }
- func (s *aztestsSuite) TestContainerGetPermissionsPublicAccessNotNone(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- containerURL.Create(ctx, nil, azblob.PublicAccessBlob) // We create the container explicitly so we can be sure the access policy is not empty
- defer deleteContainer(c, containerURL)
- resp, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.BlobPublicAccess(), chk.Equals, azblob.PublicAccessBlob)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsPublicAccessNone(c *chk.C) {
- // Test the basic one by making an anonymous request to ensure it's actually doing it and also with GetPermissions
- // For all the others, can just use GetPermissions since we've validated that it at least registers on the server correctly
- bsu := getBSU()
- containerURL, containerName := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, blobName := createNewBlockBlob(c, containerURL)
- // Container is created with PublicAccessBlob, so setting it to None will actually test that it is changed through this method
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- pipeline := azblob.NewPipeline(azblob.NewAnonymousCredential(), azblob.PipelineOptions{})
- bsu2 := azblob.NewServiceURL(bsu.URL(), pipeline)
- containerURL2 := bsu2.NewContainerURL(containerName)
- blobURL2 := containerURL2.NewBlockBlobURL(blobName)
- _, err = blobURL2.GetBlob(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{}, false)
- // Get permissions via the original container URL so the request succeeds
- resp, _ := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- // If we cannot access a blob's data, we will also not be able to enumerate blobs
- validateStorageError(c, err, azblob.ServiceCodeResourceNotFound)
- c.Assert(resp.BlobPublicAccess(), chk.Equals, azblob.PublicAccessNone)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsPublicAccessBlob(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.BlobPublicAccess(), chk.Equals, azblob.PublicAccessBlob)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsPublicAccessContainer(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessContainer, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.BlobPublicAccess(), chk.Equals, azblob.PublicAccessContainer)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsACLSinglePolicy(c *chk.C) {
- bsu := getBSU()
- credentials := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY"))
- containerURL, containerName := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, blobName := createNewBlockBlob(c, containerURL)
- start := time.Now().UTC().Add(-15 * time.Second)
- expiry := start.Add(5 * time.Minute).UTC()
- permissions := []azblob.SignedIdentifier{{
- ID: "0000",
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry,
- Permission: azblob.AccessPolicyPermission{List: true}.String(),
- },
- }}
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, permissions, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- serviceSASValues := azblob.BlobSASSignatureValues{Version: "2015-04-05",
- Identifier: "0000", ContainerName: containerName}
- queryParams := serviceSASValues.NewSASQueryParameters(credentials)
- sasURL := bsu.URL()
- sasURL.RawQuery = queryParams.Encode()
- sasPipeline := azblob.NewPipeline(azblob.NewAnonymousCredential(), azblob.PipelineOptions{})
- sasBlobServiceURL := azblob.NewServiceURL(sasURL, sasPipeline)
- // Verifies that the SAS can access the resource
- sasContainer := sasBlobServiceURL.NewContainerURL(containerName)
- resp, err := sasContainer.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Blobs.Blob[0].Name, chk.Equals, blobName)
- // Verifies that successful sas access is not just because it's public
- anonymousBlobService := azblob.NewServiceURL(bsu.URL(), sasPipeline)
- anonymousContainer := anonymousBlobService.NewContainerURL(containerName)
- _, err = anonymousContainer.ListBlobs(ctx, azblob.Marker{}, azblob.ListBlobsOptions{})
- validateStorageError(c, err, azblob.ServiceCodeResourceNotFound)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsACLMoreThanFive(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- start := time.Now().UTC()
- expiry := start.Add(5 * time.Minute).UTC()
- permissions := make([]azblob.SignedIdentifier, 6, 6)
- for i := 0; i < 6; i++ {
- permissions[i] = azblob.SignedIdentifier{
- ID: "000" + strconv.Itoa(i),
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry,
- Permission: azblob.AccessPolicyPermission{List: true}.String(),
- },
- }
- }
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, permissions, azblob.ContainerAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidXMLDocument)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsDeleteAndModifyACL(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- start := time.Now().UTC()
- expiry := start.Add(5 * time.Minute).UTC()
- permissions := make([]azblob.SignedIdentifier, 2, 2)
- for i := 0; i < 2; i++ {
- permissions[i] = azblob.SignedIdentifier{
- ID: "000" + strconv.Itoa(i),
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry,
- Permission: azblob.AccessPolicyPermission{List: true}.String(),
- },
- }
- }
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, permissions, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Value, chk.DeepEquals, permissions)
- permissions = resp.Value[:1] // Delete the first policy by removing it from the slice
- permissions[0].ID = "0004" // Modify the remaining policy which is at index 0 in the new slice
- _, err = containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, permissions, azblob.ContainerAccessConditions{})
- resp, err = containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Value, chk.HasLen, 1)
- c.Assert(resp.Value, chk.DeepEquals, permissions)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsDeleteAllPolicies(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- start := time.Now().UTC()
- expiry := start.Add(5 * time.Minute).UTC()
- permissions := make([]azblob.SignedIdentifier, 2, 2)
- for i := 0; i < 2; i++ {
- permissions[i] = azblob.SignedIdentifier{
- ID: "000" + strconv.Itoa(i),
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry,
- Permission: azblob.AccessPolicyPermission{List: true}.String(),
- },
- }
- }
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, permissions, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, []azblob.SignedIdentifier{}, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Value, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsInvalidPolicyTimes(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- // Swap start and expiry
- expiry := time.Now().UTC()
- start := expiry.Add(5 * time.Minute).UTC()
- permissions := make([]azblob.SignedIdentifier, 2, 2)
- for i := 0; i < 2; i++ {
- permissions[i] = azblob.SignedIdentifier{
- ID: "000" + strconv.Itoa(i),
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry,
- Permission: azblob.AccessPolicyPermission{List: true}.String(),
- },
- }
- }
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, permissions, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsNilPolicySlice(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsSignedIdentifierTooLong(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- id := ""
- for i := 0; i < 65; i++ {
- id += "a"
- }
- expiry := time.Now().UTC()
- start := expiry.Add(5 * time.Minute).UTC()
- permissions := make([]azblob.SignedIdentifier, 2, 2)
- for i := 0; i < 2; i++ {
- permissions[i] = azblob.SignedIdentifier{
- ID: id,
- AccessPolicy: azblob.AccessPolicy{
- Start: start,
- Expiry: expiry,
- Permission: azblob.AccessPolicyPermission{List: true}.String(),
- },
- }
- }
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, permissions, azblob.ContainerAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidXMLDocument)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- container, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, container)
- _, err := container.SetPermissions(ctx, azblob.PublicAccessNone, nil,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- resp, err := container.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.BlobPublicAccess(), chk.Equals, azblob.PublicAccessNone)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, nil,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsIfUnModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, nil,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPermissions(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.BlobPublicAccess(), chk.Equals, azblob.PublicAccessNone)
- }
- func (s *aztestsSuite) TestContainerSetPermissionsIfUnModifiedSinceFalse(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, nil,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestContainerGetPropertiesAndMetadataNoMetadata(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- resp, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestContainerGetPropsAndMetaNonExistantContainer(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeContainerNotFound)
- }
- func (s *aztestsSuite) TestContainerSetMetadataEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, basicMetadata, azblob.PublicAccessBlob)
- defer deleteContainer(c, containerURL)
- _, err = containerURL.SetMetadata(ctx, azblob.Metadata{}, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (*aztestsSuite) TestContainerSetMetadataNil(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.Create(ctx, basicMetadata, azblob.PublicAccessBlob)
- defer deleteContainer(c, containerURL)
- _, err = containerURL.SetMetadata(ctx, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (*aztestsSuite) TestContainerSetMetadataInvalidField(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetMetadata(ctx, azblob.Metadata{"!nval!d Field!@#%": "value"}, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.NotNil)
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func (*aztestsSuite) TestContainerSetMetadataNonExistant(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- _, err := containerURL.SetMetadata(ctx, nil, azblob.ContainerAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeContainerNotFound)
- }
- func (s *aztestsSuite) TestContainerSetMetadataIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetMetadata(ctx, basicMetadata,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- resp, err := containerURL.GetPropertiesAndMetadata(ctx, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestContainerSetMetadataIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := containerURL.SetMetadata(ctx, basicMetadata,
- azblob.ContainerAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestContainerNewBlobURL(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- blobURL := containerURL.NewBlobURL(blobPrefix)
- tempBlob := blobURL.URL()
- tempContainer := containerURL.URL()
- c.Assert(tempBlob.String(), chk.Equals, tempContainer.String()+"/"+blobPrefix)
- c.Assert(blobURL, chk.FitsTypeOf, azblob.BlobURL{})
- }
- func (s *aztestsSuite) TestContainerNewBlockBlobURL(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- blobURL := containerURL.NewBlockBlobURL(blobPrefix)
- tempBlob := blobURL.URL()
- tempContainer := containerURL.URL()
- c.Assert(tempBlob.String(), chk.Equals, tempContainer.String()+"/"+blobPrefix)
- c.Assert(blobURL, chk.FitsTypeOf, azblob.BlockBlobURL{})
- }
- func (s *aztestsSuite) TestBlobWithNewPipeline(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := getContainerURL(c, bsu)
- blobURL := containerURL.NewBlockBlobURL(blobPrefix)
- newBlobURL := blobURL.WithPipeline(testPipeline{})
- _, err := newBlobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.NotNil)
- c.Assert(err.Error(), chk.Equals, testPipelineMessage)
- }
- func waitForCopy(c *chk.C, copyBlobURL azblob.BlockBlobURL, blobCopyResponse *azblob.BlobsCopyResponse) {
- status := blobCopyResponse.CopyStatus()
- // Wait for the copy to finish. If the copy takes longer than a minute, we will fail
- start := time.Now()
- for status != azblob.CopyStatusSuccess {
- GetPropertiesAndMetadataResult, _ := copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- status = GetPropertiesAndMetadataResult.CopyStatus()
- currentTime := time.Now()
- if currentTime.Sub(start) >= time.Minute {
- c.Fail()
- }
- }
- }
- func (s *aztestsSuite) TestBlobStartCopyDestEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- copyBlobURL, _ := getBlockBlobURL(c, containerURL)
- blobCopyResponse, err := copyBlobURL.StartCopy(ctx, blobURL.URL(), nil, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- waitForCopy(c, copyBlobURL, blobCopyResponse)
- resp, err := copyBlobURL.GetBlob(ctx, azblob.BlobRange{Offset: 0, Count: 20}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- // Read the blob data to verify the copy
- data, _ := ioutil.ReadAll(resp.Response().Body)
- c.Assert(resp.ContentLength(), chk.Equals, int64(len(blockBlobDefaultData)))
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- resp.Body().Close()
- }
- func (s *aztestsSuite) TestBlobStartCopyMetadata(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- copyBlobURL, _ := getBlockBlobURL(c, containerURL)
- resp, err := copyBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- waitForCopy(c, copyBlobURL, resp)
- resp2, err := copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopyMetadataNil(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- copyBlobURL, _ := getBlockBlobURL(c, containerURL)
- // Have the destination start with metadata so we ensure the nil metadata passed later takes effect
- _, err := copyBlobURL.PutBlob(ctx, bytes.NewReader([]byte("data")), azblob.BlobHTTPHeaders{},
- basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := copyBlobURL.StartCopy(ctx, blobURL.URL(), nil, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- waitForCopy(c, copyBlobURL, resp)
- resp2, err := copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobStartCopyMetadataEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- copyBlobURL, _ := getBlockBlobURL(c, containerURL)
- // Have the destination start with metadata so we ensure the empty metadata passed later takes effect
- _, err := copyBlobURL.PutBlob(ctx, bytes.NewReader([]byte("data")), azblob.BlobHTTPHeaders{},
- basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := copyBlobURL.StartCopy(ctx, blobURL.URL(), azblob.Metadata{}, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- waitForCopy(c, copyBlobURL, resp)
- resp2, err := copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobStartCopyMetadataInvalidField(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- copyBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := copyBlobURL.StartCopy(ctx, blobURL.URL(), azblob.Metadata{"I nvalid.": "bar"}, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.NotNil)
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceNonExistant(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- copyBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := copyBlobURL.StartCopy(ctx, blobURL.URL(), nil, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeBlobNotFound)
- }
- func (s *aztestsSuite) TestBlobStartCopySourcePrivate(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- bsu2, err := getAlternateBSU()
- if err != nil {
- c.Skip(err.Error())
- return
- }
- copyContainerURL, _ := createNewContainer(c, bsu2)
- defer deleteContainer(c, copyContainerURL)
- copyBlobURL, _ := getBlockBlobURL(c, copyContainerURL)
- if bsu.String() == bsu2.String() {
- c.Skip("Test not valid because primary and secondary accounts are the same")
- }
- _, err = copyBlobURL.StartCopy(ctx, blobURL.URL(), nil, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeCannotVerifyCopySource)
- }
- func (s *aztestsSuite) TestBlobStartCopyUsingSASSrc(c *chk.C) {
- bsu := getBSU()
- containerURL, containerName := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- blobURL, blobName := createNewBlockBlob(c, containerURL)
- // Create sas values for the source blob
- credentials := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY"))
- serviceSASValues := azblob.BlobSASSignatureValues{Version: "2015-04-05", StartTime: time.Now().Add(-1 * time.Hour).UTC(),
- ExpiryTime: time.Now().Add(time.Hour).UTC(), Permissions: azblob.BlobSASPermissions{Read: true, Write: true}.String(),
- ContainerName: containerName, BlobName: blobName}
- queryParams := serviceSASValues.NewSASQueryParameters(credentials)
- // Create URLs to the destination blob with sas parameters
- sasURL := blobURL.URL()
- sasURL.RawQuery = queryParams.Encode()
- // Create a new container for the destination
- bsu2, err := getAlternateBSU()
- if err != nil {
- c.Skip(err.Error())
- return
- }
- copyContainerURL, _ := createNewContainer(c, bsu2)
- defer deleteContainer(c, copyContainerURL)
- copyBlobURL, _ := getBlockBlobURL(c, copyContainerURL)
- resp, err := copyBlobURL.StartCopy(ctx, sasURL, nil, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- waitForCopy(c, copyBlobURL, resp)
- resp2, err := copyBlobURL.GetBlob(ctx, azblob.BlobRange{Offset: 0, Count: int64(len(blockBlobDefaultData))}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, err := ioutil.ReadAll(resp2.Response().Body)
- c.Assert(resp2.ContentLength(), chk.Equals, int64(len(blockBlobDefaultData)))
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- resp2.Body().Close()
- }
- func (s *aztestsSuite) TestBlobStartCopyUsingSASDest(c *chk.C) {
- bsu := getBSU()
- containerURL, containerName := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- _, err := containerURL.SetPermissions(ctx, azblob.PublicAccessNone, nil, azblob.ContainerAccessConditions{})
- c.Assert(err, chk.IsNil)
- blobURL, blobName := createNewBlockBlob(c, containerURL)
- _ = blobURL
- // Generate SAS on the source
- serviceSASValues := azblob.BlobSASSignatureValues{ExpiryTime: time.Now().Add(time.Hour).UTC(),
- Permissions: azblob.BlobSASPermissions{Read: true, Write: true, Create: true}.String(), ContainerName: containerName, BlobName: blobName}
- credentials := azblob.NewSharedKeyCredential(os.Getenv("ACCOUNT_NAME"), os.Getenv("ACCOUNT_KEY"))
- queryParams := serviceSASValues.NewSASQueryParameters(credentials)
- // Create destination container
- bsu2, err := getAlternateBSU()
- if err != nil {
- c.Skip(err.Error())
- return
- }
- copyContainerURL, copyContainerName := createNewContainer(c, bsu2)
- defer deleteContainer(c, copyContainerURL)
- copyBlobURL, copyBlobName := getBlockBlobURL(c, copyContainerURL)
- // Generate Sas for the destination
- credentials = azblob.NewSharedKeyCredential(os.Getenv("SECONDARY_ACCOUNT_NAME"), os.Getenv("SECONDARY_ACCOUNT_KEY"))
- copyServiceSASvalues := azblob.BlobSASSignatureValues{StartTime: time.Now().Add(-1 * time.Hour).UTC(),
- ExpiryTime: time.Now().Add(time.Hour).UTC(), Permissions: azblob.BlobSASPermissions{Read: true, Write: true}.String(),
- ContainerName: copyContainerName, BlobName: copyBlobName}
- copyQueryParams := copyServiceSASvalues.NewSASQueryParameters(credentials)
- // Generate anonymous URL to destination with SAS
- anonURL := bsu2.URL()
- anonURL.RawQuery = copyQueryParams.Encode()
- anonPipeline := azblob.NewPipeline(azblob.NewAnonymousCredential(), azblob.PipelineOptions{})
- anonBSU := azblob.NewServiceURL(anonURL, anonPipeline)
- anonContainerURL := anonBSU.NewContainerURL(copyContainerName)
- anonBlobURL := anonContainerURL.NewBlockBlobURL(copyBlobName)
- // Apply sas to source
- srcBlobWithSasURL := blobURL.URL()
- srcBlobWithSasURL.RawQuery = queryParams.Encode()
- resp, err := anonBlobURL.StartCopy(ctx, srcBlobWithSasURL, nil, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- // Allow copy to happen
- waitForCopy(c, anonBlobURL, resp)
- resp2, err := copyBlobURL.GetBlob(ctx, azblob.BlobRange{Offset: 0, Count: int64(len(blockBlobDefaultData))}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, err := ioutil.ReadAll(resp2.Response().Body)
- _, err = resp2.Body().Read(data)
- c.Assert(resp2.ContentLength(), chk.Equals, int64(len(blockBlobDefaultData)))
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- resp2.Body().Close()
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}},
- azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}},
- azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeSourceConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}},
- azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}},
- azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeSourceConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- etag := resp.ETag()
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err = destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: etag}},
- azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp2, err := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: "a"}},
- azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeSourceConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: "a"}},
- azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp2, err := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopySourceIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- etag := resp.ETag()
- destBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err = destBlobURL.StartCopy(ctx, blobURL.URL(), nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: etag}},
- azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeSourceConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := createNewBlockBlob(c, containerURL) // The blob must exist to have a last-modified time
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- resp, err := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), nil,
- azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeTargetConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- resp, err := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- destBlobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), nil,
- azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeTargetConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata,
- azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: etag}})
- c.Assert(err, chk.IsNil)
- resp, err = destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- destBlobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{}) // SetMetadata chances the blob's etag
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), nil, azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: etag}})
- validateStorageError(c, err, azblob.ServiceCodeTargetConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- destBlobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{}) // SetMetadata chances the blob's etag
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), basicMetadata, azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: etag}})
- c.Assert(err, chk.IsNil)
- resp, err = destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobStartCopyDestIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- destBlobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := destBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- _, err := destBlobURL.StartCopy(ctx, blobURL.URL(), nil, azblob.BlobAccessConditions{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: etag}})
- validateStorageError(c, err, azblob.ServiceCodeTargetConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAbortCopyInProgress(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- // Create a large blob that takes time to copy
- blobSize := 8 * 1024 * 1024
- blobData := make([]byte, blobSize, blobSize)
- for i := range blobData {
- blobData[i] = byte('a' + i%26)
- }
- _, err := blobURL.PutBlob(ctx, bytes.NewReader(blobData), azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- containerURL.SetPermissions(ctx, azblob.PublicAccessBlob, nil, azblob.ContainerAccessConditions{}) // So that we don't have to create a SAS
- // Must copy across accounts so it takes time to copy
- bsu2, err := getAlternateBSU()
- if err != nil {
- c.Skip(err.Error())
- return
- }
- copyContainerURL, _ := createNewContainer(c, bsu2)
- copyBlobURL, _ := getBlockBlobURL(c, copyContainerURL)
- defer deleteContainer(c, copyContainerURL)
- resp, err := copyBlobURL.StartCopy(ctx, blobURL.URL(), nil, azblob.BlobAccessConditions{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CopyStatus(), chk.Equals, azblob.CopyStatusPending)
- _, err = copyBlobURL.AbortCopy(ctx, resp.CopyID(), azblob.LeaseAccessConditions{})
- if err != nil {
- // If the error is nil, the test continues as normal.
- // If the error is not nil, we want to check if it's because the copy is finished and send a message indicating this.
- validateStorageError(c, err, azblob.ServiceCodeNoPendingCopyOperation)
- c.Error("The test failed because the copy completed because it was aborted")
- }
- resp2, _ := copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(resp2.CopyStatus(), chk.Equals, azblob.CopyStatusAborted)
- }
- func (s *aztestsSuite) TestBlobAbortCopyNoCopyStarted(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- copyBlobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := copyBlobURL.AbortCopy(ctx, "copynotstarted", azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidQueryParameterValue)
- }
- func (s *aztestsSuite) TestBlobSnapshotMetadata(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.CreateSnapshot(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- // Since metadata is specified on the snapshot, the snapshot should have its own metadata different from the (empty) metadata on the source
- snapshotURL := blobURL.WithSnapshot(resp.Snapshot())
- resp2, err := snapshotURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobSnapshotMetadataEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.CreateSnapshot(ctx, azblob.Metadata{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- // In this case, because no metadata was specified, it should copy the basicMetadata from the source
- snapshotURL := blobURL.WithSnapshot(resp.Snapshot())
- resp2, err := snapshotURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobSnapshotMetadataNil(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- snapshotURL := blobURL.WithSnapshot(resp.Snapshot())
- resp2, err := snapshotURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobSnapshotMetadataInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, azblob.Metadata{"Invalid Field!": "value"}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.NotNil)
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func (s *aztestsSuite) TestBlobSnapshotBlobNotExist(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeBlobNotFound)
- }
- func (s *aztestsSuite) TestBlobSnapshotOfSnapshot(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- snapshotURL := blobURL.WithSnapshot(time.Now().UTC())
- // The library allows the server to handle the snapshot of snapshot error
- _, err := snapshotURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidQueryParameterValue)
- }
- func (s *aztestsSuite) TestBlobSnapshotIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Snapshot().IsZero(), chk.Equals, false) // i.e. The snapshot time is not zero. If the service gives us back a snapshot time, it successfully created a snapshot
- }
- func (s *aztestsSuite) TestBlobSnapshotIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSnapshotIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- resp, err := blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Snapshot().IsZero(), chk.Equals, false)
- }
- func (s *aztestsSuite) TestBlobSnapshotIfUnmodifiedSinceFalse(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSnapshotIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- resp2, err := blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.Snapshot().IsZero(), chk.Equals, false)
- }
- func (s *aztestsSuite) TestBlobSnapshotIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: "garbage"}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSnapshotIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: "garbage"}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.Snapshot().IsZero(), chk.Equals, false)
- }
- func (s *aztestsSuite) TestBlobSnapshotIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err = blobURL.CreateSnapshot(ctx, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDownloadDataNonExistantBlob(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.GetBlob(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{}, false)
- validateStorageError(c, err, azblob.ServiceCodeBlobNotFound)
- }
- func (s *aztestsSuite) TestBlobDownloadDataNegativeOffset(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- defer func() { // The library should fail if it seems numeric parameters that are guaranteed invalid
- recover()
- }()
- blobURL.GetBlob(ctx, azblob.BlobRange{Offset: -1}, azblob.BlobAccessConditions{}, false)
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobDownloadDataOffsetOutOfRange(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.GetBlob(ctx, azblob.BlobRange{Offset: int64(len(blockBlobDefaultData))}, azblob.BlobAccessConditions{}, false)
- validateStorageError(c, err, azblob.ServiceCodeInvalidRange)
- }
- func (s *aztestsSuite) TestBlobDownloadDataCountNegative(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- defer func() { // The library should panic if it sees numeric parameters that are guaranteed invalid
- recover()
- }()
- blobURL.GetBlob(ctx, azblob.BlobRange{Count: -1}, azblob.BlobAccessConditions{}, false)
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobDownloadDataCountZero(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{Count: 0}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- // Specifying a count of 0 results in the value being ignored
- data, err := ioutil.ReadAll(resp.Response().Body)
- c.Assert(err, chk.IsNil)
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- }
- func (s *aztestsSuite) TestBlobDownloadDataCountExact(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{Count: int64(len(blockBlobDefaultData))}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, err := ioutil.ReadAll(resp.Response().Body)
- c.Assert(err, chk.IsNil)
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- }
- func (s *aztestsSuite) TestBlobDownloadDataCountOutOfRange(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{Count: int64(len(blockBlobDefaultData)) * 2}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, err := ioutil.ReadAll(resp.Response().Body)
- c.Assert(err, chk.IsNil)
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- }
- func (s *aztestsSuite) TestBlobDownloadDataEmptyRangeStruct(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, err := ioutil.ReadAll(resp.Response().Body)
- c.Assert(err, chk.IsNil)
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- }
- func (s *aztestsSuite) TestBlobDownloadDataContentMD5(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{Offset: 10, Count: 3}, azblob.BlobAccessConditions{}, true)
- c.Assert(err, chk.IsNil)
- mdf := md5.Sum([]byte(blockBlobDefaultData)[10:13])
- c.Assert(resp.ContentMD5(), chk.Equals, mdf)
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}}, false)
- c.Assert(err, chk.IsNil)
- c.Assert(resp.ContentLength(), chk.Equals, int64(len(blockBlobDefaultData)))
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}}, false)
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304) // The server does not return the error in the body even though it is a GET
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}}, false)
- c.Assert(err, chk.IsNil)
- c.Assert(resp.ContentLength(), chk.Equals, int64(len(blockBlobDefaultData)))
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfUnmodifiedSinceFalse(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}}, false)
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- etag := resp.ETag()
- resp2, err := blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: etag}}, false)
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.ContentLength(), chk.Equals, int64(len(blockBlobDefaultData)))
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- etag := resp.ETag()
- blobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{})
- _, err = blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: etag}}, false)
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- etag := resp.ETag()
- blobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{})
- resp2, err := blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: etag}}, false)
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.ContentLength(), chk.Equals, int64(len(blockBlobDefaultData)))
- }
- func (s *aztestsSuite) TestBlobDownloadDataIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- etag := resp.ETag()
- _, err = blobURL.GetBlob(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: etag}}, false)
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304) // The server does not return the error in the body even though it is a GET
- }
- func (s *aztestsSuite) TestBlobDeleteNonExistant(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionInclude, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeBlobNotFound)
- }
- func (s *aztestsSuite) TestBlobDeleteSnapshot(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- snapshotURL := blobURL.WithSnapshot(resp.Snapshot())
- _, err = snapshotURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- validateBlobDeleted(c, snapshotURL)
- }
- func (s *aztestsSuite) TestBlobDeleteSnapshotsInclude(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionInclude, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, _ := containerURL.ListBlobs(ctx, azblob.Marker{},
- azblob.ListBlobsOptions{Details: azblob.BlobListingDetails{Snapshots: true}})
- c.Assert(resp.Blobs.Blob, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobDeleteSnapshotsOnly(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionOnly, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, _ := containerURL.ListBlobs(ctx, azblob.Marker{},
- azblob.ListBlobsOptions{Details: azblob.BlobListingDetails{Snapshots: true}})
- c.Assert(resp.Blobs.Blob, chk.HasLen, 1)
- c.Assert(resp.Blobs.Blob[0].Snapshot.IsZero(), chk.Equals, true)
- }
- func (s *aztestsSuite) TestBlobDeleteSnapshotsNoneWithSnapshots(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeSnapshotsPresent)
- }
- func validateBlobDeleted(c *chk.C, blobURL azblob.BlockBlobURL) {
- _, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.NotNil)
- serr := err.(azblob.StorageError) // Delete blob is a HEAD request and does not return a ServiceCode in the body
- c.Assert(serr.Response().StatusCode, chk.Equals, 404)
- }
- func (s *aztestsSuite) TestBlobDeleteIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateBlobDeleted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobDeleteIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDeleteIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateBlobDeleted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobDeleteIfUnmodifiedSinceFalse(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDeleteIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: etag}})
- c.Assert(err, chk.IsNil)
- validateBlobDeleted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobDeleteIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- blobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{})
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: etag}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDeleteIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- blobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{})
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: etag}})
- c.Assert(err, chk.IsNil)
- validateBlobDeleted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobDeleteIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- etag := resp.ETag()
- _, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: etag}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlobNonEmptyBody(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlob(ctx, strings.NewReader(blockBlobDefaultData), azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, _ := ioutil.ReadAll(resp.Response().Body)
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- }
- func (s *aztestsSuite) TestBlobPutBlobHTTPHeaders(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlob(ctx, nil, basicHeaders, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- h := resp.NewHTTPHeaders()
- c.Assert(h, chk.DeepEquals, basicHeaders)
- }
- func (s *aztestsSuite) TestBlobPutBlobMetadataNotEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobPutBlobMetadataEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobPutBlobMetadataInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, azblob.Metadata{"In valid!": "bar"}, azblob.BlobAccessConditions{})
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func validatePutBlob(c *chk.C, blobURL azblob.BlockBlobURL) {
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, _ := ioutil.ReadAll(resp.Response().Body)
- c.Assert(data, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePutBlob(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePutBlob(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validatePutBlob(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validatePutBlob(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlobIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlob(ctx, nil, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- currentTime := getRelativeTimeGMT(10)
- _, err = blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.NotNil)
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304) // No service code returned for a HEAD
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- currentTime := getRelativeTimeGMT(10)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.NotNil)
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 412)
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp2, err := blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.NotNil)
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 412)
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobGetPropsAndMetadataIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.GetPropertiesAndMetadata(ctx,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- c.Assert(err, chk.NotNil)
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304)
- }
- func (s *aztestsSuite) TestBlobSetPropertiesBasic(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetProperties(ctx, basicHeaders, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- h := resp.NewHTTPHeaders()
- c.Assert(h, chk.DeepEquals, basicHeaders)
- }
- func (s *aztestsSuite) TestBlobSetPropertiesEmptyValue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentType: "my_type"}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.ContentType(), chk.Equals, "")
- }
- func validatePropertiesSet(c *chk.C, blobURL azblob.BlockBlobURL, str string) {
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.ContentDisposition(), chk.Equals, "my_disposition")
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePropertiesSet(c, blobURL, "my_disposition")
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePropertiesSet(c, blobURL, "my_disposition")
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfUnmodifiedSinceFalse(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validatePropertiesSet(c, blobURL, "my_disposition")
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validatePropertiesSet(c, blobURL, "my_disposition")
- }
- func (s *aztestsSuite) TestBlobSetPropertiesIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.SetProperties(ctx, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetMetadataNil(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, azblob.Metadata{"not": "nil"}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.SetMetadata(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobSetMetadataEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, azblob.Metadata{"not": "nil"}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.SetMetadata(ctx, azblob.Metadata{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobSetMetadataInvalidField(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, azblob.Metadata{"Invalid field!": "value"}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.NotNil)
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func validateMetadataSet(c *chk.C, blobURL azblob.BlockBlobURL) {
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfModifiedSinceTrue(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateMetadataSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateMetadataSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfUnmodifiedSinceFalse(c *chk.C) {
- currentTime := getRelativeTimeGMT(-10)
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateMetadataSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- _, err := blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateMetadataSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetMetadataIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewBlockBlob(c, containerURL)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.SetMetadata(ctx, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobGetBlockListNone(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListNone, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 0)
- c.Assert(resp.UncommittedBlocks, chk.HasLen, 0) // Not specifying a block list type should default to only returning committed blocks
- }
- func (s *aztestsSuite) TestBlobGetBlockListUncommitted(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListUncommitted, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 0)
- c.Assert(resp.UncommittedBlocks, chk.HasLen, 1)
- }
- func (s *aztestsSuite) TestBlobGetBlockListCommitted(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{"0000"}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListCommitted, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 1)
- c.Assert(resp.UncommittedBlocks, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobGetBlockListCommittedEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListCommitted, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 0)
- c.Assert(resp.UncommittedBlocks, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobGetBlockListBothEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeBlobNotFound)
- }
- func (s *aztestsSuite) TestBlobGetBlockListBothNotEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- // Put and commit two blocks
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlock(ctx, "0001", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{"0001", "0000"}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- // Put two uncommitted blocks
- _, err = blobURL.PutBlock(ctx, "0003", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlock(ctx, "0002", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks[0].Name, chk.Equals, "0001")
- c.Assert(resp.CommittedBlocks[1].Name, chk.Equals, "0000") // Committed blocks are returned in the order they are committed (in the commit list)
- c.Assert(resp.UncommittedBlocks[0].Name, chk.Equals, "0002") // Uncommitted blocks are returned in alphabetical order
- c.Assert(resp.UncommittedBlocks[1].Name, chk.Equals, "0003")
- }
- func (s *aztestsSuite) TestBlobGetBlockListInvalidType(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.GetBlockList(ctx, azblob.BlockListType("garbage"), azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidQueryParameterValue)
- }
- func (s *aztestsSuite) TestBlobGetBlockListSnapshot(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{"0000"}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- snapshotURL := blobURL.WithSnapshot(resp.Snapshot())
- resp2, err := snapshotURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp2.CommittedBlocks, chk.HasLen, 1)
- }
- func (s *aztestsSuite) TestBlobPutBlockIDInvalidCharacters(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "!!", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidQueryParameterValue)
- }
- func (s *aztestsSuite) TestBlobPutBlockIDInvalidLength(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlock(ctx, "00000000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidBlobOrBlock)
- }
- func (s *aztestsSuite) TestBlobPutBlockEmptyBody(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(""), azblob.LeaseAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeMissingContentLengthHeader) // The server does not accept getReaderToRandomBytes length = 0
- }
- func setupPutBlockListTest(c *chk.C) (containerURL azblob.ContainerURL, blobURL azblob.BlockBlobURL, id string) {
- bsu := getBSU()
- containerURL, _ = createNewContainer(c, bsu)
- blobURL, _ = getBlockBlobURL(c, containerURL)
- _, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- id = "0000"
- return
- }
- func (s *aztestsSuite) TestBlobPutBlockListInvalidID(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id[:2]}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidBlockID)
- }
- func (s *aztestsSuite) TestBlobPutBlockListDuplicateBlocks(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id, id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 2)
- }
- func (s *aztestsSuite) TestBlobPutBlockListEmptyList(c *chk.C) {
- containerURL, blobURL, _ := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{}, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobPutBlockListMetadataEmpty(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobPutBlockListMetadataNonEmpty(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, basicMetadata, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobPutBlockListHTTPHeaders(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, basicHeaders, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- h := resp.NewHTTPHeaders()
- c.Assert(h, chk.DeepEquals, basicHeaders)
- }
- func (s *aztestsSuite) TestBlobPutBlockListHTTPHeadersEmpty(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.ContentDisposition(), chk.Equals, "")
- }
- func validateBlobCommitted(c *chk.C, blobURL azblob.BlockBlobURL) {
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 1)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfModifiedSinceTrue(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
- c.Assert(err, chk.IsNil)
- currentTime := getRelativeTimeGMT(-10)
- _, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateBlobCommitted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfModifiedSinceFalse(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfUnmodifiedSinceTrue(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
- c.Assert(err, chk.IsNil)
- currentTime := getRelativeTimeGMT(10)
- _, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateBlobCommitted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfUnmodifiedSinceFalse(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfMatchTrue(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- resp, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateBlobCommitted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfMatchFalse(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfNoneMatchTrue(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateBlobCommitted(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutBlockListIfNoneMatchFalse(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- resp, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutBlockListValidateData(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{})
- resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{}, false)
- c.Assert(err, chk.IsNil)
- data, _ := ioutil.ReadAll(resp.Response().Body)
- c.Assert(string(data), chk.Equals, blockBlobDefaultData)
- }
- func (s *aztestsSuite) TestBlobPutBlockListModifyBlob(c *chk.C) {
- containerURL, blobURL, id := setupPutBlockListTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlock(ctx, "0001", bytes.NewReader([]byte("new data")), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlock(ctx, "0010", bytes.NewReader([]byte("new data")), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlock(ctx, "0011", bytes.NewReader([]byte("new data")), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlock(ctx, "0100", bytes.NewReader([]byte("new data")), azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.PutBlockList(ctx, []string{"0001", "0011"}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.CommittedBlocks, chk.HasLen, 2)
- c.Assert(resp.CommittedBlocks[0].Name, chk.Equals, "0001")
- c.Assert(resp.CommittedBlocks[1].Name, chk.Equals, "0011")
- c.Assert(resp.UncommittedBlocks, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobCreateAppendMetadataNonEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getAppendBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{}, basicMetadata,azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobCreateAppendMetadataEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getAppendBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{}, azblob.Metadata{},azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobCreateAppendMetadataInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getAppendBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{}, azblob.Metadata{"In valid!": "bar"}, azblob.BlobAccessConditions{})
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func (s *aztestsSuite) TestBlobCreateAppendHTTPHeaders(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getAppendBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, basicHeaders, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- h := resp.NewHTTPHeaders()
- c.Assert(h, chk.DeepEquals, basicHeaders)
- }
- func validateAppendBlobPut(c *chk.C, blobURL azblob.AppendBlobURL) {
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateAppendBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateAppendBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateAppendBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateAppendBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreateAppendIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAppendBlockNilBody(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.NotNil)
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func (s *aztestsSuite) TestBlobAppendBlockEmptyBody(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(""), azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeMissingContentLengthHeader) // The server does not accept getReaderToRandomBytes length = 0
- }
- func (s *aztestsSuite) TestBlobAppendBlockNonExistantBlob(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getAppendBlobURL(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData), azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeBlobNotFound)
- }
- func validateBlockAppended(c *chk.C, blobURL azblob.AppendBlobURL, expectedSize int) {
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.ContentLength(), chk.Equals, int64(expectedSize))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, len(blockBlobDefaultData))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, len(blockBlobDefaultData))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, len(blockBlobDefaultData))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, len(blockBlobDefaultData))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfAppendPositionMatchTrueNegOne(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{AppendBlobAccessConditions: azblob.AppendBlobAccessConditions{IfAppendPositionEqual: -1}}) // This will cause the library to set the value of the header to 0
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, len(blockBlobDefaultData))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfAppendPositionMatchZero(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData), azblob.BlobAccessConditions{}) // The position will not match, but the condition should be ignored
- c.Assert(err, chk.IsNil)
- _, err = blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{AppendBlobAccessConditions: azblob.AppendBlobAccessConditions{IfAppendPositionEqual: 0}})
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, 2*len(blockBlobDefaultData))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfAppendPositionMatchTrueNonZero(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{AppendBlobAccessConditions: azblob.AppendBlobAccessConditions{IfAppendPositionEqual: int32(len(blockBlobDefaultData))}})
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, len(blockBlobDefaultData)*2)
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfAppendPositionMatchFalseNegOne(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{AppendBlobAccessConditions: azblob.AppendBlobAccessConditions{IfAppendPositionEqual: -1}}) // This will cause the library to set the value of the header to 0
- validateStorageError(c, err, azblob.ServiceCodeAppendPositionConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfAppendPositionMatchFalseNonZero(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{AppendBlobAccessConditions: azblob.AppendBlobAccessConditions{IfAppendPositionEqual: 12}})
- validateStorageError(c, err, azblob.ServiceCodeAppendPositionConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfMaxSizeTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{AppendBlobAccessConditions: azblob.AppendBlobAccessConditions{IfMaxSizeLessThanOrEqual: int32(len(blockBlobDefaultData) + 1)}})
- c.Assert(err, chk.IsNil)
- validateBlockAppended(c, blobURL, len(blockBlobDefaultData))
- }
- func (s *aztestsSuite) TestBlobAppendBlockIfMaxSizeFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewAppendBlob(c, containerURL)
- _, err := blobURL.AppendBlock(ctx, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{AppendBlobAccessConditions: azblob.AppendBlobAccessConditions{IfMaxSizeLessThanOrEqual: int32(len(blockBlobDefaultData) - 1)}})
- validateStorageError(c, err, azblob.ServiceCodeMaxBlobSizeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobCreatePageSizeInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getPageBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, 1, 0, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidHeaderValue)
- }
- func (s *aztestsSuite) TestBlobCreatePageSequenceInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getPageBlobURL(c, containerURL)
- // Negative sequenceNumber should cause a panic
- defer func() {
- recover()
- }()
- blobURL.Create(ctx, azblob.PageBlobPageBytes, -1, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobCreatePageMetadataNonEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getPageBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, basicMetadata,azblob.BlobAccessConditions{})
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobCreatePageMetadataEmpty(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getPageBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobCreatePageMetadataInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getPageBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, azblob.Metadata{"In valid1": "bar"}, azblob.BlobAccessConditions{})
- c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
- }
- func (s *aztestsSuite) TestBlobCreatePageHTTPHeaders(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getPageBlobURL(c, containerURL)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicHeaders, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- h := resp.NewHTTPHeaders()
- c.Assert(h, chk.DeepEquals, basicHeaders)
- }
- func validatePageBlobPut(c *chk.C, blobURL azblob.PageBlobURL) {
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewMetadata(), chk.DeepEquals, basicMetadata)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePageBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePageBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validatePageBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validatePageBlobPut(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobCreatePageIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesInvalidRange(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- defer func() { // The library should panic if the page range is invalid in any way
- recover()
- }()
- blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: int32(len(blockBlobDefaultData))}, strings.NewReader(blockBlobDefaultData),
- azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobPutPagesNilBody(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- // A page range that starts and ends at 0 should panic
- defer func() {
- recover()
- }()
- blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: 0}, nil, azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobPutPagesEmptyBody(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- // A page range that starts and ends at 0 should panic
- defer func() {
- recover()
- }()
- blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: 0}, bytes.NewReader([]byte{}), azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobPutPagesNonExistantBlob(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := getPageBlobURL(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes), azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeBlobNotFound)
- }
- func validatePutPages(c *chk.C, blobURL azblob.PageBlobURL) {
- // This will only validate a single put page at 0-azblob.PageBlobPageBytes-1
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.PageRange[0], chk.Equals, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1})
- }
- func (s *aztestsSuite) TestBlobPutPagesIfModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberLessThanTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThan: 10}})
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberLessThanFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 10, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThan: 1}})
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberLessThanNegOne(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThan: -1}}) // This will cause the library to set the value of the header to 0
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberLTETrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 1, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThanOrEqual: 1}})
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberLTEqualFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 10, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThanOrEqual: 1}})
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberLTENegOne(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThanOrEqual: -1}}) // This will cause the library to set the value of the header to 0
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberEqualTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 1, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberEqual: 1}})
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberEqualFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberEqual: 1}})
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobPutPagesIfSequenceNumberEqualNegOne(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes),
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberEqual: -1}}) // This will cause the library to set the value of the header to 0
- c.Assert(err, chk.IsNil)
- validatePutPages(c, blobURL)
- }
- func setupClearPagesTest(c *chk.C) (azblob.ContainerURL, azblob.PageBlobURL) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- return containerURL, blobURL
- }
- func validateClearPagesTest(c *chk.C, blobURL azblob.PageBlobURL) {
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.PageRange, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobClearPagesInvalidRange(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- // A misaligned page range will panic (End is set to n*512 instead of (n*512)-1 as is required)
- defer func() {
- recover()
- }()
- blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes}, azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobClearPagesIfModifiedSinceTrue(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfModifiedSinceFalse(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfUnmodifiedSinceTrue(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfUnmodifiedSinceFalse(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfMatchTrue(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfMatchFalse(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfNoneMatchTrue(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfNoneMatchFalse(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberLessThanTrue(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThan: 10}})
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberLessThanFalse(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 10, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThan: 1}})
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberLessThanNegOne(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThan: -1}}) // This will cause the library to set the value of the header to 0
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberLTETrue(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThanOrEqual: 10}})
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberLTEFalse(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 10, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThanOrEqual: 1}})
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberLTENegOne(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberLessThanOrEqual: -1}}) // This will cause the library to set the value of the header to 0
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberEqualTrue(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 10, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberEqual: 10}})
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberEqualFalse(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, 10, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- _, err = blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberEqual: 1}})
- validateStorageError(c, err, azblob.ServiceCodeSequenceNumberConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobClearPagesIfSequenceNumberEqualNegOne(c *chk.C) {
- containerURL, blobURL := setupClearPagesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.ClearPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1},
- azblob.BlobAccessConditions{PageBlobAccessConditions: azblob.PageBlobAccessConditions{IfSequenceNumberEqual: -1}}) // This will cause the library to set the value of the header to 0
- c.Assert(err, chk.IsNil)
- validateClearPagesTest(c, blobURL)
- }
- func setupGetPageRangesTest(c *chk.C) (containerURL azblob.ContainerURL, blobURL azblob.PageBlobURL) {
- bsu := getBSU()
- containerURL, _ = createNewContainer(c, bsu)
- blobURL, _ = createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- return
- }
- func validateBasicGetPageRanges(c *chk.C, resp *azblob.PageList, err error) {
- c.Assert(err, chk.IsNil)
- c.Assert(resp.PageRange, chk.HasLen, 1)
- c.Assert(resp.PageRange[0], chk.Equals, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1})
- }
- func (s *aztestsSuite) TestBlobGetPageRangesEmptyBlob(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.PageRange, chk.HasLen, 0)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesEmptyRange(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{})
- validateBasicGetPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesInvalidRange(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- defer func() { // Invalid blob range should panic
- recover()
- }()
- blobURL.GetPageRanges(ctx, azblob.BlobRange{Offset: -2, Count: 500}, azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobGetPageRangesNonContiguousRanges(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: azblob.PageBlobPageBytes * 2, End: (azblob.PageBlobPageBytes * 3) - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.PageRange, chk.HasLen, 2)
- c.Assert(resp.PageRange[0], chk.Equals, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1})
- c.Assert(resp.PageRange[1], chk.Equals, azblob.PageRange{Start: azblob.PageBlobPageBytes * 2, End: (azblob.PageBlobPageBytes * 3) - 1})
- }
- func (s *aztestsSuite) TestblobGetPageRangesNotPageAligned(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{Offset: 0, Count: 2000}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- validateBasicGetPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesSnapshot(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- snapshotURL := blobURL.WithSnapshot(resp.Snapshot())
- resp2, err := snapshotURL.GetPageRanges(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- validateBasicGetPageRanges(c, resp2, err)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfModifiedSinceTrue(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateBasicGetPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfModifiedSinceFalse(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304) // Service Code not returned in the body for a HEAD
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfUnmodifiedSinceTrue(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateBasicGetPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfUnmodifiedSinceFalse(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfMatchTrue(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- resp2, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- validateBasicGetPageRanges(c, resp2, err)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfMatchFalse(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfNoneMatchTrue(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- validateBasicGetPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobGetPageRangesIfNoneMatchFalse(c *chk.C) {
- containerURL, blobURL := setupGetPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.GetPageRanges(ctx, azblob.BlobRange{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304) // Service Code not returned in the body for a HEAD
- }
- func setupDiffPageRangesTest(c *chk.C) (containerURL azblob.ContainerURL, blobURL azblob.PageBlobURL, snapshot time.Time) {
- bsu := getBSU()
- containerURL, _ = createNewContainer(c, bsu)
- blobURL, _ = createNewPageBlob(c, containerURL)
- _, err := blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- snapshot = resp.Snapshot()
- _, err = blobURL.PutPages(ctx, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1}, getReaderToRandomBytes(azblob.PageBlobPageBytes), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil) // This ensures there is a diff on the first page
- return
- }
- func validateDiffPageRanges(c *chk.C, resp *azblob.PageList, err error) {
- c.Assert(err, chk.IsNil)
- c.Assert(resp.PageRange, chk.HasLen, 1)
- c.Assert(resp.PageRange[0], chk.Equals, azblob.PageRange{Start: 0, End: azblob.PageBlobPageBytes - 1})
- }
- func (s *aztestsSuite) TestBlobDiffPageRangesNonExistantSnapshot(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot.Add(time.Minute), azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodePreviousSnapshotNotFound)
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeInvalidRange(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- defer func() { // Invalid page range should panic
- recover()
- }()
- blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{Offset: -22, Count: 14}, snapshot, azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfModifiedSinceTrue(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- resp, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateDiffPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfModifiedSinceFalse(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304) // Service Code not returned in the body for a HEAD
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfUnmodifiedSinceTrue(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- resp, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateDiffPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfUnmodifiedSinceFalse(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfMatchTrue(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- resp2, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- validateDiffPageRanges(c, resp2, err)
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfMatchFalse(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- _, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfNoneMatchTrue(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- validateDiffPageRanges(c, resp, err)
- }
- func (s *aztestsSuite) TestBlobDiffPageRangeIfNoneMatchFalse(c *chk.C) {
- containerURL, blobURL, snapshot := setupDiffPageRangesTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.GetPageRangesDiff(ctx, azblob.BlobRange{}, snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- serr := err.(azblob.StorageError)
- c.Assert(serr.Response().StatusCode, chk.Equals, 304) // Service Code not returned in the body for a HEAD
- }
- func (s *aztestsSuite) TestBlobResizeZero(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- // The default blob is created with size > 0, so this should actually update
- _, err := blobURL.Resize(ctx, 0, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.ContentLength(), chk.Equals, int64(0))
- }
- func (s *aztestsSuite) TestBlobResizeInvalidSizeNegative(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- defer func() { // Negative size should panic
- recover()
- }()
- blobURL.Resize(ctx, -4, azblob.BlobAccessConditions{})
- c.Fail()
- }
- func (s *aztestsSuite) TestBlobResizeInvalidSizeMisaligned(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- defer func() { // Invalid size should panic
- recover()
- }()
- blobURL.Resize(ctx, 12, azblob.BlobAccessConditions{})
- c.Fail()
- }
- func validateResize(c *chk.C, blobURL azblob.PageBlobURL) {
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(resp.ContentLength(), chk.Equals, int64(azblob.PageBlobPageBytes))
- }
- func (s *aztestsSuite) TestBlobResizeIfModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateResize(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobResizeIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobResizeIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateResize(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobResizeIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobResizeIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateResize(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobResizeIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobResizeIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateResize(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobResizeIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.Resize(ctx, azblob.PageBlobPageBytes,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberActionTypeInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionType("garbage"), 1, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidHeaderValue)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberSequenceNumberInvalid(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- defer func() { // Invalid sequence number should panic
- recover()
- }()
- blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionUpdate, -1, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberHTTPHeaders(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, basicHeaders, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.NewHTTPHeaders(), chk.DeepEquals, basicHeaders)
- }
- func validateSequenceNumberSet(c *chk.C, blobURL azblob.PageBlobURL) {
- resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- c.Assert(resp.BlobSequenceNumber(), chk.Equals, "1")
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfModifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateSequenceNumberSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfModifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfUnmodifiedSinceTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(10)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateSequenceNumberSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfUnmodifiedSinceFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- currentTime := getRelativeTimeGMT(-10)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateSequenceNumberSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfNoneMatchTrue(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateSequenceNumberSet(c, blobURL)
- }
- func (s *aztestsSuite) TestBlobSetSequenceNumberIfNoneMatchFalse(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := blobURL.SetSequenceNumber(ctx, azblob.SequenceNumberActionIncrement, 0, azblob.BlobHTTPHeaders{},
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func waitForIncrementalCopy(c *chk.C, copyBlobURL azblob.PageBlobURL, blobCopyResponse *azblob.PageBlobsIncrementalCopyResponse) time.Time {
- status := blobCopyResponse.CopyStatus()
- var getPropertiesAndMetadataResult *azblob.BlobsGetPropertiesResponse
- // Wait for the copy to finish
- start := time.Now()
- for status != azblob.CopyStatusSuccess {
- getPropertiesAndMetadataResult, _ = copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- status = getPropertiesAndMetadataResult.CopyStatus()
- currentTime := time.Now()
- if currentTime.Sub(start) >= time.Minute {
- c.Fail()
- }
- }
- return getPropertiesAndMetadataResult.DestinationSnapshot()
- }
- func setupStartIncrementalCopyTest(c *chk.C) (containerURL azblob.ContainerURL, blobURL azblob.PageBlobURL, copyBlobURL azblob.PageBlobURL, snapshot time.Time) {
- bsu := getBSU()
- containerURL, _ = createNewContainer(c, bsu)
- blobURL, _ = createNewPageBlob(c, containerURL)
- resp, _ := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
- copyBlobURL, _ = getPageBlobURL(c, containerURL)
- // Must create the incremental copy blob so that the access conditions work on it
- resp2, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), resp.Snapshot(), azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- waitForIncrementalCopy(c, copyBlobURL, resp2)
- resp, _ = blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{}) // Take a new snapshot so the next copy will succeed
- snapshot = resp.Snapshot()
- return
- }
- func validateIncrementalCopy(c *chk.C, copyBlobURL azblob.PageBlobURL, resp *azblob.PageBlobsIncrementalCopyResponse) {
- t := waitForIncrementalCopy(c, copyBlobURL, resp)
- // If we can access the snapshot without error, we are satisfied that it was created as a result of the copy
- copySnapshotURL := copyBlobURL.WithSnapshot(t)
- _, err := copySnapshotURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- c.Assert(err, chk.IsNil)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopySnapshotNotExist(c *chk.C) {
- bsu := getBSU()
- containerURL, _ := createNewContainer(c, bsu)
- defer deleteContainer(c, containerURL)
- blobURL, _ := createNewPageBlob(c, containerURL)
- copyBlobURL, _ := getPageBlobURL(c, containerURL)
- _, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), time.Now(), azblob.BlobAccessConditions{})
- validateStorageError(c, err, azblob.ServiceCodeInvalidHeaderValue)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfModifiedSinceTrue(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-20)
- resp, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateIncrementalCopy(c, copyBlobURL, resp)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfModifiedSinceFalse(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(20)
- _, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfUnmodifiedSinceTrue(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(20)
- resp, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- c.Assert(err, chk.IsNil)
- validateIncrementalCopy(c, copyBlobURL, resp)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfUnmodifiedSinceFalse(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- currentTime := getRelativeTimeGMT(-20)
- _, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfMatchTrue(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- resp2, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
- c.Assert(err, chk.IsNil)
- validateIncrementalCopy(c, copyBlobURL, resp2)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfMatchFalse(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- _, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
- validateStorageError(c, err, azblob.ServiceCodeTargetConditionNotMet)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfNoneMatchTrue(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- resp, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
- c.Assert(err, chk.IsNil)
- validateIncrementalCopy(c, copyBlobURL, resp)
- }
- func (s *aztestsSuite) TestBlobStartIncrementalCopyIfNoneMatchFalse(c *chk.C) {
- containerURL, blobURL, copyBlobURL, snapshot := setupStartIncrementalCopyTest(c)
- defer deleteContainer(c, containerURL)
- resp, _ := copyBlobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
- _, err := copyBlobURL.StartIncrementalCopy(ctx, blobURL.URL(), snapshot,
- azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
- validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
- }
|