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") }
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) }
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) }
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) }
func setupTestEnvironment(id string) (string, input.ConfigData, []input.ContentData) { baseDir := filepath.Join(test.GetTestPath(), "pageTest"+id) outputDirectory := filepath.Join(baseDir, "output") test.CreateTestDirectory(baseDir) test.CreateTestDirectory(outputDirectory) configDataPath := createConfigFile(baseDir) contentPath := createContent(baseDir) configData := input.CreateConfigData(configDataPath) elements := input.LoadContentData(contentPath) return outputDirectory, configData, elements }
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))) } }
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") } }
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))) } }
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") } }
func TestCheckFilePathForOutputFolderExists(t *testing.T) { filename := test.CreateTestFileReturnPath("validEnding.yaml", "") filename2 := test.CreateTestFileReturnPath("validEnding.html", "") workingDir := test.GetTestPath() testAndExpectPanic(filename, filename2, workingDir, filename+"sdf", "argument error - directory does not exist", t) }