Skip to content

Commit 2e22282

Browse files
authored
Fix file path in comments for windows (#105)
* Test the content - this fails on windows * Always use slashed for file path Fixes #104
1 parent 3ceaa41 commit 2e22282

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

cmd/packer-sdc/internal/struct-markdown/struct_markdown.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func (cmd *Command) Run(args []string) int {
8080
log.Fatalf("ParseFile: %+v", err)
8181
}
8282

83+
canonicalFilePath := filepath.ToSlash(filePath)
84+
8385
for _, decl := range f.Decls {
8486
typeDecl, ok := decl.(*ast.GenDecl)
8587
if !ok {
@@ -96,23 +98,23 @@ func (cmd *Command) Run(args []string) int {
9698

9799
fields := structDecl.Fields.List
98100
header := Struct{
99-
SourcePath: filePath,
101+
SourcePath: canonicalFilePath,
100102
Name: typeSpec.Name.Name,
101103
Filename: typeSpec.Name.Name + ".mdx",
102104
Header: strings.TrimSpace(typeDecl.Doc.Text()),
103105
}
104106
dataSourceOutput := Struct{
105-
SourcePath: filePath,
107+
SourcePath: canonicalFilePath,
106108
Name: typeSpec.Name.Name,
107109
Filename: typeSpec.Name.Name + ".mdx",
108110
}
109111
required := Struct{
110-
SourcePath: filePath,
112+
SourcePath: canonicalFilePath,
111113
Name: typeSpec.Name.Name,
112114
Filename: typeSpec.Name.Name + "-required.mdx",
113115
}
114116
notRequired := Struct{
115-
SourcePath: filePath,
117+
SourcePath: canonicalFilePath,
116118
Name: typeSpec.Name.Name,
117119
Filename: typeSpec.Name.Name + "-not-required.mdx",
118120
}

cmd/packer-sdc/internal/struct-markdown/struct_markdown_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package struct_markdown
22

33
import (
44
"fmt"
5+
"io/ioutil"
6+
"strings"
57
"testing"
68

79
. "github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc/internal/cmd"
@@ -35,6 +37,14 @@ func TestCommand_Run(t *testing.T) {
3537
if got := cmd.Run(tt.args); got != tt.want {
3638
t.Errorf("CMD.Run() = %v, want %v", got, tt.want)
3739
}
40+
targetedPath := strings.TrimPrefix(tt.args[0], "../test-data/packer-plugin-happycloud/")
41+
for _, p := range tt.FileCheck.ExpectedFiles() {
42+
raw, _ := ioutil.ReadFile(p)
43+
content := string(raw)
44+
if !strings.Contains(content, targetedPath) {
45+
t.Errorf("%s must contain '%s'. Its content is:\n%s", p, targetedPath, content)
46+
}
47+
}
3848
})
3949
}
4050

0 commit comments

Comments
 (0)