Debian Codegraph @

tfconfig/markdown_test.go

raw
1 // Copyright (c) HashiCorp, Inc.
2 // SPDX-License-Identifier: MPL-2.0
3
4 package tfconfig
5
6 import (
7 "bytes"
8 "io/ioutil"
9 "path/filepath"
10 "testing"
11
12 "github.com/go-test/deep"
13 )
14
15 func TestRenderMarkdown(t *testing.T) {
16 fixturesDir := "testdata"
17 testDirs, err := ioutil.ReadDir(fixturesDir)
18 if err != nil {
19 t.Fatal(err)
20 }
21
22 for _, info := range testDirs {
23 if !info.IsDir() {
24 continue
25 }
26
27 t.Run(info.Name(), func(t *testing.T) {
28 name := info.Name()
29 path := filepath.Join(fixturesDir, name)
30
31 fullPath := filepath.Join(path, name+".out.md")
32 expected, err := ioutil.ReadFile(fullPath)
33 if err != nil {
34 t.Skipf("%q not found, skipping test", fullPath)
35 }
36
37 module, _ := LoadModule(path)
38 if module == nil {
39 t.Fatalf("result object is nil; want a real object")
40 }
41
42 var b bytes.Buffer
43 buf := &b
44 err = RenderMarkdown(buf, module)
45 if err != nil {
46 t.Fatal(err)
47 }
48
49 if diff := deep.Equal(buf.String(), string(expected)); diff != nil {
50 for _, problem := range diff {
51 t.Errorf("%s", problem)
52 }
53 }
54 })
55 }
56 }