-
Notifications
You must be signed in to change notification settings - Fork 9
/
ConnectionProviderModule.qtest
executable file
·89 lines (75 loc) · 3.34 KB
/
ConnectionProviderModule.qtest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-
%require-types
%enable-all-warnings
%new-style
%strict-args
%allow-injection
%requires ../../../../qlib/Util.qm
%requires ../../../../qlib/QUnit.qm
%exec-class ConnectionProviderModuleTest
public class ConnectionProviderModuleTest inherits QUnit::Test {
constructor() : Test("ConnectionProvider Test", "1.0") {
addTestCase("urlp test", \urlProviderTest());
addTestCase("urlp neg test", \urlProviderNegativeTest());
addTestCase("filesystem", \filesystemConnectionTest());
# Return for compatibility with test harness that checks return value.
set_return_value(main());
}
urlProviderTest() {
Program mp(PO_NO_CHILD_PO_RESTRICTIONS|PO_NEW_STYLE);
mp.setGlobalVarValue("ENV", ENV + {"QORE_CONNECTION_PROVIDERS": get_script_dir() + "./TestConnectionProvider.qm"});
mp.loadApplyToUserModule(get_script_dir() + "../../../../qlib/ConnectionProvider", True);
{
Program p();
p.loadModule("ConnectionProvider");
p.parse("string sub test(string str) { return get_connection_url(str); }", "");
assertEq("test://user:pass@x", p.callFunction("test", "X"));
assertThrows("CONNECTION-ERROR", \p.callFunction(), ("test", "Y"));
}
{
Program p();
p.loadModule("ConnectionProvider");
p.parsePending("AbstractConnection sub get_obj(string str) { return get_connection(str); }", "");
p.parsePending("hash sub get_conn() { return get_connections(); }", "");
p.parse("hash sub get_hash() { return get_connection_hash(); }", "");
any obj = p.callFunction("get_obj", "X");
assertEq(Type::Object, obj.type());
assertEq("test://user:<masked>@x", obj.getInfo().url);
assertEq(NOTHING, obj.getInfo().url_hash.password);
assertEq("test://user:pass@x", obj.getInfo(True).url);
assertEq("pass", obj.getInfo(True).url_hash.password);
assertEq(Type::Hash, p.callFunction("get_conn").type());
assertEq(Type::Hash, p.callFunction("get_hash").type());
}
}
urlProviderNegativeTest() {
Program mp(PO_NO_CHILD_PO_RESTRICTIONS|PO_NEW_STYLE);
mp.loadApplyToUserModule(get_script_dir() + "../../../../qlib/ConnectionProvider", True);
Program p();
p.loadModule("ConnectionProvider");
p.parse("string sub test(string str) { return get_connection_url(str); }", "");
assertThrows("CONNECTION-ERROR", \p.callFunction(), ("test", "X"));
assertEq("X://x", p.callFunction("test", "X://x"));
}
filesystemConnectionTest() {
Program p();
p.loadModule("ConnectionProvider");
p.loadModule("Util");
p.parse("FilesystemConnection sub get_conn() {
string dir = tmp_location() + '/' + get_random_string() + '/' + get_random_string();
string url = 'file://' + dir;
return new FilesystemConnection('test', 'desc', url);
}", "");
object o = p.callFunction("get_conn");
hash h = o.ping();
assertEq("test", h.name);
assertEq("desc", h.desc);
assertEq(False, h.ok);
o.opts.readonly = True;
h = o.ping();
assertEq("test", h.name);
assertEq("desc", h.desc);
assertEq(True, h.ok);
}
}