Skip to content

Commit

Permalink
Fix file path in comments for windows (#105)
Browse files Browse the repository at this point in the history
* Test the content - this fails on windows

* Always use slashed for file path Fixes #104
  • Loading branch information
hmalphettes committed Apr 29, 2022
1 parent 3ceaa41 commit 2e22282
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/packer-sdc/internal/struct-markdown/struct_markdown.go
Expand Up @@ -80,6 +80,8 @@ func (cmd *Command) Run(args []string) int {
log.Fatalf("ParseFile: %+v", err)
}

canonicalFilePath := filepath.ToSlash(filePath)

for _, decl := range f.Decls {
typeDecl, ok := decl.(*ast.GenDecl)
if !ok {
Expand All @@ -96,23 +98,23 @@ func (cmd *Command) Run(args []string) int {

fields := structDecl.Fields.List
header := Struct{
SourcePath: filePath,
SourcePath: canonicalFilePath,
Name: typeSpec.Name.Name,
Filename: typeSpec.Name.Name + ".mdx",
Header: strings.TrimSpace(typeDecl.Doc.Text()),
}
dataSourceOutput := Struct{
SourcePath: filePath,
SourcePath: canonicalFilePath,
Name: typeSpec.Name.Name,
Filename: typeSpec.Name.Name + ".mdx",
}
required := Struct{
SourcePath: filePath,
SourcePath: canonicalFilePath,
Name: typeSpec.Name.Name,
Filename: typeSpec.Name.Name + "-required.mdx",
}
notRequired := Struct{
SourcePath: filePath,
SourcePath: canonicalFilePath,
Name: typeSpec.Name.Name,
Filename: typeSpec.Name.Name + "-not-required.mdx",
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/packer-sdc/internal/struct-markdown/struct_markdown_test.go
Expand Up @@ -2,6 +2,8 @@ package struct_markdown

import (
"fmt"
"io/ioutil"
"strings"
"testing"

. "github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc/internal/cmd"
Expand Down Expand Up @@ -35,6 +37,14 @@ func TestCommand_Run(t *testing.T) {
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)
}
}
})
}

Expand Down

0 comments on commit 2e22282

Please sign in to comment.