Skip to content

Commit 62a22d9

Browse files
committed
Update samples and tests
1 parent e6355a6 commit 62a22d9

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

examples/2-pssql/src/sample.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- sample
2-
SELECT * FROM test;
2+
SELECT * FROM sample.test order by 1;
3+
34

45
SELECT name,name FROM test;
56
/*

examples/3-mysql/src/sample.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- sample
2-
SELECT * FROM test;
2+
SELECT * FROM sample.test order by 1;
33
SELECT name,name FROM test;
44
/*
55
end comment

src/sonar-sql-plugin/src/test/java/org/sonar/plugins/sql/sensors/SQLSensorTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,27 @@ public void testPsSQL() throws IOException {
5757
SQLSensor s = new SQLSensor();
5858
s.execute(ctxTester);
5959

60-
Assert.assertEquals(0, ctxTester.allIssues().size());
60+
Assert.assertEquals(2, ctxTester.allIssues().size());
61+
62+
}
63+
64+
@SuppressWarnings("deprecation")
65+
@Test
66+
public void testMySQL() throws IOException {
67+
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
68+
ctxTester.settings().setProperty(Constants.PLUGIN_SQL_DIALECT, "mysql");
69+
File baseFile = folder.newFile("test.sql");
70+
FileUtils.copyURLToFile(getClass().getResource("/mysql/sample1.sql"), baseFile);
71+
72+
String contents = new String(Files.readAllBytes(baseFile.toPath()));
73+
DefaultInputFile ti = new TestInputFileBuilder("test", "test.sql").initMetadata(contents).setContents(contents)
74+
.setLanguage(Constants.languageKey).build();
75+
ctxTester.fileSystem().add(ti);
76+
77+
SQLSensor s = new SQLSensor();
78+
s.execute(ctxTester);
79+
80+
Assert.assertEquals(2, ctxTester.allIssues().size());
6181

6282
}
6383

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM sample.test order by 1;

src/sonar-sql-plugin/src/test/resources/pssql/sample1.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ SET row_security = off;
2020

2121
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
2222

23+
24+
SELECT * FROM sample.test order by 1;

0 commit comments

Comments
 (0)