Skip to content
Snippets Groups Projects
Commit 0676e7ba authored by Michal Svamberg's avatar Michal Svamberg
Browse files

Vylepseni testu

parent a8c58360
No related branches found
No related tags found
No related merge requests found
Pipeline #3648 failed
......@@ -18,7 +18,7 @@ class Location {
/// * scp scp://[user@]host[:port][/path]
Location(this._uri) {
String pattern = _selectPattern();
//print(pattern);
final regExp = RegExp(pattern, caseSensitive: false);
RegExpMatch regExpMatch = regExp.firstMatch(_uri)!;
user = (regExpMatch.namedGroup('user') == '') ? null : regExpMatch.namedGroup('user');
......
......@@ -13,31 +13,36 @@ class Method {
String selectCommand(bool cond, String command, String last) {
if (cond == true) {
print('+ $command');
print('+ $command'); // DEBUG
return (last.isEmpty) ? command : last;
}
else {
print('- $command');
print('- $command'); // DEBUG
return last;
}
}
String getCommand() {
String best = '';
print("SRC: ${src.location.host} -> DST: ${dst.location.host}");
best = selectCommand(
src.location.host != null && src.location.host == dst.location.host && src.isScpRemote(),
"ssh ${dst.getAsSsh()} 'cp ${opt.getAsCp()} ${src.getScpPath()} ${dst.getScpPath()}'",
best);
best = selectCommand(
src.isScpDirect() && dst.isScpRemote(),
"scp ${opt.getAsScp()} ${src.getAsScp()} ${dst.getAsScp()}",
"scp ${opt.getAsScp(remove:['3'])} ${src.getAsScp()} ${dst.getAsScp()}",
best);
best = selectCommand(
src.isScpRemote() && dst.isScpDirect() && !opt.isDefinedPort(),
"ssh ${dst.getAsSsh()} -c 'scp ${opt.getAsScp()} ${src.getAsScp()} ${dst.getAsCp()}'",
"ssh ${dst.getAsSsh()} 'scp ${opt.getAsScp(remove:['3'])} ${src.getAsScp()} ${dst.getAsCp()}'",
best);
best = selectCommand(
src.isScpRemote() && dst.isScpRemote(),
"scp -3 ${opt.getAsScp()} ${src.getAsScp()} ${dst.getAsScp()}",
"scp -3 ${opt.getAsScp(remove:['3'])} ${src.getAsScp()} ${dst.getAsScp()}",
best);
best = selectCommand(
......
......@@ -19,7 +19,7 @@ String Optimize(Options opt) {
//print('SRC: ${storageSrc.availableMethods()}');
Storage storageDst = Storage(locationDst);
print('DST: ${storageDst.availableMethods()}');
//print('DST: ${storageDst.availableMethods()}');
// najit vsechny spolecne metody, jako prunik
List<Copy> storageIntersect = storageSrc.intersection(storageDst);
......@@ -32,7 +32,7 @@ String Optimize(Options opt) {
// vybrat první metodu a vrátit výsledek
//print('${storageIntersect.first}');
Method method = Method(storageSrc, storageDst, storageIntersect.first, opt);
print("===DEBUG MODE===");
//print("===DEBUG MODE===");
return method.getCommand();
}
\ No newline at end of file
......@@ -80,11 +80,14 @@ class Options {
return _sources;
}
String getAsScp() {
String getAsScp({List<String> remove = const []} ) {
String optOut = '';
List<String> opts = ['3', '4', '6', 'A', 'B', 'C', 'p', 'q', 'r', 'T', 'v', 'c', 'F', 'i', 'J', 'l', 'o', 'P', 'S'];
for (var element in opts) {
if (remove.contains(element)) {
continue;
}
if (_parser.options[element]?.isFlag == true && _results[element] == true) {
optOut = "$optOut -$element";
}
......
......@@ -149,8 +149,11 @@ class Storage {
if (location.host == null && getFqdn().isEmpty) {
return "${location.path}";
}
else {
String uri = 'scp://';
String uri = '';
if (location.path != null && !(location.path!.startsWith('~'))) {
uri = 'scp://';
}
if (location.user != null) {
uri += "${location.user}@";
}
......@@ -158,10 +161,9 @@ class Storage {
if (location.port != null) {
uri += "${location.port}";
}
uri += "${getScpPath()}";
uri += getScpPath();
return uri;
}
}
String getAsSsh() {
String command = '';
......
......@@ -183,7 +183,7 @@ class StorageData {
"fqdn": "storage-du-cesnet.metacentrum.cz",
"match_host": "^storage-du-cesnet.*",
"match_path": "^/(auto|storage)/du-cesnet/.*",
"scpDirect": true,
"scpDirect": false,
"scpRemote": true,
"copy": true,
"nfsMounts": [ "/storage/du-cesnet", "/auto/du-cesnet" ]
......
......@@ -65,13 +65,22 @@ void main() {
});
test('relative path as .*', () {
Location location = Location('../test/_file.');
Location location = Location('../test/_file');
expect(location.user, null);
expect(location.host, null);
expect(location.path, File('../test/_file.').absolute.path);
expect(location.path, File('../test/_file').absolute.path);
expect(location.port, null);
});
test('home dir on NFS storage', () {
Location location = Location('storage-praha1:~/test/_file');
expect(location.user, null);
expect(location.host, 'storage-praha1');
expect(location.path, '~/test/_file');
expect(location.port, null);
});
});
......
......@@ -5,17 +5,25 @@ import 'package:scp_meta/options.dart';
import 'package:test/test.dart';
void main() {
group('Copy without changes', () {
group('Copy without change of protocol or path', () {
test('storage-storage', () {
expect(Optimize(Options(
["username@storage-plzen1:/src/file.txt", "username@storage-plzen1:/dst/file.txt"], reparse: true)),
"scp scp://username@storage-plzen1:/src/file.txt scp://username@storage-plzen1:/dst/file.txt");
["username@storage-plzen1:/src/file.txt", "username@storage-praha1:/dst/file.txt"], reparse: true)),
"scp scp://username@storage-plzen1:/src/file.txt scp://username@storage-praha1:/dst/file.txt");
});
test('local-local', () {
expect(Optimize(Options(
["/src/file.txt", "/dst/file.txt"], reparse: true)),
"scp /src/file.txt /dst/file.txt");
});
test('local-storage_with_tilda', () {
expect(Optimize(Options(
["~/file.txt", "storage-praha1:~alice/dst/file.txt"], reparse: true)),
"scp ~/file.txt storage-praha1:~alice/dst/file.txt");
});
});
group('Copy with change on target', () {
......@@ -24,13 +32,36 @@ void main() {
["/src/file.txt", "vorel@skirit.metacentrum.cz:/storage/praha5-elixir/home/vorel"], reparse: true)),
"scp /src/file.txt scp://vorel@storage-praha5-elixir.metacentrum.cz:/home/vorel");
});
/*
test('local-storage', () {
expect(Optimize(Options(
["/src/file.txt", "/dst/file.txt"], reparse: true)),
"scp /src/file.txt /dst/file.txt");
["file.txt", "tarkil:/storage/plzen1/home/svamberg/dst/file.txt"], reparse: true)),
"scp ${Directory.current.path}/file.txt scp://storage-plzen1.metacentrum.cz:/home/svamberg/dst/file.txt");
});
});
group('Examples from presentation', () {
test('black example', () {
expect(Optimize(Options(
["tarkil:/storage/plzen1/home/userA/data", "skirit:/storage/praha1/home/userA/data"], reparse: true)),
"scp scp://storage-plzen1.metacentrum.cz:/home/userA/data scp://storage-vestec1-elixir.metacentrum.cz:/home/userA/data");
});
*/
test('red example', () {
expect(Optimize(Options(
["/storage/plzen1/home/userA/data", "/storage/praha1/home/userA/data"], reparse: true)),
"scp scp://storage-plzen1.metacentrum.cz:/home/userA/data scp://storage-vestec1-elixir.metacentrum.cz:/home/userA/data");
});
test('green example', () {
expect(Optimize(Options(
["/storage/brno2/home/userB/data", "/storage/brno2/project/X"], reparse: true)),
"ssh storage-brno6.metacentrum.cz 'cp /home/userB/data /project/X'");
});
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment