MCPcopy Create free account
hub / github.com/docker/docker-language-server / testDefinition

Function testDefinition

internal/bake/hcl/definition_test.go:35–1572  ·  view source on GitHub ↗
(t *testing.T, dockerfilePath, backendDockerfilePath, bakeFilePath string)

Source from the content-addressed store, hash-verified

33}
34
35func testDefinition(t *testing.T, dockerfilePath, backendDockerfilePath, bakeFilePath string) {
36 dockerfilePath = filepath.ToSlash(dockerfilePath)
37 bakeFilePath = filepath.ToSlash(bakeFilePath)
38
39 dockerfileURI := fmt.Sprintf("file:///%v", strings.TrimPrefix(dockerfilePath, "/"))
40 bakeFileURI := fmt.Sprintf("file:///%v", strings.TrimPrefix(bakeFilePath, "/"))
41 backendDockerfileURI := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(backendDockerfilePath), "/"))
42
43 testCases := []struct {
44 name string
45 content string
46 line uint32
47 character uint32
48 endCharacter int
49 locations any
50 links any
51 }{
52 {
53 name: "reference valid stage with target attribute on the wrong character",
54 content: "target \"default\" {\ndockerfile = \"Dockerfile\"\ntarget = \"stage\" }",
55 line: 2,
56 character: 0, // point to the attribute's name instead of value
57 endCharacter: -1,
58 locations: nil,
59 links: nil,
60 },
61 {
62 name: "reference valid stage with target attribute on the wrong line",
63 content: "target \"default\" {\ndockerfile = \"Dockerfile\"\ntarget = \"stage\" }",
64 line: 1, // point to the dockerfile attribute instead of the target attribute
65 character: 13,
66 endCharacter: -1,
67 locations: nil,
68 links: nil,
69 },
70 {
71 name: "reference stage in a non-target attribute",
72 content: "target \"default\" {\n network = \"stage\"\n}",
73 line: 1,
74 character: 17,
75 endCharacter: -1,
76 locations: nil,
77 links: nil,
78 },
79 {
80 name: "reference stage in a variable block",
81 content: "variable \"var\" {\n target = \"stage\"\n}",
82 line: 1,
83 character: 17,
84 endCharacter: -1,
85 locations: nil,
86 links: nil,
87 },
88 {
89 name: "context attribute points to a declared variable",
90 content: "variable \"var\" {\n default = \"stageName\"\n}\ntarget \"default\" {\n context = var\n}",
91 line: 4,
92 character: 13,

Callers 1

TestDefinitionFunction · 0.85

Calls 4

NewDocumentManagerFunction · 0.92
NewBakeHCLDocumentFunction · 0.92
DefinitionFunction · 0.70
URIMethod · 0.65

Tested by

no test coverage detected