flapdoodle-oss / de.flapdoodle.embed.mongo.spring

embedded mongo spring integration
Apache License 2.0
32 stars 7 forks source link

Use local files instead of downloading it #16

Closed rfogel closed 1 year ago

rfogel commented 1 year ago

Hello.

I'm trying to run some tests on pipeline but I can't download anything so I want to embed the mongodb files in my project. Is there a way to load the image from filesystem(or classpath) instead of having it downloaded from internet?

Thanks in advanced

michaelmosmann commented 1 year ago

@rfogel i guess you are using spring with that.. as you can customize many aspects of flapdoodle mongodb (for instance https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/main/Howto.md#customize-downloader-implementation) currently the spring integration is not as customizable. There are some things you can try:

For anything else i must make the spring integration more customizeable .. (would suggest a system property for that)

rfogel commented 1 year ago

Hi Michael, thanks for your reply. Your link gave me a hint, so I managed to do it like this:

@Bean
@Primary
public Mongod mongod(MongodArguments mongodArguments, ProcessOutput processOutput, Net net, ProgressListener progressListener) {

            DownloadCache downloadCache = new DownloadCache() {
                @SneakyThrows
                @Override
                public Optional<Path> archiveFor(URL url, ArchiveType archiveType) {
                    return Optional.of(Path.of(ClassLoader.getSystemResource("mongodb.tgz").toURI()));
                }

                @Override
                public Path store(URL url, ArchiveType archiveType, Path path) {
                    return null;
                }
            };

            ImmutableMongod copy = Mongod.builder()
                    .mongodArguments(Start.to(MongodArguments.class).initializedWith(mongodArguments))
                    .net(Start.to(Net.class).initializedWith(net))
                    .processOutput(Start.to(ProcessOutput.class).initializedWith(processOutput))
                    .downloadCache(Start.to(DownloadCache.class).initializedWith(downloadCache))
                    .build();

            if (progressListener != null) {
                copy = copy.withProgressListener(Start.to(ProgressListener.class).initializedWith(progressListener));
            }

            return copy;
        }

Thanks again.

michaelmosmann commented 1 year ago

@rfogel .. ah.. interesting .. maybe i should improve the documentation. Even i did implement this i did not thought of this solution:)