Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from int128/refactor-spec
Migrate complex file transfer specs to os-integration-test
- Loading branch information
Showing
8 changed files
with
968 additions
and
971 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
os-integration-test/src/main/groovy/org/hidetake/groovy/ssh/test/os/FileDivCategory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.hidetake.groovy.ssh.test.os | ||
|
||
@Category(File) | ||
class FileDivCategory { | ||
|
||
File div(String child) { | ||
new File(this as File, child) | ||
} | ||
|
||
File div(MkdirType type) { | ||
switch (type) { | ||
case MkdirType.DIRECTORY: | ||
assert mkdir() | ||
break | ||
|
||
case MkdirType.DIRECTORIES: | ||
assert mkdirs() | ||
break | ||
|
||
default: | ||
throw new IllegalArgumentException("Unknown mkdir type: $type") | ||
} | ||
this | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
os-integration-test/src/main/groovy/org/hidetake/groovy/ssh/test/os/MkdirType.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.hidetake.groovy.ssh.test.os | ||
|
||
enum MkdirType { | ||
DIRECTORY, | ||
DIRECTORIES | ||
} |
120 changes: 120 additions & 0 deletions
120
os-integration-test/src/main/groovy/org/hidetake/groovy/ssh/test/os/RemoteFixture.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.hidetake.groovy.ssh.test.os | ||
|
||
import groovy.transform.Canonical | ||
import groovy.util.logging.Slf4j | ||
import org.hidetake.groovy.ssh.Ssh | ||
import org.hidetake.groovy.ssh.core.Service | ||
import org.hidetake.groovy.ssh.operation.SftpException | ||
import org.junit.rules.ExternalResource | ||
|
||
@Slf4j | ||
class RemoteFixture extends ExternalResource { | ||
|
||
private final Service ssh = Ssh.newService() | ||
|
||
@Override | ||
protected void before() { | ||
Fixture.createRemotes(ssh) | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
} | ||
|
||
@Canonical | ||
static class RemotePath { | ||
Service ssh | ||
String path | ||
|
||
RemotePath div(String child) { | ||
new RemotePath(ssh, "$path/$child") | ||
} | ||
|
||
RemotePath div(MkdirType type) { | ||
switch (type) { | ||
case MkdirType.DIRECTORY: | ||
ssh.run { | ||
session(ssh.remotes.Default) { | ||
execute("mkdir $path") | ||
} | ||
} | ||
break | ||
|
||
case MkdirType.DIRECTORIES: | ||
ssh.run { | ||
session(ssh.remotes.Default) { | ||
execute("mkdir -p $path") | ||
} | ||
} | ||
break | ||
|
||
default: | ||
throw new IllegalArgumentException("Unknown mkdir type: $type") | ||
} | ||
this | ||
} | ||
|
||
String getName() { | ||
path.substring(path.lastIndexOf('/')) | ||
} | ||
|
||
String getText() { | ||
ssh.run { | ||
session(ssh.remotes.Default) { | ||
get from: path | ||
} | ||
} | ||
} | ||
|
||
RemotePath leftShift(String text) { | ||
ssh.run { | ||
session(ssh.remotes.Default) { | ||
put text: text, into: path | ||
} | ||
} | ||
this | ||
} | ||
|
||
List list() { | ||
ssh.run { | ||
session(ssh.remotes.Default) { | ||
sftp { | ||
ls(path).findAll { !(it.filename in ['.', '..']) } | ||
} | ||
} | ||
} as List | ||
} | ||
|
||
boolean exists() { | ||
try { | ||
ssh.run { | ||
session(ssh.remotes.Default) { | ||
sftp { | ||
stat(path) | ||
} | ||
} | ||
} as List | ||
true | ||
} catch (SftpException e) { | ||
false | ||
} | ||
} | ||
|
||
@Override | ||
String toString() { | ||
path | ||
} | ||
} | ||
|
||
RemotePath newFolder() { | ||
def path = new RemotePath(ssh, Fixture.remoteTmpPath()) | ||
path / MkdirType.DIRECTORY | ||
path | ||
} | ||
|
||
RemotePath newFile() { | ||
def folder = newFolder() | ||
folder / "${UUID.randomUUID()}" | ||
} | ||
|
||
} |
Oops, something went wrong.