forked from terraform-docs/terraform-docs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
testing.go
52 lines (40 loc) · 940 Bytes
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package doc
import (
"os"
"path/filepath"
"github.com/mitchellh/go-testing-interface"
)
// TestDoc creates a *Doc from a Terraform module.
func TestDoc(t testing.T, path string) *Doc {
path, err := absPath(testDataPath(path))
if err != nil {
t.Fatal(err)
}
doc, err := CreateFromPaths([]string{path})
if err != nil {
t.Fatal(err)
}
return doc
}
// TestDocFromFile creates a *Doc from a Terraform file.
func TestDocFromFile(t testing.T, path string, name string) *Doc {
path, err := absPath(filepath.Join(testDataPath(path), name))
if err != nil {
t.Fatal(err)
}
doc, err := CreateFromPaths([]string{path})
if err != nil {
t.Fatal(err)
}
return doc
}
func absPath(relative string) (string, error) {
pwd, err := os.Getwd()
if err != nil {
return "", err
}
return filepath.Join(pwd, relative), nil
}
func testDataPath(path string) string {
return filepath.Join(path, "..", "..", "..", "examples")
}