Skip to content

Commit f4e78fb

Browse files
committed
chore: add test case for #112
Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
1 parent f53715d commit f4e78fb

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

internal/provider/provider_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,48 @@
44
*/
55

66
package provider_test
7+
8+
import (
9+
"bufio"
10+
"os"
11+
"regexp"
12+
"strings"
13+
"testing"
14+
)
15+
16+
func TestProviderDocumentation(t *testing.T) {
17+
file, err := os.Open("../../docs/data-sources/external_secrets_io_cluster_secret_store_v1alpha1_manifest.md")
18+
if err != nil {
19+
t.Fatal(err)
20+
}
21+
defer file.Close()
22+
23+
linkPattern := regexp.MustCompile(`<a id="nestedatt--(?P<DashedPath>.*)"></a>`)
24+
titlePattern := regexp.MustCompile("### Nested Schema for `(?P<DottedPath>.*)`")
25+
expectedTitle := ""
26+
27+
scanner := bufio.NewScanner(file)
28+
for scanner.Scan() {
29+
line := scanner.Text()
30+
31+
link := linkPattern.FindStringSubmatch(line)
32+
title := titlePattern.FindStringSubmatch(line)
33+
34+
if len(link) > 0 {
35+
attributeIndex := linkPattern.SubexpIndex("DashedPath")
36+
attributeValue := link[attributeIndex]
37+
expectedTitle = strings.ReplaceAll(attributeValue, "--", ".")
38+
}
39+
if len(title) > 0 {
40+
pathIndex := titlePattern.SubexpIndex("DottedPath")
41+
pathValue := title[pathIndex]
42+
if expectedTitle != pathValue {
43+
t.Errorf("Wanted [%s] but got [%s]", expectedTitle, pathValue)
44+
}
45+
}
46+
}
47+
48+
if err := scanner.Err(); err != nil {
49+
t.Fatal(err)
50+
}
51+
}

0 commit comments

Comments
 (0)