@@ -2,15 +2,23 @@ package hcl
22
33import (
44 "context"
5+ "fmt"
6+ "os"
7+ "path/filepath"
58 "testing"
69
710 "github.com/docker/docker-language-server/internal/pkg/document"
811 "github.com/docker/docker-language-server/internal/tliron/glsp/protocol"
912 "github.com/docker/docker-language-server/internal/types"
1013 "github.com/stretchr/testify/require"
14+ "go.lsp.dev/uri"
1115)
1216
1317func TestCodeLens (t * testing.T ) {
18+ testsFolder := filepath .Join (os .TempDir (), "codeLensTests" )
19+ bakeFilePath := filepath .Join (testsFolder , "docker-bake.hcl" )
20+ uriString := fmt .Sprintf ("file:///%v" , filepath .ToSlash (bakeFilePath ))
21+
1422 testCases := []struct {
1523 name string
1624 content string
@@ -38,7 +46,7 @@ func TestCodeLens(t *testing.T) {
3846 map [string ]string {
3947 "call" : "build" ,
4048 "target" : "first" ,
41- "cwd" : "/tmp" ,
49+ "cwd" : testsFolder ,
4250 },
4351 },
4452 },
@@ -55,7 +63,7 @@ func TestCodeLens(t *testing.T) {
5563 map [string ]string {
5664 "call" : "check" ,
5765 "target" : "first" ,
58- "cwd" : "/tmp" ,
66+ "cwd" : testsFolder ,
5967 },
6068 },
6169 },
@@ -72,7 +80,7 @@ func TestCodeLens(t *testing.T) {
7280 map [string ]string {
7381 "call" : "print" ,
7482 "target" : "first" ,
75- "cwd" : "/tmp" ,
83+ "cwd" : testsFolder ,
7684 },
7785 },
7886 },
@@ -95,7 +103,7 @@ func TestCodeLens(t *testing.T) {
95103 map [string ]string {
96104 "call" : "build" ,
97105 "target" : "g1" ,
98- "cwd" : "/tmp" ,
106+ "cwd" : testsFolder ,
99107 },
100108 },
101109 },
@@ -112,7 +120,7 @@ func TestCodeLens(t *testing.T) {
112120 map [string ]string {
113121 "call" : "check" ,
114122 "target" : "g1" ,
115- "cwd" : "/tmp" ,
123+ "cwd" : testsFolder ,
116124 },
117125 },
118126 },
@@ -129,7 +137,7 @@ func TestCodeLens(t *testing.T) {
129137 map [string ]string {
130138 "call" : "print" ,
131139 "target" : "g1" ,
132- "cwd" : "/tmp" ,
140+ "cwd" : testsFolder ,
133141 },
134142 },
135143 },
@@ -144,8 +152,8 @@ func TestCodeLens(t *testing.T) {
144152
145153 for _ , tc := range testCases {
146154 t .Run (tc .name , func (t * testing.T ) {
147- doc := document .NewBakeHCLDocument ("file:///tmp/docker-bake.hcl" , 1 , []byte (tc .content ))
148- codeLens , err := CodeLens (context .Background (), "file:///tmp/docker-bake.hcl" , doc )
155+ doc := document .NewBakeHCLDocument (uri . URI ( uriString ) , 1 , []byte (tc .content ))
156+ codeLens , err := CodeLens (context .Background (), uriString , doc )
149157 require .NoError (t , err )
150158 require .Equal (t , tc .codeLens , codeLens )
151159 })
0 commit comments