@@ -2,6 +2,10 @@ package compose
22
33import (
44 "context"
5+ "fmt"
6+ "os"
7+ "path/filepath"
8+ "strings"
59 "testing"
610
711 "github.com/docker/docker-language-server/internal/pkg/document"
@@ -11,6 +15,12 @@ import (
1115)
1216
1317func TestDocumentLink (t * testing.T ) {
18+ testsFolder := filepath .Join (os .TempDir (), "composeDocumentLinkTests" )
19+ composeFilePath := filepath .Join (testsFolder , "docker-compose.yml" )
20+ referencedFilePath := filepath .Join (testsFolder , "file.yml" )
21+ composeStringURI := fmt .Sprintf ("file:///%v" , strings .TrimPrefix (filepath .ToSlash (composeFilePath ), "/" ))
22+ referencedFileStringURI := fmt .Sprintf ("file:///%v" , strings .TrimPrefix (filepath .ToSlash (referencedFilePath ), "/" ))
23+
1424 testCases := []struct {
1525 name string
1626 content string
@@ -26,8 +36,8 @@ func TestDocumentLink(t *testing.T) {
2636 Start : protocol.Position {Line : 1 , Character : 4 },
2737 End : protocol.Position {Line : 1 , Character : 12 },
2838 },
29- Target : types .CreateStringPointer ("file:///home/user/file.yml" ),
30- Tooltip : types .CreateStringPointer ("/home/user/file.yml" ),
39+ Target : types .CreateStringPointer (referencedFileStringURI ),
40+ Tooltip : types .CreateStringPointer (referencedFilePath ),
3141 },
3242 },
3343 },
@@ -36,7 +46,7 @@ func TestDocumentLink(t *testing.T) {
3646 for _ , tc := range testCases {
3747 t .Run (tc .name , func (t * testing.T ) {
3848 doc := document .NewComposeDocument ("docker-compose.yml" , 1 , []byte (tc .content ))
39- links , err := DocumentLink (context .Background (), "file:///home/user/docker-compose.yml.hcl" , doc )
49+ links , err := DocumentLink (context .Background (), composeStringURI , doc )
4050 require .NoError (t , err )
4151 require .Equal (t , tc .links , links )
4252 })
0 commit comments