Ejemplo n.º 1
0
func TestLoadContentCorrectContentCountAccordingToFileEnding(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo3")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo2.markdown"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo3.m2"), test.ContentData)

	files := LoadContentData(pathToFolder)

	if len(files) != 2 {
		t.Error("expected 2 files but were : " + fmt.Sprintf("%v", len(files)))
	}
}
Ejemplo n.º 2
0
func TestLoadContentCorrectContentForData(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo4")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)

	files := LoadContentData(pathToFolder)

	if len(files) != 1 {
		t.Error("expected 1 files but were : " + fmt.Sprintf("%v", len(files)))
	}

	file := files[0]

	test.TestValues(t, test.ContentDataTitle, file.Title, "title not correctly loaded")

	if file.Date.Unix() != 1427236080 {
		t.Error("date not correctly loaded")
	}
	if len(file.Categories) != len(test.ContentDataCategories) {
		t.Error("category not correctly loaded")
	}
	if file.Categories[0] != test.ContentDataCategories[0] || file.Categories[1] != test.ContentDataCategories[1] {
		t.Error("category content not correctly loaded")
	}

	test.TestValues(t, test.ContentDataContent, file.Content, "content not correctly loaded")
}
Ejemplo n.º 3
0
func createContent(baseDir string) string {
	pathToFolder := filepath.Join(baseDir, "input")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo.md"), test.ContentData)

	return pathToFolder
}
Ejemplo n.º 4
0
func TestLoadContentMissingSeparator(t *testing.T) {
	alteredContent := strings.Replace(test.ContentData, "---", "", -1)
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo9")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredContent)

	testLoadContentDataExpectException("Content file must contain '---' to separate config data from content", pathToFolder, t)
}
Ejemplo n.º 5
0
func TestLoadContentMissingContentException(t *testing.T) {
	alteredContent := strings.Replace(test.ContentData, test.ContentDataContent, "", -1)
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo8")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredContent)

	testLoadContentDataExpectException("Content missing in content file", pathToFolder, t)
}
Ejemplo n.º 6
0
func TestLoadContentIncorrectDateException(t *testing.T) {
	alteredContent := strings.Replace(test.ContentData, test.ContentDataDate, "a"+test.ContentDataDate+"1", -1)
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo7")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredContent)

	testLoadContentDataExpectException("Incorrect format of date in content file", pathToFolder, t)
}
Ejemplo n.º 7
0
func TestLoadContentCorrectContentCountWithSubfolders(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo2")
	pathToFolder2 := filepath.Join(pathToFolder, "foo2")
	pathToFolder3 := filepath.Join(pathToFolder2, "foo2")
	pathToFolder4 := filepath.Join(pathToFolder3, "foo2")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestDirectory(pathToFolder2)
	test.CreateTestDirectory(pathToFolder3)
	test.CreateTestDirectory(pathToFolder4)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder2, "foo2.md"), test.ContentData)
	test.CreateTestFile(filepath.Join(pathToFolder4, "foo3.md"), test.ContentData)

	files := LoadContentData(pathToFolder)

	if len(files) != 3 {
		t.Error("expected 3 files but were : " + fmt.Sprintf("%v", len(files)))
	}
}
Ejemplo n.º 8
0
func TestCreateContent(t *testing.T) {
	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo66")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), test.ContentData)

	files := input.LoadContentData(pathToFolder)
	result := CreateContent(testConfigData, files[0])
	expected := "<p>2015-03-24 22:28</p></br>\n<h3>Old Pages</h3>\n<p>Old unsupported pages :</p>\n"

	if result != expected {
		fmt.Println("expected : '" + expected + "'")
		fmt.Println("result   : '" + result + "'")
		t.Error("incorrect created content")
	}
}
Ejemplo n.º 9
0
func TestCreateContentChangeVariousProperties(t *testing.T) {
	alteredCorrectData := strings.Replace(test.ContentData, "2015-03-24 22:28", "2015-03-24 22:29", -1)
	alteredCorrectData = strings.Replace(alteredCorrectData, "Old Pages", "New Pages", -1)
	alteredCorrectData = strings.Replace(alteredCorrectData, "Old unsupported pages :", "New supported pages :", -1)
	alteredTestConfigData := input.ConfigData{TitleType: "h2"}

	dirPath := test.GetTestPath()
	pathToFolder := filepath.Join(dirPath, "foo67")

	test.CreateTestDirectory(pathToFolder)
	test.CreateTestFile(filepath.Join(pathToFolder, "foo1.md"), alteredCorrectData)

	files := input.LoadContentData(pathToFolder)
	result := CreateContent(alteredTestConfigData, files[0])
	expected := "<p>2015-03-24 22:29</p></br>\n<h2>New Pages</h2>\n<p>New supported pages :</p>\n"

	if result != expected {
		fmt.Println("expected : '" + expected + "'")
		fmt.Println("result   : '" + result + "'")
		t.Error("incorrect created content")
	}
}
Ejemplo n.º 10
0
func createConfigFile(baseDir string) string {
	configDataPath := filepath.Join(baseDir, "configFile.yaml")
	test.CreateTestFile(configDataPath, test.ConfigDataContent)

	return configDataPath
}