Skip to content

Commit fc7f408

Browse files
chore: loading resources to run locally (#74)
## Summary - Load local resources irrespective of where the tests are currently being run from. This allows us to run them from Intellij. - ## Checklist - [x] Added Unit Tests - [x] Covered by existing CI - [x] Integration tested - [x] Documentation update <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved test robustness by replacing hardcoded file paths with dynamic resource URI retrieval for loading test data. - **Tests** - Enhanced flexibility in test cases for locating resources, ensuring consistent access regardless of the working directory. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 19a6b22 commit fc7f408

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

spark/src/test/scala/ai/chronon/spark/test/LocalDataLoaderTest.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class LocalDataLoaderTest {
4747

4848
@Test
4949
def loadDataFileAsTableShouldBeCorrect(): Unit = {
50-
val file = new File("spark/src/test/resources/local_data_csv/test_table_1_data.csv")
50+
val resourceURL = Option(getClass.getResource("/local_data_csv/test_table_1_data.csv"))
51+
.getOrElse(throw new IllegalStateException("Required test resource not found"))
52+
val file = new File(resourceURL.getFile)
5153
val nameSpaceAndTable = "test.table"
5254
LocalDataLoader.loadDataFileAsTable(file, spark, nameSpaceAndTable)
5355

@@ -60,7 +62,8 @@ class LocalDataLoaderTest {
6062

6163
@Test
6264
def loadDataRecursivelyShouldBeCorrect(): Unit = {
63-
val path = new File("spark/src/test/resources/local_data_csv")
65+
val resourceURI = getClass.getResource("/local_data_csv")
66+
val path = new File(resourceURI.getFile)
6467
LocalDataLoader.loadDataRecursively(path, spark)
6568

6669
val loadedDataDf = spark.sql("SELECT * FROM local_data_csv.test_table_1_data")

0 commit comments

Comments
 (0)