|
25 | 25 | import org.junit.Assert; |
26 | 26 | import org.junit.Test; |
27 | 27 | import org.mockito.Mockito; |
| 28 | + |
28 | 29 | import java.io.IOException; |
29 | 30 | import java.sql.Types; |
30 | 31 | import java.util.ArrayList; |
@@ -144,4 +145,37 @@ public void testGetSchemaFromSnowflake() throws IOException { |
144 | 145 | Assert.assertTrue(collector.getValidationFailures().isEmpty()); |
145 | 146 | Assert.assertEquals(expected, actual); |
146 | 147 | } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void testGetSchemaWhenMacroIsEnabled() { |
| 151 | + Schema expected = Schema.recordOf("test", |
| 152 | + Schema.Field.of("test_field", Schema.nullableOf(Schema.of(Schema.Type.LONG))) |
| 153 | + ); |
| 154 | + |
| 155 | + SnowflakeBatchSourceConfig mockConfig = Mockito.mock(SnowflakeBatchSourceConfig.class); |
| 156 | + Mockito.when(mockConfig.canConnect()).thenReturn(false); |
| 157 | + Mockito.when(mockConfig.getSchema()).thenReturn(expected.toString()); |
| 158 | + |
| 159 | + MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE); |
| 160 | + Schema actual = SchemaHelper.getSchema(mockConfig, collector); |
| 161 | + |
| 162 | + Assert.assertTrue(collector.getValidationFailures().isEmpty()); |
| 163 | + Assert.assertEquals(expected, actual); |
| 164 | + |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + public void testGetSchemaWhenMacroIsEnabledSchemaIsNull() { |
| 169 | + |
| 170 | + SnowflakeBatchSourceConfig mockConfig = Mockito.mock(SnowflakeBatchSourceConfig.class); |
| 171 | + Mockito.when(mockConfig.canConnect()).thenReturn(false); |
| 172 | + Mockito.when(mockConfig.getSchema()).thenReturn(null); |
| 173 | + |
| 174 | + MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE); |
| 175 | + Schema actual = SchemaHelper.getSchema(mockConfig, collector); |
| 176 | + |
| 177 | + Assert.assertTrue(collector.getValidationFailures().isEmpty()); |
| 178 | + Assert.assertNull(actual); |
| 179 | + |
| 180 | + } |
147 | 181 | } |
0 commit comments