From 79d7516daada058a88b71f56aa53f79f1933508a Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Tue, 27 Dec 2022 20:31:19 +0530 Subject: [PATCH] Cleanup Signed-off-by: Parthvi Vala --- tests/helper/helper_documentation.go | 73 ---------------------------- 1 file changed, 73 deletions(-) diff --git a/tests/helper/helper_documentation.go b/tests/helper/helper_documentation.go index 354a56155e8..2ffa9234dd3 100644 --- a/tests/helper/helper_documentation.go +++ b/tests/helper/helper_documentation.go @@ -19,79 +19,6 @@ const ( unicodeSpinnerFrames = "◓◐◑◒" ) -// CompareDocOutput compares the output from test and the mdx file line by line; -// it ignores the time output if any is present in the line -// the function returns a list strings missing from the cmd out and from the file along with an error -// TODO: make cmdOut string same as mdx and compare them both -// TODO: can pass static values of time(can be something else as well) and pattern as defined in mdx while comparing -func CompareDocOutput(cmdOut string, filePath string) (stringsMissingFromCmdOut, stringsMissingFromFile []string, err error) { - // store lines of the cmdOut in this map - var got = map[string]struct{}{} - for _, line := range strings.Split(cmdOut, "\n") { - // trim any space present at the beginning or end of a line - line = strings.TrimFunc(line, unicode.IsSpace) - if strings.Contains(line, "...") || line == "" { - continue - } - - line = removeTimeIfExists(line) - got[line] = struct{}{} - } - - mdxDir := func() string { - // filename of this file - _, filename, _, _ := runtime.Caller(0) - // path to the docs directory - return filepath.Join(filepath.Dir(filename), "..", "..", "docs", "website", "docs") - }() - - readFile, err := os.Open(filepath.Join(mdxDir, filePath)) - if err != nil { - return nil, nil, err - } - defer readFile.Close() - - fileScanner := bufio.NewScanner(readFile) - - fileScanner.Split(bufio.ScanLines) - - for fileScanner.Scan() { - // trim any space present at the beginning or end of a line - line := strings.TrimFunc(fileScanner.Text(), unicode.IsSpace) - - // ignore the line that starts with: 1) a code block "```", 2) the command "$", or 3) an empty line - if strings.Contains(line, "```") || strings.Contains(line, "$") || line == "" || strings.Contains(line, "...") { - continue - } - - line = removeTimeIfExists(line) - - // check if the line can be retrieved from the cmdOut map - if _, ok := got[line]; !ok { - stringsMissingFromFile = append(stringsMissingFromFile, line) - } else { - delete(got, line) - } - } - - for line := range got { - stringsMissingFromCmdOut = append(stringsMissingFromCmdOut, line) - } - - return stringsMissingFromCmdOut, stringsMissingFromFile, nil -} - -// removeTimeIfExists removes time string from a line -// e.g. of a time string: [4s], [1m], [3ms] -func removeTimeIfExists(line string) string { - // check if a line has time data by checking for closing bracket of [4s] - if hasTimeDataInLine := strings.HasSuffix(line, "]"); !hasTimeDataInLine { - return line - } - reg := regexp.MustCompile(timePatternInOdo) - return reg.ReplaceAllString(line, "") -} - func ReplaceTimeInString(docString string, timeString string) string { reg := regexp.MustCompile(timePatternInOdo) return reg.ReplaceAllString(docString, timeString)