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

Function TestGetInstruction

internal/pkg/document/document_test.go:13–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestGetInstruction(t *testing.T) {
14 testCases := []struct {
15 name string
16 content string
17 positions []protocol.Position
18 found []bool
19 instructions []string
20 }{
21 {
22 name: "FROM alpine:3.16.1",
23 content: "FROM alpine:3.16.1",
24 positions: []protocol.Position{
25 {Line: 0, Character: 0},
26 {Line: 1, Character: 0},
27 },
28 found: []bool{
29 true, false,
30 },
31 instructions: []string{"FROM", ""},
32 },
33 }
34
35 for _, tc := range testCases {
36 t.Run(tc.name, func(t *testing.T) {
37 opts := WithReadDocumentFunc(func(uri.URI) ([]byte, error) {
38 return []byte(tc.content), nil
39 })
40 mgr := NewDocumentManager(opts)
41 doc, err := mgr.Read(context.Background(), "")
42 require.Nil(t, err)
43
44 for i := range tc.positions {
45 instruction := doc.(DockerfileDocument).Instruction(tc.positions[i])
46 if tc.found[i] {
47 require.NotNil(t, instruction)
48 require.Equal(t, tc.instructions[i], instruction.Value)
49 } else {
50 require.Nil(t, instruction)
51 }
52 }
53 })
54 }
55}
56
57func TestUpdate(t *testing.T) {
58 testCases := []struct {

Callers

nothing calls this directly

Calls 4

WithReadDocumentFuncFunction · 0.85
NewDocumentManagerFunction · 0.85
InstructionMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected