Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit d76b0a84
authored
Sep 29, 2018
by
Takashi Sasaki
Committed by
Sushant
Sep 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query): check valid warn message (#9919) (#9948)
1 parent
fa2f3733
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
lib/dialects/mysql/query.js
test/integration/dialects/mysql/warning.test.js
test/unit/dialects/mysql/query.test.js
lib/dialects/mysql/query.js
View file @
d76b0a8
...
...
@@ -178,6 +178,7 @@ class Query extends AbstractQuery {
const
warningMessage
=
'MySQL Warnings ('
+
(
this
.
connection
.
uuid
||
'default'
)
+
'): '
;
const
messages
=
[];
for
(
const
_warningRow
of
warningResults
)
{
if
(
typeof
_warningRow
===
'undefined'
||
typeof
_warningRow
[
Symbol
.
iterator
]
!==
'function'
)
continue
;
for
(
const
_warningResult
of
_warningRow
)
{
if
(
_warningResult
.
hasOwnProperty
(
'Message'
))
{
messages
.
push
(
_warningResult
.
Message
);
...
...
test/integration/dialects/mysql/warning.test.js
0 → 100644
View file @
d76b0a8
'use strict'
;
const
chai
=
require
(
'chai'
);
const
expect
=
chai
.
expect
;
const
Support
=
require
(
'../../../support'
);
const
Sequelize
=
Support
.
Sequelize
;
const
dialect
=
Support
.
getTestDialect
();
const
sinon
=
require
(
'sinon'
);
describe
(
Support
.
getTestDialectTeaser
(
'Warning'
),
()
=>
{
// We can only test MySQL warnings when using MySQL.
if
(
dialect
===
'mysql'
)
{
describe
(
'logging'
,
()
=>
{
it
(
'logs warnings when there are warnings'
,
()
=>
{
const
logger
=
sinon
.
spy
(
console
,
'log'
);
const
sequelize
=
Support
.
createSequelizeInstance
({
logging
:
logger
,
benchmark
:
false
,
showWarnings
:
true
});
const
Model
=
sequelize
.
define
(
'model'
,
{
name
:
Sequelize
.
DataTypes
.
STRING
(
1
,
true
)
});
return
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
sequelize
.
authenticate
();
}).
then
(()
=>
{
return
sequelize
.
query
(
"SET SESSION sql_mode='';"
);
}).
then
(()
=>
{
return
Model
.
create
({
name
:
'very-long-long-name'
});
}).
then
(()
=>
{
// last log is warning message
expect
(
logger
.
args
[
logger
.
args
.
length
-
1
][
0
]).
to
.
be
.
match
(
/^MySQL Warnings
\(
default
\)
:.*/m
);
},
()
=>
{
expect
.
fail
();
});
});
});
}
});
\ No newline at end of file
test/unit/dialects/mysql/query.test.js
0 → 100644
View file @
d76b0a8
'use strict'
;
const
path
=
require
(
'path'
);
const
Query
=
require
(
path
.
resolve
(
'./lib/dialects/mysql/query.js'
));
const
Support
=
require
(
path
.
join
(
__dirname
,
'./../../support'
));
const
chai
=
require
(
'chai'
);
const
sinon
=
require
(
'sinon'
);
const
current
=
Support
.
sequelize
;
const
expect
=
chai
.
expect
;
describe
(
'[MYSQL Specific] Query'
,
()
=>
{
describe
(
'logWarnings'
,
()
=>
{
beforeEach
(()
=>
{
sinon
.
spy
(
console
,
'log'
);
});
afterEach
(()
=>
{
console
.
log
.
restore
();
});
it
(
'check iterable'
,
()
=>
{
const
validWarning
=
[];
const
invalidWarning
=
{};
const
warnings
=
[
validWarning
,
undefined
,
invalidWarning
];
const
query
=
new
Query
({},
current
,
{});
const
stub
=
sinon
.
stub
(
query
,
'run'
);
stub
.
onFirstCall
().
resolves
(
warnings
);
return
query
.
logWarnings
(
'dummy-results'
).
then
(
results
=>
{
expect
(
'dummy-results'
).
to
.
equal
(
results
);
expect
(
true
).
to
.
equal
(
console
.
log
.
calledOnce
);
});
});
});
});
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment