/
struct_markdown_test.go
51 lines (46 loc) · 1.49 KB
/
struct_markdown_test.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
package struct_markdown
import (
"fmt"
"io/ioutil"
"strings"
"testing"
. "github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc/internal/cmd"
)
func TestCommand_Run(t *testing.T) {
tests := []struct {
args []string
want int
FileCheck
}{
{
[]string{"../test-data/packer-plugin-happycloud/builder/happycloud/config.go"},
0,
FileCheck{
Expected: []string{
"../test-data/packer-plugin-happycloud/docs-partials/builder/happycloud/Config-not-required.mdx",
"../test-data/packer-plugin-happycloud/docs-partials/builder/happycloud/Config.mdx",
"../test-data/packer-plugin-happycloud/docs-partials/builder/happycloud/Config-required.mdx",
"../test-data/packer-plugin-happycloud/docs-partials/builder/happycloud/CustomerEncryptionKey-not-required.mdx",
"../test-data/packer-plugin-happycloud/docs-partials/builder/happycloud/CustomerEncryptionKey.mdx",
},
},
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s", tt.args), func(t *testing.T) {
defer tt.FileCheck.Cleanup(t)
cmd := &Command{}
if got := cmd.Run(tt.args); got != tt.want {
t.Errorf("CMD.Run() = %v, want %v", got, tt.want)
}
targetedPath := strings.TrimPrefix(tt.args[0], "../test-data/packer-plugin-happycloud/")
for _, p := range tt.FileCheck.ExpectedFiles() {
raw, _ := ioutil.ReadFile(p)
content := string(raw)
if !strings.Contains(content, targetedPath) {
t.Errorf("%s must contain '%s'. Its content is:\n%s", p, targetedPath, content)
}
}
})
}
}