MCPcopy Index your code
hub / github.com/keploy/keploy / readNextYAMLDocument

Method readNextYAMLDocument

pkg/platform/yaml/mockreader.go:125–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

123}
124
125func (r *MockReader) readNextYAMLDocument() ([]byte, error) {
126 var buffer bytes.Buffer
127 isFirstDoc := r.lineNum == 0
128
129 for {
130 select {
131 case <-r.ctx.Done():
132 return nil, r.ctx.Err()
133 default:
134 }
135
136 line, err := r.reader.ReadString('\n')
137 r.lineNum++
138
139 if err != nil {
140 if err == io.EOF {
141 r.done = true
142 if buffer.Len() > 0 {
143 return buffer.Bytes(), nil
144 }
145 return nil, io.EOF
146 }
147 return nil, fmt.Errorf("failed to read line %d: %w", r.lineNum, err)
148 }
149
150 trimmedLine := strings.TrimSpace(line)
151
152 if trimmedLine == "---" {
153 if buffer.Len() == 0 {
154 continue
155 }
156 return buffer.Bytes(), nil
157 }
158
159 if isFirstDoc && buffer.Len() == 0 && strings.HasPrefix(trimmedLine, "#") {
160 continue
161 }
162
163 buffer.WriteString(line)
164 }
165}
166
167// Format returns the format the reader is decoding. Callers can use this to
168// pick between ReadNextDoc (NetworkTrafficDoc with yaml.Node spec) and

Callers 1

ReadNextDocumentMethod · 0.95

Calls 1

BytesMethod · 0.45

Tested by

no test coverage detected