MCPcopy Index your code
hub / github.com/databus23/helm-diff / TestPrepareStdinValues

Function TestPrepareStdinValues

cmd/local_test.go:259–326  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

257}
258
259func TestPrepareStdinValues(t *testing.T) {
260 l := &local{
261 valueFiles: valueFiles{"-", "-", "real-values.yaml"},
262 }
263
264 stdinContent := `key: stdin-value
265`
266 tmpStdin, err := os.CreateTemp("", "fake-stdin")
267 if err != nil {
268 t.Fatal(err)
269 }
270 defer os.Remove(tmpStdin.Name())
271 if _, err := tmpStdin.WriteString(stdinContent); err != nil {
272 t.Fatal(err)
273 }
274 if err := tmpStdin.Close(); err != nil {
275 t.Fatal(err)
276 }
277
278 oldStdin := os.Stdin
279 f, err := os.Open(tmpStdin.Name())
280 if err != nil {
281 t.Fatal(err)
282 }
283 os.Stdin = f
284 defer func() {
285 os.Stdin = oldStdin
286 f.Close()
287 }()
288
289 cleanup, err := l.prepareStdinValues()
290 if err != nil {
291 t.Fatalf("Expected no error but got: %v", err)
292 }
293 if cleanup == nil {
294 t.Fatal("Expected cleanup function but got nil")
295 }
296
297 if l.valueFiles[0] == "-" {
298 t.Error("Expected first valueFile to be replaced with temp file path")
299 }
300 if l.valueFiles[1] == "-" {
301 t.Error("Expected second valueFile to be replaced with temp file path")
302 }
303 if l.valueFiles[0] != l.valueFiles[1] {
304 t.Errorf("Expected both '-' entries to point to the same temp file, got %q and %q", l.valueFiles[0], l.valueFiles[1])
305 }
306 if _, err := os.Stat(l.valueFiles[0]); os.IsNotExist(err) {
307 t.Errorf("Expected temp file %q to exist", l.valueFiles[0])
308 }
309 if l.valueFiles[2] != "real-values.yaml" {
310 t.Errorf("Expected third valueFile to be unchanged, got %q", l.valueFiles[2])
311 }
312
313 data, err := os.ReadFile(l.valueFiles[0])
314 if err != nil {
315 t.Fatalf("Failed to read temp file: %v", err)
316 }

Callers

nothing calls this directly

Calls 1

prepareStdinValuesMethod · 0.95

Tested by

no test coverage detected