internal/importer/main_test.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | package importer import ( "testing" "alin.ovh/x/log" "alin.ovh/searchix/internal/config" "alin.ovh/searchix/internal/file" "alin.ovh/searchix/internal/index" "alin.ovh/searchix/internal/manpages" "alin.ovh/searchix/internal/storage" ) var cfg = config.DefaultConfig func BenchmarkImporterLowMemory(b *testing.B) { tmp, err := file.OpenRoot(b.TempDir()) if err != nil { b.Fatal(err) } logger := log.Configure(false) _, write, _, err := index.OpenOrCreate(&index.Options{ Config: &cfg, Force: false, LowMemory: true, BatchSize: cfg.Importer.BatchSize, Logger: logger.Named("index"), Root: tmp, }) if err != nil { b.Fatal(err) } store, err := storage.New(&storage.Options{ Root: tmp, Logger: logger.Named("storage"), }) if err != nil { b.Fatal(err) } imp, err := New(&cfg, &Options{ Logger: logger.Named("importer"), LowMemory: true, WriteIndex: write, Manpages: manpages.New(&manpages.Options{ Logger: logger.Named("manpages"), Root: tmp, }), Offline: true, Root: tmp, Storage: store, }) if err != nil { b.Fatal(err) } source := cfg.Importer.Sources["nixpkgs"] source.Programs.Enable = false err = imp.Start( b.Context(), false, false, &[]string{source.Key}, ) if err != nil { b.Fatal(err) } hadErrors, err := ImportSource( b.Context(), logger.Named("importer"), store, source, write, ) if err != nil { b.Fatal(err) } if hadErrors { b.Fatal("had errors") } } |