-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlabci.m
73 lines (54 loc) · 2.14 KB
/
gitlabci.m
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
%% test raw mariadb mex file
HOSTNAME = getenv('MYSQL_HOST');
if length(HOSTNAME) == 0
HOSTNAME = '127.0.0.1'
end
MARIADB_10_4 = "10.4.4-MariaDB";
MARIADB_10_3 = "10.3.14-MariaDB";
MARIADB_10_2 = "10.2.17-MariaDB";
MARIADB_10_1 = "10.1.35-MariaDB";
MARIADB_10_0 = "10.0.36-MariaDB";
MARIADB_5_5 = "5.5.61-MariaDB";
MYSQL_5_7 = "5.7.21";
function retval = check_version (input_string)
retval = strfind (input_string, "10.") || strfind (input_string, "5.");
end
testMex = @(x) strcat('MEX FILE: ', x);
testClassdef = @(x) strcat('CLASSDEF: ', x);
retval = mariadb_(HOSTNAME, 3306, 'root', 'password', 'select version() as version');
assert(2 == length(retval),
testMex('data length must be 2'))
assert(1 == strcmp(retval{1}, 'version'),
testMex('first cell value must be string "version"'))
assert(1 == check_version(retval{2}),
testMex('check for mariadb/mysql version'))
%% classdef tests
sql = mariadb('hostname', HOSTNAME, 'password', 'password');
retval = sql.query('select version() as version');
assert(2 == length(retval),
testClassdef('data length must be 2'))
assert(1 == strcmp(retval{1}, 'version'),
testClassdef('first cell value must be string "version"'))
assert(1 == check_version(retval{2}),
testClassdef('check for mariadb/mysql version'))
% test change output format
sql.output = 'mat';
retval = sql.query('select version() as version');
assert(1 == ismatrix(retval),
testClassdef('return value must be a Matrix'))
assert(0 == numel(sql.query('create database if not exists octave')),
testClassdef('create database octave'))
% test change database
sql.database = 'octave';
assert(0 == numel(sql.query('create table a (idx int)')),
testClassdef('create table a'))
% test connection with given database
sql = mariadb('hostname', HOSTNAME, 'password', 'password', 'database', 'octave');
sql.output = 'mat';
assert(0 == numel(sql.query('insert into a (idx) values (1),(2),(3),(4)')),
testClassdef('insert data into table a'))
retval = sql.query('select * from a');
assert(10 == sum(retval(~isnan(retval))),
testClassdef('sum all numbers of table a'))
assert(isnan(retval(1)),
testClassdef('first element is not a number'))