Skip to content

Commit 8a469c2

Browse files
committed
Fix completion_test.go tests on Windows
Due to Windows paths having drive letters and having backslashes, completion_test.go was not passing. Replacing path.Join with filepath.Join and ensuring URIs are created properly fixes the problem. Signed-off-by: Remy Suen <[email protected]>
1 parent c126b0d commit 8a469c2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

internal/bake/hcl/completion_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path"
88
"path/filepath"
9+
"strings"
910
"testing"
1011

1112
"github.com/docker/docker-language-server/internal/pkg/document"
@@ -340,9 +341,15 @@ func TestCompletion(t *testing.T) {
340341
},
341342
}
342343

343-
bakeFilePath := path.Join(completionTestFolderPath, "docker-bake.hcl")
344-
bakeFileURI := uri.URI(fmt.Sprintf("file://%v", bakeFilePath))
345-
dockerfileURI := uri.URI(fmt.Sprintf("file://%v", path.Join(completionTestFolderPath, "Dockerfile")))
344+
bakeFilePath := filepath.Join(completionTestFolderPath, "docker-bake.hcl")
345+
bakeFilePath = filepath.ToSlash(bakeFilePath)
346+
347+
dockerfilePath := filepath.Join(completionTestFolderPath, "Dockerfile")
348+
dockerfilePath = filepath.ToSlash(dockerfilePath)
349+
350+
bakeFileURI := uri.URI(fmt.Sprintf("file:///%v", strings.TrimPrefix(bakeFilePath, "/")))
351+
dockerfileURI := uri.URI(fmt.Sprintf("file:///%v", strings.TrimPrefix(dockerfilePath, "/")))
352+
346353
for _, tc := range testCases {
347354
t.Run(tc.name, func(t *testing.T) {
348355
manager := document.NewDocumentManager()

internal/bake/hcl/definition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func ParseDockerfile(dockerfilePath string) ([]byte, *parser.Result, error) {
377377
}
378378

379379
func OpenDockerfile(ctx context.Context, manager *document.Manager, path string) ([]byte, []*parser.Node) {
380-
doc := manager.Get(ctx, uri.URI(fmt.Sprintf("file://%v", path)))
380+
doc := manager.Get(ctx, uri.URI(fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(path), "/"))))
381381
if doc != nil {
382382
if dockerfile, ok := doc.(document.DockerfileDocument); ok {
383383
return dockerfile.Input(), dockerfile.Nodes()

0 commit comments

Comments
 (0)