Skip to content

Commit

Permalink
Migrate validation tests to e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Sep 30, 2022
1 parent 89fb3e9 commit a72dd54
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 55 deletions.
54 changes: 49 additions & 5 deletions client/tests/e2e/suite/extension.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
activateAndOpenInEditor,
getDocUri,
closeAllEditors,
sleep,
assertDiagnostics,
ensureGalaxyLanguageServerInstalled,
waitForDiagnostics,
} from "./helpers";
import * as assert from "assert";

Expand All @@ -19,21 +19,65 @@ suite("Extension Test Suite", () => {
});
teardown(closeAllEditors);
suite("Validation Tests", () => {
test("Tool should have minimum required attributes 'id' and 'name'", async () => {
test("Valid tool returns empty diagnostics", async () => {
const docUri = getDocUri(path.join("test_tool_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await assertDiagnostics(docUri, []);
});

test("Valid macro file returns empty diagnostics", async () => {
const docUri = getDocUri(path.join("macros_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await assertDiagnostics(docUri, []);
});

test("Invalid tool should return diagnostics for required attributes 'id' and 'name'", async () => {
const docUri = getDocUri(path.join("test_invalid_tool_01.xml"));
await activateAndOpenInEditor(docUri);

await sleep(2000); // Wait for diagnostics
await waitForDiagnostics();
await assertDiagnostics(docUri, [
{
message: "Element 'tool': The attribute 'id' is required but missing.",
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)),
severity: 0,
severity: vscode.DiagnosticSeverity.Error,
},
{
message: "Element 'tool': The attribute 'name' is required but missing.",
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)),
severity: 0,
severity: vscode.DiagnosticSeverity.Error,
},
]);
});

test("Invalid tool document with syntax error should return diagnostic", async () => {
const docUri = getDocUri(path.join("test_syntax_error_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await assertDiagnostics(docUri, [
{
message: "Couldn't find end of Start Tag tool line 1, line 2, column 1",
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 1)),
severity: vscode.DiagnosticSeverity.Error,
},
]);
});

test("Invalid macro document with syntax error should return diagnostic", async () => {
const docUri = getDocUri(path.join("test_syntax_error_macro_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await assertDiagnostics(docUri, [
{
message: "Premature end of data in tag macros line 1, line 2, column 1",
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 1)),
severity: vscode.DiagnosticSeverity.Error,
},
]);
});
Expand Down
6 changes: 6 additions & 0 deletions server/galaxyls/tests/files/macros_01.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<macros>
<token name="@WRAPPER_VERSION@">0.1.0</token>
<macro name="inputs">
<inputs/>
</macro>
</macros>
1 change: 1 addition & 0 deletions server/galaxyls/tests/files/test_syntax_error_01.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<tool
1 change: 1 addition & 0 deletions server/galaxyls/tests/files/test_syntax_error_macro_01.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<macros>unclosed
2 changes: 0 additions & 2 deletions server/galaxyls/tests/unit/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@

TEST_SYNTAX_ERROR_TOOL_01_DOCUMENT = Document("file://test_syntax_error_01.xml", "tool")

TEST_SYNTAX_ERROR_MACRO_01_DOCUMENT = Document("file://test_syntax_error_macro_01.xml", "<macros>unclosed")

TEST_TOOL_WITH_PROLOG = """<?xml version="1.0" encoding="UTF-8"?>
<tool id="test" name="Test Tool" version="0.1.0">
<inputs/>
Expand Down
48 changes: 0 additions & 48 deletions server/galaxyls/tests/unit/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

from galaxyls.services.validation import DocumentValidator
from ...services.xsd.constants import TOOL_XSD_FILE
from ...services.xsd.validation import GalaxyToolSchemaValidationService
from .sample_data import (
TEST_MACRO_01_DOCUMENT,
TEST_SYNTAX_ERROR_MACRO_01_DOCUMENT,
TEST_SYNTAX_ERROR_TOOL_01_DOCUMENT,
)
from .utils import TestUtils


Expand All @@ -19,48 +13,6 @@ def xsd_schema() -> etree.XMLSchema:
return schema


class TestGalaxyToolValidationServiceClass:
def test_validate_document_returns_empty_diagnostics_when_valid(self, xsd_schema: etree.XMLSchema) -> None:
service = GalaxyToolSchemaValidationService(xsd_schema)
xml_document = TestUtils.get_test_xml_document_from_file("test_tool_01.xml")

actual = service.validate_document(xml_document)

assert actual == []

def test_validate_macro_file_returns_empty_diagnostics_when_valid(self, xsd_schema: etree.XMLSchema) -> None:
service = GalaxyToolSchemaValidationService(xsd_schema)
xml_document = TestUtils.from_document_to_xml_document(TEST_MACRO_01_DOCUMENT)

actual = service.validate_document(xml_document)

assert actual == []

def test_validate_document_returns_diagnostics_when_invalid(self, xsd_schema: etree.XMLSchema) -> None:
service = GalaxyToolSchemaValidationService(xsd_schema)
xml_document = TestUtils.get_test_xml_document_from_file("test_invalid_tool_01.xml")

actual = service.validate_document(xml_document)

assert len(actual) > 0

def test_validate_document_returns_diagnostics_when_syntax_error(self, xsd_schema: etree.XMLSchema) -> None:
service = GalaxyToolSchemaValidationService(xsd_schema)
xml_document = TestUtils.from_document_to_xml_document(TEST_SYNTAX_ERROR_TOOL_01_DOCUMENT)

actual = service.validate_document(xml_document)

assert len(actual) == 1

def test_validate_macro_file_returns_diagnostics_when_syntax_error(self, xsd_schema: etree.XMLSchema) -> None:
service = GalaxyToolSchemaValidationService(xsd_schema)
xml_document = TestUtils.from_document_to_xml_document(TEST_SYNTAX_ERROR_MACRO_01_DOCUMENT)

actual = service.validate_document(xml_document)

assert len(actual) == 1


class TestDocumentValidatorClass:
@pytest.mark.parametrize(
"source, expected",
Expand Down

0 comments on commit a72dd54

Please sign in to comment.