How to use runInstance method of main Package

Best Syzkaller code snippet using main.runInstance

cache_internal_test.go

Source:cache_internal_test.go Github

copy

Full Screen

...44)45var (46 remoteName string47 uploadDir string48 runInstance *run49 errNotSupported = errors.New("not supported")50 decryptedToEncryptedRemotes = map[string]string{51 "one": "lm4u7jjt3c85bf56vjqgeenuno",52 "second": "qvt1ochrkcfbptp5mu9ugb2l14",53 "test": "jn4tegjtpqro30t3o11thb4b5s",54 "test2": "qakvqnh8ttei89e0gc76crpql4",55 "data.bin": "0q2847tfko6mhj3dag3r809qbc",56 "ticw/data.bin": "5mv97b0ule6pht33srae5pice8/0q2847tfko6mhj3dag3r809qbc",57 "tiuufo/test/one": "vi6u1olqhirqv14cd8qlej1mgo/jn4tegjtpqro30t3o11thb4b5s/lm4u7jjt3c85bf56vjqgeenuno",58 "tiuufo/test/second": "vi6u1olqhirqv14cd8qlej1mgo/jn4tegjtpqro30t3o11thb4b5s/qvt1ochrkcfbptp5mu9ugb2l14",59 "tiutfo/test/one": "legd371aa8ol36tjfklt347qnc/jn4tegjtpqro30t3o11thb4b5s/lm4u7jjt3c85bf56vjqgeenuno",60 "tiutfo/second/one": "legd371aa8ol36tjfklt347qnc/qvt1ochrkcfbptp5mu9ugb2l14/lm4u7jjt3c85bf56vjqgeenuno",61 "second/one": "qvt1ochrkcfbptp5mu9ugb2l14/lm4u7jjt3c85bf56vjqgeenuno",62 "test/one": "jn4tegjtpqro30t3o11thb4b5s/lm4u7jjt3c85bf56vjqgeenuno",63 "test/second": "jn4tegjtpqro30t3o11thb4b5s/qvt1ochrkcfbptp5mu9ugb2l14",64 "one/test": "lm4u7jjt3c85bf56vjqgeenuno/jn4tegjtpqro30t3o11thb4b5s",65 "one/test/data.bin": "lm4u7jjt3c85bf56vjqgeenuno/jn4tegjtpqro30t3o11thb4b5s/0q2847tfko6mhj3dag3r809qbc",66 "second/test/data.bin": "qvt1ochrkcfbptp5mu9ugb2l14/jn4tegjtpqro30t3o11thb4b5s/0q2847tfko6mhj3dag3r809qbc",67 "test/third": "jn4tegjtpqro30t3o11thb4b5s/2nd7fjiop5h3ihfj1vl953aa5g",68 "test/0.bin": "jn4tegjtpqro30t3o11thb4b5s/e6frddt058b6kvbpmlstlndmtk",69 "test/1.bin": "jn4tegjtpqro30t3o11thb4b5s/kck472nt1k7qbmob0mt1p1crgc",70 "test/2.bin": "jn4tegjtpqro30t3o11thb4b5s/744oe9ven2rmak4u27if51qk24",71 "test/3.bin": "jn4tegjtpqro30t3o11thb4b5s/2bjd8kef0u5lmsu6qhqll34bcs",72 "test/4.bin": "jn4tegjtpqro30t3o11thb4b5s/cvjs73iv0a82v0c7r67avllh7s",73 "test/5.bin": "jn4tegjtpqro30t3o11thb4b5s/0plkdo790b6bnmt33qsdqmhv9c",74 "test/6.bin": "jn4tegjtpqro30t3o11thb4b5s/s5r633srnjtbh83893jovjt5d0",75 "test/7.bin": "jn4tegjtpqro30t3o11thb4b5s/6rq45tr9bjsammku622flmqsu4",76 "test/8.bin": "jn4tegjtpqro30t3o11thb4b5s/37bc6tcl3e31qb8cadvjb749vk",77 "test/9.bin": "jn4tegjtpqro30t3o11thb4b5s/t4pr35hnls32789o8fk0chk1ec",78 }79)80func init() {81 goflag.StringVar(&remoteName, "remote-internal", "TestInternalCache", "Remote to test with, defaults to local filesystem")82 goflag.StringVar(&uploadDir, "upload-dir-internal", "", "")83}84// TestMain drives the tests85func TestMain(m *testing.M) {86 goflag.Parse()87 var rc int88 log.Printf("Running with the following params: \n remote: %v", remoteName)89 runInstance = newRun()90 rc = m.Run()91 os.Exit(rc)92}93func TestInternalListRootAndInnerRemotes(t *testing.T) {94 id := fmt.Sprintf("tilrair%v", time.Now().Unix())95 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, true, true, nil, nil)96 defer runInstance.cleanupFs(t, rootFs, boltDb)97 // Instantiate inner fs98 innerFolder := "inner"99 runInstance.mkdir(t, rootFs, innerFolder)100 rootFs2, boltDb2 := runInstance.newCacheFs(t, remoteName, id+"/"+innerFolder, true, true, nil, nil)101 defer runInstance.cleanupFs(t, rootFs2, boltDb2)102 runInstance.writeObjectString(t, rootFs2, "one", "content")103 listRoot, err := runInstance.list(t, rootFs, "")104 require.NoError(t, err)105 listRootInner, err := runInstance.list(t, rootFs, innerFolder)106 require.NoError(t, err)107 listInner, err := rootFs2.List(context.Background(), "")108 require.NoError(t, err)109 require.Len(t, listRoot, 1)110 require.Len(t, listRootInner, 1)111 require.Len(t, listInner, 1)112}113/* TODO: is this testing something?114func TestInternalVfsCache(t *testing.T) {115 vfsflags.Opt.DirCacheTime = time.Second * 30116 testSize := int64(524288000)117 vfsflags.Opt.CacheMode = vfs.CacheModeWrites118 id := "tiuufo"119 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, true, true, nil, map[string]string{"writes": "true", "info_age": "1h"})120 defer runInstance.cleanupFs(t, rootFs, boltDb)121 err := rootFs.Mkdir(context.Background(), "test")122 require.NoError(t, err)123 runInstance.writeObjectString(t, rootFs, "test/second", "content")124 _, err = rootFs.List(context.Background(), "test")125 require.NoError(t, err)126 testReader := runInstance.randomReader(t, testSize)127 writeCh := make(chan interface{})128 //write2Ch := make(chan interface{})129 readCh := make(chan interface{})130 cacheCh := make(chan interface{})131 // write the main file132 go func() {133 defer func() {134 writeCh <- true135 }()136 log.Printf("========== started writing file 'test/one'")137 runInstance.writeRemoteReader(t, rootFs, "test/one", testReader)138 log.Printf("========== done writing file 'test/one'")139 }()140 // routine to check which cache has what, autostarts141 go func() {142 for {143 select {144 case <-cacheCh:145 log.Printf("========== finished checking caches")146 return147 default:148 }149 li2 := [2]string{path.Join("test", "one"), path.Join("test", "second")}150 for _, r := range li2 {151 var err error152 ci, err := ioutil.ReadDir(path.Join(runInstance.chunkPath, runInstance.encryptRemoteIfNeeded(t, path.Join(id, r))))153 if err != nil || len(ci) == 0 {154 log.Printf("========== '%v' not in cache", r)155 } else {156 log.Printf("========== '%v' IN CACHE", r)157 }158 _, err = os.Stat(path.Join(runInstance.vfsCachePath, id, r))159 if err != nil {160 log.Printf("========== '%v' not in vfs", r)161 } else {162 log.Printf("========== '%v' IN VFS", r)163 }164 }165 time.Sleep(time.Second * 10)166 }167 }()168 // routine to list, autostarts169 go func() {170 for {171 select {172 case <-readCh:173 log.Printf("========== finished checking listings and readings")174 return175 default:176 }177 li, err := runInstance.list(t, rootFs, "test")178 if err != nil {179 log.Printf("========== error listing 'test' folder: %v", err)180 } else {181 log.Printf("========== list 'test' folder count: %v", len(li))182 }183 time.Sleep(time.Second * 10)184 }185 }()186 // wait for main file to be written187 <-writeCh188 log.Printf("========== waiting for VFS to expire")189 time.Sleep(time.Second * 120)190 // try a final read191 li2 := [2]string{"test/one", "test/second"}192 for _, r := range li2 {193 _, err := runInstance.readDataFromRemote(t, rootFs, r, int64(0), int64(2), false)194 if err != nil {195 log.Printf("========== error reading '%v': %v", r, err)196 } else {197 log.Printf("========== read '%v'", r)198 }199 }200 // close the cache and list checkers201 cacheCh <- true202 readCh <- true203}204*/205func TestInternalObjWrapFsFound(t *testing.T) {206 id := fmt.Sprintf("tiowff%v", time.Now().Unix())207 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, true, true, nil, nil)208 defer runInstance.cleanupFs(t, rootFs, boltDb)209 cfs, err := runInstance.getCacheFs(rootFs)210 require.NoError(t, err)211 wrappedFs := cfs.UnWrap()212 var testData []byte213 if runInstance.rootIsCrypt {214 testData, err = base64.StdEncoding.DecodeString(cryptedTextBase64)215 require.NoError(t, err)216 } else {217 testData = []byte("test content")218 }219 runInstance.writeObjectBytes(t, wrappedFs, runInstance.encryptRemoteIfNeeded(t, "test"), testData)220 listRoot, err := runInstance.list(t, rootFs, "")221 require.NoError(t, err)222 require.Len(t, listRoot, 1)223 cachedData, err := runInstance.readDataFromRemote(t, rootFs, "test", 0, int64(len([]byte("test content"))), false)224 require.NoError(t, err)225 require.Equal(t, "test content", string(cachedData))226 err = runInstance.rm(t, rootFs, "test")227 require.NoError(t, err)228 listRoot, err = runInstance.list(t, rootFs, "")229 require.NoError(t, err)230 require.Len(t, listRoot, 0)231}232func TestInternalObjNotFound(t *testing.T) {233 id := fmt.Sprintf("tionf%v", time.Now().Unix())234 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)235 defer runInstance.cleanupFs(t, rootFs, boltDb)236 obj, err := rootFs.NewObject(context.Background(), "404")237 require.Error(t, err)238 require.Nil(t, obj)239}240func TestInternalCachedWrittenContentMatches(t *testing.T) {241 testy.SkipUnreliable(t)242 id := fmt.Sprintf("ticwcm%v", time.Now().Unix())243 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)244 defer runInstance.cleanupFs(t, rootFs, boltDb)245 cfs, err := runInstance.getCacheFs(rootFs)246 require.NoError(t, err)247 chunkSize := cfs.ChunkSize()248 // create some rand test data249 testData := randStringBytes(int(chunkSize*4 + chunkSize/2))250 // write the object251 runInstance.writeRemoteBytes(t, rootFs, "data.bin", testData)252 // check sample of data from in-file253 sampleStart := chunkSize / 2254 sampleEnd := chunkSize255 testSample := testData[sampleStart:sampleEnd]256 checkSample, err := runInstance.readDataFromRemote(t, rootFs, "data.bin", sampleStart, sampleEnd, false)257 require.NoError(t, err)258 require.Equal(t, int64(len(checkSample)), sampleEnd-sampleStart)259 require.Equal(t, checkSample, testSample)260}261func TestInternalDoubleWrittenContentMatches(t *testing.T) {262 id := fmt.Sprintf("tidwcm%v", time.Now().Unix())263 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)264 defer runInstance.cleanupFs(t, rootFs, boltDb)265 // write the object266 runInstance.writeRemoteString(t, rootFs, "one", "one content")267 err := runInstance.updateData(t, rootFs, "one", "one content", " updated")268 require.NoError(t, err)269 err = runInstance.updateData(t, rootFs, "one", "one content updated", " double")270 require.NoError(t, err)271 // check sample of data from in-file272 data, err := runInstance.readDataFromRemote(t, rootFs, "one", int64(0), int64(len("one content updated double")), true)273 require.NoError(t, err)274 require.Equal(t, "one content updated double", string(data))275}276func TestInternalCachedUpdatedContentMatches(t *testing.T) {277 testy.SkipUnreliable(t)278 id := fmt.Sprintf("ticucm%v", time.Now().Unix())279 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)280 defer runInstance.cleanupFs(t, rootFs, boltDb)281 var err error282 // create some rand test data283 var testData1 []byte284 var testData2 []byte285 if runInstance.rootIsCrypt {286 testData1, err = base64.StdEncoding.DecodeString(cryptedTextBase64)287 require.NoError(t, err)288 testData2, err = base64.StdEncoding.DecodeString(cryptedText2Base64)289 require.NoError(t, err)290 } else {291 testData1 = []byte(random.String(100))292 testData2 = []byte(random.String(200))293 }294 // write the object295 o := runInstance.updateObjectRemote(t, rootFs, "data.bin", testData1, testData2)296 require.Equal(t, o.Size(), int64(len(testData2)))297 // check data from in-file298 checkSample, err := runInstance.readDataFromRemote(t, rootFs, "data.bin", 0, int64(len(testData2)), false)299 require.NoError(t, err)300 require.Equal(t, checkSample, testData2)301}302func TestInternalWrappedWrittenContentMatches(t *testing.T) {303 id := fmt.Sprintf("tiwwcm%v", time.Now().Unix())304 vfsflags.Opt.DirCacheTime = time.Second305 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, true, true, nil, nil)306 defer runInstance.cleanupFs(t, rootFs, boltDb)307 if runInstance.rootIsCrypt {308 t.Skip("test skipped with crypt remote")309 }310 cfs, err := runInstance.getCacheFs(rootFs)311 require.NoError(t, err)312 chunkSize := cfs.ChunkSize()313 // create some rand test data314 testSize := chunkSize*4 + chunkSize/2315 testData := randStringBytes(int(testSize))316 // write the object317 o := runInstance.writeObjectBytes(t, cfs.UnWrap(), "data.bin", testData)318 require.Equal(t, o.Size(), testSize)319 time.Sleep(time.Second * 3)320 checkSample, err := runInstance.readDataFromRemote(t, rootFs, "data.bin", 0, testSize, false)321 require.NoError(t, err)322 require.Equal(t, int64(len(checkSample)), o.Size())323 for i := 0; i < len(checkSample); i++ {324 require.Equal(t, testData[i], checkSample[i])325 }326}327func TestInternalLargeWrittenContentMatches(t *testing.T) {328 id := fmt.Sprintf("tilwcm%v", time.Now().Unix())329 vfsflags.Opt.DirCacheTime = time.Second330 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, true, true, nil, nil)331 defer runInstance.cleanupFs(t, rootFs, boltDb)332 if runInstance.rootIsCrypt {333 t.Skip("test skipped with crypt remote")334 }335 cfs, err := runInstance.getCacheFs(rootFs)336 require.NoError(t, err)337 chunkSize := cfs.ChunkSize()338 // create some rand test data339 testSize := chunkSize*10 + chunkSize/2340 testData := randStringBytes(int(testSize))341 // write the object342 runInstance.writeObjectBytes(t, cfs.UnWrap(), "data.bin", testData)343 time.Sleep(time.Second * 3)344 readData, err := runInstance.readDataFromRemote(t, rootFs, "data.bin", 0, testSize, false)345 require.NoError(t, err)346 for i := 0; i < len(readData); i++ {347 require.Equalf(t, testData[i], readData[i], "at byte %v", i)348 }349}350func TestInternalWrappedFsChangeNotSeen(t *testing.T) {351 id := fmt.Sprintf("tiwfcns%v", time.Now().Unix())352 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)353 defer runInstance.cleanupFs(t, rootFs, boltDb)354 cfs, err := runInstance.getCacheFs(rootFs)355 require.NoError(t, err)356 chunkSize := cfs.ChunkSize()357 // create some rand test data358 testData := randStringBytes(int(chunkSize*4 + chunkSize/2))359 runInstance.writeRemoteBytes(t, rootFs, "data.bin", testData)360 // update in the wrapped fs361 originalSize, err := runInstance.size(t, rootFs, "data.bin")362 require.NoError(t, err)363 log.Printf("original size: %v", originalSize)364 o, err := cfs.UnWrap().NewObject(context.Background(), runInstance.encryptRemoteIfNeeded(t, "data.bin"))365 require.NoError(t, err)366 expectedSize := int64(len([]byte("test content")))367 var data2 []byte368 if runInstance.rootIsCrypt {369 data2, err = base64.StdEncoding.DecodeString(cryptedText3Base64)370 require.NoError(t, err)371 expectedSize = expectedSize + 1 // FIXME newline gets in, likely test data issue372 } else {373 data2 = []byte("test content")374 }375 objInfo := object.NewStaticObjectInfo(runInstance.encryptRemoteIfNeeded(t, "data.bin"), time.Now(), int64(len(data2)), true, nil, cfs.UnWrap())376 err = o.Update(context.Background(), bytes.NewReader(data2), objInfo)377 require.NoError(t, err)378 require.Equal(t, int64(len(data2)), o.Size())379 log.Printf("updated size: %v", len(data2))380 // get a new instance from the cache381 if runInstance.wrappedIsExternal {382 err = runInstance.retryBlock(func() error {383 coSize, err := runInstance.size(t, rootFs, "data.bin")384 if err != nil {385 return err386 }387 if coSize != expectedSize {388 return errors.Errorf("%v <> %v", coSize, expectedSize)389 }390 return nil391 }, 12, time.Second*10)392 require.NoError(t, err)393 } else {394 coSize, err := runInstance.size(t, rootFs, "data.bin")395 require.NoError(t, err)396 require.NotEqual(t, coSize, expectedSize)397 }398}399func TestInternalMoveWithNotify(t *testing.T) {400 id := fmt.Sprintf("timwn%v", time.Now().Unix())401 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)402 defer runInstance.cleanupFs(t, rootFs, boltDb)403 if !runInstance.wrappedIsExternal {404 t.Skipf("Not external")405 }406 cfs, err := runInstance.getCacheFs(rootFs)407 require.NoError(t, err)408 srcName := runInstance.encryptRemoteIfNeeded(t, "test") + "/" + runInstance.encryptRemoteIfNeeded(t, "one") + "/" + runInstance.encryptRemoteIfNeeded(t, "data.bin")409 dstName := runInstance.encryptRemoteIfNeeded(t, "test") + "/" + runInstance.encryptRemoteIfNeeded(t, "second") + "/" + runInstance.encryptRemoteIfNeeded(t, "data.bin")410 // create some rand test data411 var testData []byte412 if runInstance.rootIsCrypt {413 testData, err = base64.StdEncoding.DecodeString(cryptedTextBase64)414 require.NoError(t, err)415 } else {416 testData = []byte("test content")417 }418 _ = cfs.UnWrap().Mkdir(context.Background(), runInstance.encryptRemoteIfNeeded(t, "test"))419 _ = cfs.UnWrap().Mkdir(context.Background(), runInstance.encryptRemoteIfNeeded(t, "test/one"))420 _ = cfs.UnWrap().Mkdir(context.Background(), runInstance.encryptRemoteIfNeeded(t, "test/second"))421 srcObj := runInstance.writeObjectBytes(t, cfs.UnWrap(), srcName, testData)422 // list in mount423 _, err = runInstance.list(t, rootFs, "test")424 require.NoError(t, err)425 _, err = runInstance.list(t, rootFs, "test/one")426 require.NoError(t, err)427 // move file428 _, err = cfs.UnWrap().Features().Move(context.Background(), srcObj, dstName)429 require.NoError(t, err)430 err = runInstance.retryBlock(func() error {431 li, err := runInstance.list(t, rootFs, "test")432 if err != nil {433 log.Printf("err: %v", err)434 return err435 }436 if len(li) != 2 {437 log.Printf("not expected listing /test: %v", li)438 return errors.Errorf("not expected listing /test: %v", li)439 }440 li, err = runInstance.list(t, rootFs, "test/one")441 if err != nil {442 log.Printf("err: %v", err)443 return err444 }445 if len(li) != 0 {446 log.Printf("not expected listing /test/one: %v", li)447 return errors.Errorf("not expected listing /test/one: %v", li)448 }449 li, err = runInstance.list(t, rootFs, "test/second")450 if err != nil {451 log.Printf("err: %v", err)452 return err453 }454 if len(li) != 1 {455 log.Printf("not expected listing /test/second: %v", li)456 return errors.Errorf("not expected listing /test/second: %v", li)457 }458 if fi, ok := li[0].(os.FileInfo); ok {459 if fi.Name() != "data.bin" {460 log.Printf("not expected name: %v", fi.Name())461 return errors.Errorf("not expected name: %v", fi.Name())462 }463 } else if di, ok := li[0].(fs.DirEntry); ok {464 if di.Remote() != "test/second/data.bin" {465 log.Printf("not expected remote: %v", di.Remote())466 return errors.Errorf("not expected remote: %v", di.Remote())467 }468 } else {469 log.Printf("unexpected listing: %v", li)470 return errors.Errorf("unexpected listing: %v", li)471 }472 log.Printf("complete listing: %v", li)473 return nil474 }, 12, time.Second*10)475 require.NoError(t, err)476}477func TestInternalNotifyCreatesEmptyParts(t *testing.T) {478 id := fmt.Sprintf("tincep%v", time.Now().Unix())479 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)480 defer runInstance.cleanupFs(t, rootFs, boltDb)481 if !runInstance.wrappedIsExternal {482 t.Skipf("Not external")483 }484 cfs, err := runInstance.getCacheFs(rootFs)485 require.NoError(t, err)486 srcName := runInstance.encryptRemoteIfNeeded(t, "test") + "/" + runInstance.encryptRemoteIfNeeded(t, "one") + "/" + runInstance.encryptRemoteIfNeeded(t, "test")487 dstName := runInstance.encryptRemoteIfNeeded(t, "test") + "/" + runInstance.encryptRemoteIfNeeded(t, "one") + "/" + runInstance.encryptRemoteIfNeeded(t, "test2")488 // create some rand test data489 var testData []byte490 if runInstance.rootIsCrypt {491 testData, err = base64.StdEncoding.DecodeString(cryptedTextBase64)492 require.NoError(t, err)493 } else {494 testData = []byte("test content")495 }496 err = rootFs.Mkdir(context.Background(), "test")497 require.NoError(t, err)498 err = rootFs.Mkdir(context.Background(), "test/one")499 require.NoError(t, err)500 srcObj := runInstance.writeObjectBytes(t, cfs.UnWrap(), srcName, testData)501 // list in mount502 _, err = runInstance.list(t, rootFs, "test")503 require.NoError(t, err)504 _, err = runInstance.list(t, rootFs, "test/one")505 require.NoError(t, err)506 found := boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test")))507 require.True(t, found)508 boltDb.Purge()509 found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test")))510 require.False(t, found)511 // move file512 _, err = cfs.UnWrap().Features().Move(context.Background(), srcObj, dstName)513 require.NoError(t, err)514 err = runInstance.retryBlock(func() error {515 found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test")))516 if !found {517 log.Printf("not found /test")518 return errors.Errorf("not found /test")519 }520 found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test"), runInstance.encryptRemoteIfNeeded(t, "one")))521 if !found {522 log.Printf("not found /test/one")523 return errors.Errorf("not found /test/one")524 }525 found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test"), runInstance.encryptRemoteIfNeeded(t, "one"), runInstance.encryptRemoteIfNeeded(t, "test2")))526 if !found {527 log.Printf("not found /test/one/test2")528 return errors.Errorf("not found /test/one/test2")529 }530 li, err := runInstance.list(t, rootFs, "test/one")531 if err != nil {532 log.Printf("err: %v", err)533 return err534 }535 if len(li) != 1 {536 log.Printf("not expected listing /test/one: %v", li)537 return errors.Errorf("not expected listing /test/one: %v", li)538 }539 if fi, ok := li[0].(os.FileInfo); ok {540 if fi.Name() != "test2" {541 log.Printf("not expected name: %v", fi.Name())542 return errors.Errorf("not expected name: %v", fi.Name())543 }544 } else if di, ok := li[0].(fs.DirEntry); ok {545 if di.Remote() != "test/one/test2" {546 log.Printf("not expected remote: %v", di.Remote())547 return errors.Errorf("not expected remote: %v", di.Remote())548 }549 } else {550 log.Printf("unexpected listing: %v", li)551 return errors.Errorf("unexpected listing: %v", li)552 }553 log.Printf("complete listing /test/one/test2")554 return nil555 }, 12, time.Second*10)556 require.NoError(t, err)557}558func TestInternalChangeSeenAfterDirCacheFlush(t *testing.T) {559 id := fmt.Sprintf("ticsadcf%v", time.Now().Unix())560 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, nil)561 defer runInstance.cleanupFs(t, rootFs, boltDb)562 cfs, err := runInstance.getCacheFs(rootFs)563 require.NoError(t, err)564 chunkSize := cfs.ChunkSize()565 // create some rand test data566 testData := randStringBytes(int(chunkSize*4 + chunkSize/2))567 runInstance.writeRemoteBytes(t, rootFs, "data.bin", testData)568 // update in the wrapped fs569 o, err := cfs.UnWrap().NewObject(context.Background(), runInstance.encryptRemoteIfNeeded(t, "data.bin"))570 require.NoError(t, err)571 wrappedTime := time.Now().Add(-1 * time.Hour)572 err = o.SetModTime(context.Background(), wrappedTime)573 require.NoError(t, err)574 // get a new instance from the cache575 co, err := rootFs.NewObject(context.Background(), "data.bin")576 require.NoError(t, err)577 require.NotEqual(t, o.ModTime(context.Background()).String(), co.ModTime(context.Background()).String())578 cfs.DirCacheFlush() // flush the cache579 // get a new instance from the cache580 co, err = rootFs.NewObject(context.Background(), "data.bin")581 require.NoError(t, err)582 require.Equal(t, wrappedTime.Unix(), co.ModTime(context.Background()).Unix())583}584func TestInternalCacheWrites(t *testing.T) {585 id := "ticw"586 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, map[string]string{"writes": "true"})587 defer runInstance.cleanupFs(t, rootFs, boltDb)588 cfs, err := runInstance.getCacheFs(rootFs)589 require.NoError(t, err)590 chunkSize := cfs.ChunkSize()591 // create some rand test data592 earliestTime := time.Now()593 testData := randStringBytes(int(chunkSize*4 + chunkSize/2))594 runInstance.writeRemoteBytes(t, rootFs, "data.bin", testData)595 expectedTs := time.Now()596 ts, err := boltDb.GetChunkTs(runInstance.encryptRemoteIfNeeded(t, path.Join(rootFs.Root(), "data.bin")), 0)597 require.NoError(t, err)598 require.WithinDuration(t, expectedTs, ts, expectedTs.Sub(earliestTime))599}600func TestInternalMaxChunkSizeRespected(t *testing.T) {601 id := fmt.Sprintf("timcsr%v", time.Now().Unix())602 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil, map[string]string{"workers": "1"})603 defer runInstance.cleanupFs(t, rootFs, boltDb)604 cfs, err := runInstance.getCacheFs(rootFs)605 require.NoError(t, err)606 chunkSize := cfs.ChunkSize()607 totalChunks := 20608 // create some rand test data609 testData := randStringBytes(int(int64(totalChunks-1)*chunkSize + chunkSize/2))610 runInstance.writeRemoteBytes(t, rootFs, "data.bin", testData)611 o, err := cfs.NewObject(context.Background(), runInstance.encryptRemoteIfNeeded(t, "data.bin"))612 require.NoError(t, err)613 co, ok := o.(*cache.Object)614 require.True(t, ok)615 for i := 0; i < 4; i++ { // read first 4616 _ = runInstance.readDataFromObj(t, co, chunkSize*int64(i), chunkSize*int64(i+1), false)617 }618 cfs.CleanUpCache(true)619 // the last 2 **must** be in the cache620 require.True(t, boltDb.HasChunk(co, chunkSize*2))621 require.True(t, boltDb.HasChunk(co, chunkSize*3))622 for i := 4; i < 6; i++ { // read next 2623 _ = runInstance.readDataFromObj(t, co, chunkSize*int64(i), chunkSize*int64(i+1), false)624 }625 cfs.CleanUpCache(true)626 // the last 2 **must** be in the cache627 require.True(t, boltDb.HasChunk(co, chunkSize*4))628 require.True(t, boltDb.HasChunk(co, chunkSize*5))629}630func TestInternalExpiredEntriesRemoved(t *testing.T) {631 id := fmt.Sprintf("tieer%v", time.Now().Unix())632 vfsflags.Opt.DirCacheTime = time.Second * 4 // needs to be lower than the defined633 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, true, true, map[string]string{"info_age": "5s"}, nil)634 defer runInstance.cleanupFs(t, rootFs, boltDb)635 cfs, err := runInstance.getCacheFs(rootFs)636 require.NoError(t, err)637 // create some rand test data638 runInstance.writeRemoteString(t, rootFs, "one", "one content")639 runInstance.mkdir(t, rootFs, "test")640 runInstance.writeRemoteString(t, rootFs, "test/second", "second content")641 l, err := runInstance.list(t, rootFs, "test")642 require.NoError(t, err)643 require.Len(t, l, 1)644 err = cfs.UnWrap().Mkdir(context.Background(), runInstance.encryptRemoteIfNeeded(t, "test/third"))645 require.NoError(t, err)646 l, err = runInstance.list(t, rootFs, "test")647 require.NoError(t, err)648 require.Len(t, l, 1)649 err = runInstance.retryBlock(func() error {650 l, err = runInstance.list(t, rootFs, "test")651 if err != nil {652 return err653 }654 if len(l) != 2 {655 return errors.New("list is not 2")656 }657 return nil658 }, 10, time.Second)659 require.NoError(t, err)660}661func TestInternalBug2117(t *testing.T) {662 vfsflags.Opt.DirCacheTime = time.Second * 10663 id := fmt.Sprintf("tib2117%v", time.Now().Unix())664 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, false, true, nil,665 map[string]string{"info_age": "72h", "chunk_clean_interval": "15m"})666 defer runInstance.cleanupFs(t, rootFs, boltDb)667 if runInstance.rootIsCrypt {668 t.Skipf("skipping crypt")669 }670 cfs, err := runInstance.getCacheFs(rootFs)671 require.NoError(t, err)672 err = cfs.UnWrap().Mkdir(context.Background(), "test")673 require.NoError(t, err)674 for i := 1; i <= 4; i++ {675 err = cfs.UnWrap().Mkdir(context.Background(), fmt.Sprintf("test/dir%d", i))676 require.NoError(t, err)677 for j := 1; j <= 4; j++ {678 err = cfs.UnWrap().Mkdir(context.Background(), fmt.Sprintf("test/dir%d/dir%d", i, j))679 require.NoError(t, err)680 runInstance.writeObjectString(t, cfs.UnWrap(), fmt.Sprintf("test/dir%d/dir%d/test.txt", i, j), "test")681 }682 }683 di, err := runInstance.list(t, rootFs, "test/dir1/dir2")684 require.NoError(t, err)685 log.Printf("len: %v", len(di))686 require.Len(t, di, 1)687 time.Sleep(time.Second * 30)688 di, err = runInstance.list(t, rootFs, "test/dir1/dir2")689 require.NoError(t, err)690 log.Printf("len: %v", len(di))691 require.Len(t, di, 1)692 di, err = runInstance.list(t, rootFs, "test/dir1")693 require.NoError(t, err)694 log.Printf("len: %v", len(di))695 require.Len(t, di, 4)696 di, err = runInstance.list(t, rootFs, "test")697 require.NoError(t, err)698 log.Printf("len: %v", len(di))699 require.Len(t, di, 4)700}701// run holds the remotes for a test run702type run struct {703 okDiff time.Duration704 runDefaultCfgMap configmap.Simple705 tmpUploadDir string706 rootIsCrypt bool707 wrappedIsExternal bool708 tempFiles []*os.File709 dbPath string710 chunkPath string711 vfsCachePath string712}713func newRun() *run {714 var err error715 r := &run{716 okDiff: time.Second * 9, // really big diff here but the build machines seem to be slow. need a different way for this717 }718 // Read in all the defaults for all the options719 fsInfo, err := fs.Find("cache")720 if err != nil {721 panic(fmt.Sprintf("Couldn't find cache remote: %v", err))722 }723 r.runDefaultCfgMap = configmap.Simple{}724 for _, option := range fsInfo.Options {725 r.runDefaultCfgMap.Set(option.Name, fmt.Sprint(option.Default))726 }727 if uploadDir == "" {728 r.tmpUploadDir, err = ioutil.TempDir("", "rclonecache-tmp")729 if err != nil {730 panic(fmt.Sprintf("Failed to create temp dir: %v", err))731 }732 } else {733 r.tmpUploadDir = uploadDir734 }735 log.Printf("Temp Upload Dir: %v", r.tmpUploadDir)736 return r737}738func (r *run) encryptRemoteIfNeeded(t *testing.T, remote string) string {739 if !runInstance.rootIsCrypt || len(decryptedToEncryptedRemotes) == 0 {740 return remote741 }742 enc, ok := decryptedToEncryptedRemotes[remote]743 if !ok {744 t.Fatalf("Failed to find decrypted -> encrypted mapping for '%v'", remote)745 return remote746 }747 return enc748}749func (r *run) newCacheFs(t *testing.T, remote, id string, needRemote, purge bool, cfg map[string]string, flags map[string]string) (fs.Fs, *cache.Persistent) {750 fstest.Initialise()751 remoteExists := false752 for _, s := range config.FileSections() {753 if s == remote {754 remoteExists = true755 }756 }757 if !remoteExists && needRemote {758 t.Skipf("Need remote (%v) to exist", remote)759 return nil, nil760 }761 // Config to pass to NewFs762 m := configmap.Simple{}763 for k, v := range r.runDefaultCfgMap {764 m.Set(k, v)765 }766 for k, v := range flags {767 m.Set(k, v)768 }769 // if the remote doesn't exist, create a new one with a local one for it770 // identify which is the cache remote (it can be wrapped by a crypt too)771 rootIsCrypt := false772 cacheRemote := remote773 if !remoteExists {774 localRemote := remote + "-local"775 config.FileSet(localRemote, "type", "local")776 config.FileSet(localRemote, "nounc", "true")777 m.Set("type", "cache")778 m.Set("remote", localRemote+":"+filepath.Join(os.TempDir(), localRemote))779 } else {780 remoteType := config.FileGet(remote, "type")781 if remoteType == "" {782 t.Skipf("skipped due to invalid remote type for %v", remote)783 return nil, nil784 }785 if remoteType != "cache" {786 if remoteType == "crypt" {787 rootIsCrypt = true788 m.Set("password", cryptPassword1)789 m.Set("password2", cryptPassword2)790 }791 remoteRemote := config.FileGet(remote, "remote")792 if remoteRemote == "" {793 t.Skipf("skipped due to invalid remote wrapper for %v", remote)794 return nil, nil795 }796 remoteRemoteParts := strings.Split(remoteRemote, ":")797 remoteWrapping := remoteRemoteParts[0]798 remoteType := config.FileGet(remoteWrapping, "type")799 if remoteType != "cache" {800 t.Skipf("skipped due to invalid remote type for %v: '%v'", remoteWrapping, remoteType)801 return nil, nil802 }803 cacheRemote = remoteWrapping804 }805 }806 runInstance.rootIsCrypt = rootIsCrypt807 runInstance.dbPath = filepath.Join(config.CacheDir, "cache-backend", cacheRemote+".db")808 runInstance.chunkPath = filepath.Join(config.CacheDir, "cache-backend", cacheRemote)809 runInstance.vfsCachePath = filepath.Join(config.CacheDir, "vfs", remote)810 boltDb, err := cache.GetPersistent(runInstance.dbPath, runInstance.chunkPath, &cache.Features{PurgeDb: true})811 require.NoError(t, err)812 ci := fs.GetConfig(context.Background())813 ci.LowLevelRetries = 1814 // Instantiate root815 if purge {816 boltDb.PurgeTempUploads()817 _ = os.RemoveAll(path.Join(runInstance.tmpUploadDir, id))818 }819 f, err := cache.NewFs(context.Background(), remote, id, m)820 require.NoError(t, err)821 cfs, err := r.getCacheFs(f)822 require.NoError(t, err)823 _, isCache := cfs.Features().UnWrap().(*cache.Fs)824 _, isCrypt := cfs.Features().UnWrap().(*crypt.Fs)825 _, isLocal := cfs.Features().UnWrap().(*local.Fs)826 if isCache || isCrypt || isLocal {827 r.wrappedIsExternal = false828 } else {829 r.wrappedIsExternal = true830 }831 if purge {...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...69 }70 if len(describeImages.Images) == 0 {71 return "", fmt.Errorf("describeImages has empty length (%d)", len(describeImages.Images))72 }73 runInstance, err := ec2Client.RunInstances(ctx, &ec2.RunInstancesInput{74 ImageId: describeImages.Images[0].ImageId,75 InstanceType: types.InstanceTypeT3Micro,76 KeyName: aws.String("go-aws-ec2"),77 MinCount: aws.Int32(1),78 MaxCount: aws.Int32(1),79 })80 if err != nil {81 return "", fmt.Errorf("RunInstance error: %s", err)82 }83 if len(runInstance.Instances) == 0 {84 return "", fmt.Errorf("RunInstance has empty length (%d)", len(runInstance.Instances))85 }86 return *runInstance.Instances[0].InstanceId, nil87}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 runInstance()5}6import (7func runInstance() {8 fmt.Println("Hello, playground")9}10runInstance undefined (type func() is interface with no methods)”11import (12type Instance struct {13}14func runInstance() {15 fmt.Println("Hello, playground")16}17import (18func main() {19 fmt.Println("Hello, playground")20 runInstance()21}22runInstance undefined (type func() is interface with no methods)”23import (24type Instance struct {25}26func runInstance() {27 fmt.Println("Hello, playground")28}29import (30func main() {31 fmt.Println("Hello, playground")32 runInstance()33}34runInstance undefined (type func() is interface with no methods)”

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 instance := new(Instance)4 instance.runInstance()5}6import (7func main() {8 instance := new(Instance)9 instance.runInstance()10}11import (12func main() {13 instance := new(Instance)14 instance.runInstance()15}16import (17func main() {18 instance := new(Instance)19 instance.runInstance()20}21import (22func main() {23 instance := new(Instance)24 instance.runInstance()25}26import (27func main() {28 instance := new(Instance)29 instance.runInstance()30}31import (32func main() {33 instance := new(Instance)34 instance.runInstance()35}36import (37func main() {38 instance := new(Instance)39 instance.runInstance()40}41import (42func main() {43 instance := new(Instance)44 instance.runInstance()45}46import (47func main() {48 instance := new(Instance)49 instance.runInstance()50}51import (52func main() {53 instance := new(Instance)54 instance.runInstance()55}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 runInstance()4}5import "fmt"6func main(){7 runInstance()8}9import "fmt"10func main(){11 runInstance()12}13import "fmt"14func main(){15 runInstance()16}17import "fmt"18func main(){19 runInstance()20}21import "fmt"22func main(){23 runInstance()24}25import "fmt"26func main(){27 runInstance()28}29import "fmt"30func main(){31 runInstance()32}33import "fmt"34func main(){35 runInstance()36}37import "fmt"38func main(){39 runInstance()40}41import "fmt"42func main(){43 runInstance()44}45import "fmt"46func main(){47 runInstance()48}49import "fmt"50func main(){51 runInstance()52}53import "fmt"54func main(){55 runInstance()56}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 mylib.RunInstance()4 fmt.Println("Done")5}6import "fmt"7func RunInstance() {8 fmt.Println("Running instance")9}10import "fmt"11func init() {12 fmt.Println("Running init")13}14import "fmt"15func init() {16 fmt.Println("Running init 2")17}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the number of instances you want to run: ")4 fmt.Scanln(&a)5 for i := 0; i < a; i++ {6 runInstance()7 }8}9import (10func runInstance() {11 fmt.Println("Instance of main class is running")12}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4}5import "fmt"6func main() {7 fmt.Println("Hello, World!")8}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1func main() {2 fmt.Println("Hello World")3 mainObj := mainClass{}4 mainObj.runInstance()5}6import "fmt"7type mainClass struct {8}9func (m mainClass) runInstance() {10 for i := 0; i < 10; i++ {11 fmt.Println("Hello World")12 }13}14func main() {15 fmt.Println("Hello World")16 mainObj := mainClass{}17 mainObj.runInstance()18}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4 i.runInstance()5}6import "fmt"7type instance struct {8}9func (i instance) runInstance() {10 fmt.Println("Hello, World!")11}12./2.go:11:3: cannot use i (type instance) as type instance in field value:13 instance does not implement instance (runInstance method has pointer receiver)14import "fmt"15func main() {16 fmt.Println("Hello, World!")17 i.runInstance()18}19import "fmt"20type instance struct {21}22func (i *instance) runInstance() {23 fmt.Println("Hello, World!")24}

Full Screen

Full Screen

runInstance

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 obj1.runInstance()5}6import "fmt"7type instance struct {8}9func (obj instance) runInstance() {10 fmt.Println("Hello, playground")11}12func main() {13 s := make([]string, 3)14 s = append(s, "one", "two", "three")15 fmt.Println(s)16}17func main() {18 s := make([]string, 3)19 s = append(s, []string{"one", "two", "three"}...)20 fmt.Println(s)21}22func main() {23 s := make([]string, 3)24 s = append(s, "one", "two", "three")25 fmt.Println(s)26}27func main() {28 s := make([]string, 3)29 s = append(s, []string{"one", "two", "three"}...)30 fmt.Println(s)31}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful