From fb0357947f61dbba1677c6d9b4195d56d11d7e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Mon, 18 Sep 2023 14:11:11 +0200 Subject: [PATCH] sql: add more tests (#74919) --- .../sql/components/SqlComponents.test.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/public/app/features/plugins/sql/components/SqlComponents.test.tsx b/public/app/features/plugins/sql/components/SqlComponents.test.tsx index 696cf6598e7..412abd45f3c 100644 --- a/public/app/features/plugins/sql/components/SqlComponents.test.tsx +++ b/public/app/features/plugins/sql/components/SqlComponents.test.tsx @@ -87,7 +87,25 @@ describe('SQLWhereRow', () => { expect(exp.whereString).toBe('hostname IN (${multiHost})'); }); - it('should not remove quotes in a where clause not including a multi-value variable', () => { + it('should not remove quotes in a where clause including a non-multi variable', () => { + const exp: SQLExpression = { + whereString: "hostname IN ('${host}')", + }; + + const multiVar = customBuilder().withId('multiVar').withName('multiHost').build(); + const nonMultiVar = customBuilder().withId('nonMultiVar').withName('host').build(); + + multiVar.multi = true; + nonMultiVar.multi = false; + + const variables = [multiVar, nonMultiVar]; + + removeQuotesForMultiVariables(exp, variables); + + expect(exp.whereString).toBe("hostname IN ('${host}')"); + }); + + it('should not remove quotes in a where clause not including any known variables', () => { const exp: SQLExpression = { whereString: "hostname IN ('${nonMultiHost}')", };