package main import ( "testing" "github.com/stretchr/testify/assert" ) var xmlData = Message{ corpusName: "test", name: "test-default.xml", startAt: 1456693426, extension: ".xml", path: "./example/xml/test-default.xml", mimetype: "text/xml", size: 7123, } func TestValidXML(t *testing.T) { result := getXMlData(xmlData.path) assert.Equal(t, result.doctype.Sysid, "note.dtd", "Doctype is valid") assert.Equal(t, result.isWellFormed, true, "XML is well formed") assert.Equal(t, len(result.wellFormedErrors), 0, "Return empty if xml is not well formed") } func TestInvalidXML(t *testing.T) { xmlData.path = "./example/xml/test-not-wellformed.xml" result := getXMlData(xmlData.path) assert.Equal(t, result.doctype.Sysid, "", "Not get doctype if xml is invalid") assert.Equal(t, result.isWellFormed, false, "XML is not well formed") assert.Equal(t, result.wellFormedErrors[0].Message, "Opening and ending tag mismatch: from line 4 and Ffrom <from>Jani</Ffrom>", "Return empty if xml is not well formed") assert.Equal(t, result.wellFormedErrors[0].Line, "4", "Return empty if xml is not well formed") } func TestValidDTD(t *testing.T) { listDTD = append(listDTD, "./example/dtd/note.dtd") xmlData.path = "./example/xml/test-default.xml" result := processDetailledAnalysis(xmlData.path, "note.dtd") assert.Equal(t, result.isValidAgainstDTD, true, "XML must be valid according to the DTD") } func TestInvalidDTD(t *testing.T) { listDTD = append(listDTD, "./example/dtd/note.dtd") xmlData.path = "./example/xml/test-default-bad-doctype.xml" result := processDetailledAnalysis(xmlData.path, "bad-doctype.dtd") assert.Equal(t, result.isValidAgainstDTD, false, "XML must not be valid according to the DTD") } func TestValidSchema(t *testing.T) { listDTD = append(listDTD, "./example/dtd/note.dtd") listXSD = append(listXSD, "./example/xsd/note.xsd") xmlData.path = "./example/xml/test-default.xml" result := processDetailledAnalysis(xmlData.path, "") assert.Equal(t, result.isValidAgainstSchema, true, "XML must be valid according to the Schema") }