fake-sftp-server-lambda icon indicating copy to clipboard operation
fake-sftp-server-lambda copied to clipboard

Enhancement: Split Start and Stop of Server

Open Stromner opened this issue 4 years ago • 6 comments
trafficstars

I've got a couple of detailed test cases where we do multiple sftp related calls. They look very odd when I have to wrap all of the test rows inside the withSftpServer lambda. It would be much more preferable if start and stop of the server was independent of each other.

Stromner avatar Feb 23 '21 14:02 Stromner

Can you please show me such a test. I would like to understand better the problem that should be solved. You can remove details of the test and replace it with comments of course.

stefanbirkner avatar Mar 13 '21 00:03 stefanbirkner

Very short and without code it looks something like this:

// Setup
// Call to unrelated service
// Start fake-sftp-server
   // Call(s) to service that needs to use SFTP
   // Get file A from the server
      // Verify file
   // Get file B from the server
      // Verify file
   ...
   // If files passed verification upload response
      // Verify that service transformed the file correctly
...

I know there are a couple of things that I can do myself to make this big withSftpServer smaller. Like moving the last if block to a separate withSftpServer but it doesn't sit well with me to essentially use two ftp servers when in reality it's the same server. Or breaking out the verification but that breaks how we generally structure our tests in the code base with verifying as we go instead of doing it "in batches". But even if I did do these refactoring it would still be a a couple of rows wrapped inside the call to setup the fake ftp server thus the reason I would like to control the start and stop of the sftp server myself.

Stromner avatar Mar 16 '21 21:03 Stromner

Forgot to mention but it also creates a lot of extra bulk having to set up new users, ports and directories everywhere when generally it's the same for all tests

Stromner avatar Mar 25 '21 07:03 Stromner

Let me rephrase what I understood. From your point of view there are too issues with using Fake SFTP Server Lambda.

  1. Most of your test methods have an additional level of indent because the code is within a lambda expression like
@Test
void someTest() {
  withSftpServer(server -> {
     ... // a lot of lines with your test code
  });
}
  1. You have the same setup code in every method
@Test
void someTest() {
  //common setup code that is repeated in every test
  withSftpServer(server -> {
     ...
  });
}

Is that correct?

stefanbirkner avatar Mar 28 '21 00:03 stefanbirkner

Correct but as I added in the comment just above I also have to set up users, ports, folder et.c constantly even though they rarely differs between the tests that needs to use SFTP.

Stromner avatar Mar 29 '21 12:03 Stromner

+1 for this.

We use this library in scala and it makes our tests very big and less readable, we would like to have a single instance of the fake server for the whole tests in a file, like this:

val server = new FakeSftpServer()
override def beforeAllTests() {
  server.start
  server.putFile(.....)
  server.putFile(.....)
}

override def afterAllTests() {
  server.stop
}

The problem is that FakeSftpServer needs memory filesystem as constructor (have to add a dependency to marschall.memoryfilesystem) and server.start is private.

mpindado avatar Aug 18 '21 10:08 mpindado