Newer
Older
sisyphe-go / xml_test.go
@Nacim Nacim on 15 Feb 2022 1 KB change struct json
package main

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

var xmlData = Message{
	corpusName: "test",
	name:       "test-default.xml",
	startAt:    "Thu Mar  4 13:08:00 2010 CET",
	extension:  ".xml",
	path:       "./example/xml/test-default.xml",
	mimetype:   "text/xml",
	size:       7123,
}

func TestValidXML(t *testing.T) {
	result := getXMlData(&xmlData)
	assert.Equal(t, result.isWellFormed, true, "XML is well formed")
	assert.Equal(t, result.wellFormedErrors.Message, "", "Return empty if xml is not well formed")
	assert.Equal(t, result.wellFormedErrors.File, "", "Return empty if xml is not well formed")
	assert.Equal(t, result.doctype.Sysid, "Note.dtd", "Doctype is valid")
}

func TestInvalidXML(t *testing.T) {
	xmlData.path = "./example/xml/test-not-wellformed.xml"
	result := getXMlData(&xmlData)
	assert.Equal(t, result.isWellFormed, false, "XML is not well formed")
	assert.Equal(t, result.wellFormedErrors.File, xmlData.path)
	assert.Equal(t, result.doctype.Sysid, "", "Not get doctype if xml is invalid")
}