-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding more unit test coverage (#295)
* Adding tests for ExtensionRestHandler Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com> * Adding unit tests for some more coverage Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com> * Addressing comments Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com> Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>
- Loading branch information
1 parent
3535849
commit 850fcb2
Showing
5 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.sdk; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
/* | ||
* Most of the code in BaseExtension is tested by HelloWorld extension tests. | ||
* This class tests code paths which are not tested. | ||
*/ | ||
public class TestBaseExtension extends OpenSearchTestCase { | ||
|
||
private static final String UNPARSEABLE_EXTENSION_CONFIG = "/bad-extension.yml"; | ||
private static final String EXTENSION_DESCRIPTOR_FILEPATH = "src/test/resources" + UNPARSEABLE_EXTENSION_CONFIG; | ||
|
||
public class TestExtension extends BaseExtension { | ||
|
||
public TestExtension(String path) { | ||
super(path); | ||
} | ||
} | ||
|
||
@Test | ||
public void testBaseExtensionWithNullPath() { | ||
// When a null path is passed, reading from YAML will fail. | ||
assertThrows(IllegalArgumentException.class, () -> { TestExtension testExtension = new TestExtension(null); }); | ||
} | ||
|
||
@Test | ||
public void testBaseExtensionWithBadConfig() { | ||
// When a bad extensions.yml config is passed, expect failing initialization. | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> { TestExtension testExtension = new TestExtension(EXTENSION_DESCRIPTOR_FILEPATH); } | ||
); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/org/opensearch/sdk/TestExtensionRestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.sdk; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.extensions.rest.ExtensionRestRequest; | ||
import org.opensearch.extensions.rest.ExtensionRestResponse; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class TestExtensionRestHandler extends OpenSearchTestCase { | ||
private class NoOpExtensionRestHandler implements ExtensionRestHandler { | ||
|
||
@Override | ||
public ExtensionRestResponse handleRequest(ExtensionRestRequest request) { | ||
return null; | ||
} | ||
} | ||
|
||
@Test | ||
public void testHandlerDefaultRoutes() { | ||
NoOpExtensionRestHandler handler = new NoOpExtensionRestHandler(); | ||
assertTrue(handler.routes().isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extensionName: bad-extension |