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

Function TestUpdate

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

Source from the content-addressed store, hash-verified

55}
56
57func TestUpdate(t *testing.T) {
58 testCases := []struct {
59 name string
60 content string
61 newContent string
62 hasNodes bool
63 instructionValue string
64 }{
65 {
66 name: "syntax error interrupts parsing",
67 content: "FROM alpine:3.16.1",
68 newContent: "FROM alpine:3.16.1\nRUN <<a",
69 hasNodes: false,
70 instructionValue: "",
71 },
72 {
73 name: "instruction completely changed",
74 content: "FROM alpine:3.16.1",
75 newContent: "ARG imageTag",
76 hasNodes: true,
77 instructionValue: "ARG",
78 },
79 }
80
81 for _, tc := range testCases {
82 t.Run(tc.name, func(t *testing.T) {
83 document := NewDocument(NewDocumentManager(), "", protocol.DockerfileLanguage, 1, []byte(tc.content))
84 document.Update(2, []byte(tc.newContent))
85 if tc.hasNodes {
86 require.Equal(t, tc.instructionValue, document.(DockerfileDocument).Nodes()[0].Value)
87 } else {
88 require.Len(t, document.(DockerfileDocument).Nodes(), 0)
89 }
90 })
91 }
92}
93
94func TestGetDecoder(t *testing.T) {
95 testCases := []struct {

Callers

nothing calls this directly

Calls 4

UpdateMethod · 0.95
NewDocumentFunction · 0.85
NewDocumentManagerFunction · 0.85
NodesMethod · 0.65

Tested by

no test coverage detected