Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <pvala@redhat.com>
  • Loading branch information
valaparthvi committed Dec 27, 2022
1 parent 3913bde commit 79d7516
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions tests/helper/helper_documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 79d7516

Please sign in to comment.