Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

io.github.ricall.junit5-sftp:junit5-sftp

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io.github.ricall.junit5-sftp:junit5-sftp

A JUnit 5 extension library that allows you to fake a SFTP server.

  • 2.0.1
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

JUnit 5 SFTP server

What is it?

This JUnit 5 libary provides a way to create a sftp server that can be used for integration testing.

How to use it

Gradle

Add the dependency to gradle

testImplementation 'io.github.ricall.junit5-sftp:junit5-sftp:2.0.1'

Maven

Add the dependency to mvn pom.xml


<dependency>
    <groupId>io.github.ricall.junit5-sftp</groupId>
    <artifactId>junit5-sftp</artifactId>
    <version>2.0.1</version>
    <scope>test</scope>
</dependency>

Using the JUnit5 extension

public class TestEmbeddedSftpServer {

    @RegisterExtension
    public final EmbeddedSftpServer sftpServer = SftpServer.defaultSftpServer()
            .withPort(3022)
            .withUser("user", "pass")
            .withResources(resourceAt("/tmp/data").fromClasspathResource("/data"))
            .build();

    @Test
    public void verifySftpFilesCanBeDownloaded() {
        // sftp server is running on sftp://user:pass@localhost:3022
        // the files and directories from the data package are copied into the /tmp/data folder
        // on the sftp server
    }
    
}

The FTP server uses an in-memory FileSystem to manage files, between tests the file system is recreated so that tests do not impact each other.

Using the FileSystemResource abstraction.

@SftpEmbeddableServerExtension provides a powerful FileSystemResource abstraction that allows you to populate the in-memory FileSystem with files/folders in a simple easy to use fashion.


FileSystemResource withText

Return a FileSystemResource that will populate the /tmp/file1.txt file with File Contents

FileSystemResource.resourceAt("/tmp/file1.txt").withText("File Contents")

FileSystemResource withContent

Return a FileSystemResource that will populate the /tmp/file2.txt file with the data returned from createFileInputStream()

FileSystemResource.resourceAt("/tmp/file2.txt").withContent(this::createFileInputStream)

FileSystemResource fromClasspathResource

Return a list of FileSystemResource's that will populate the /tmp/test-data folder with all files/directories under the test.data package.

FileSystemResource.resourceAt("/tmp/test-data").fromClasspathResource("/test/data")

FileSystemResource fromPath

Return a list of FileSystemResource's that will populate the /tmp/folder folder with all the files/directories under path (path can be files/folders on your hard drive, files/folders in a ZIP/TAR container or event files/folders in another in-memory filesystem)

FileSystemResource.resourceAt("/tmp/folder").fromPath(path)

License

This software is licensed using MIT

FAQs

Package last updated on 22 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc