(t *testing.T)
| 476 | } |
| 477 | |
| 478 | func Test_getVariablesFromOptions(t *testing.T) { |
| 479 | genFile := func(s string) string { |
| 480 | f, err := os.CreateTemp("", "gh-env.*") |
| 481 | if err != nil { |
| 482 | t.Fatal(err) |
| 483 | return "" |
| 484 | } |
| 485 | defer f.Close() |
| 486 | t.Cleanup(func() { |
| 487 | _ = os.Remove(f.Name()) |
| 488 | }) |
| 489 | _, err = f.WriteString(s) |
| 490 | if err != nil { |
| 491 | t.Fatal(err) |
| 492 | } |
| 493 | return f.Name() |
| 494 | } |
| 495 | |
| 496 | tests := []struct { |
| 497 | name string |
| 498 | opts SetOptions |
| 499 | isTTY bool |
| 500 | stdin string |
| 501 | want map[string]string |
| 502 | wantErr bool |
| 503 | }{ |
| 504 | { |
| 505 | name: "variable from arg", |
| 506 | opts: SetOptions{ |
| 507 | VariableName: "FOO", |
| 508 | Body: "bar", |
| 509 | }, |
| 510 | want: map[string]string{"FOO": "bar"}, |
| 511 | }, |
| 512 | { |
| 513 | name: "variable from stdin", |
| 514 | opts: SetOptions{ |
| 515 | Body: "", |
| 516 | EnvFile: "-", |
| 517 | }, |
| 518 | stdin: `FOO=bar`, |
| 519 | want: map[string]string{"FOO": "bar"}, |
| 520 | }, |
| 521 | { |
| 522 | name: "variables from file", |
| 523 | opts: SetOptions{ |
| 524 | Body: "", |
| 525 | EnvFile: genFile(heredoc.Doc(` |
| 526 | FOO=bar |
| 527 | QUOTED="my value" |
| 528 | #IGNORED=true |
| 529 | export SHELL=bash |
| 530 | `)), |
| 531 | }, |
| 532 | stdin: `FOO=bar`, |
| 533 | want: map[string]string{ |
| 534 | "FOO": "bar", |
| 535 | "SHELL": "bash", |
nothing calls this directly
no test coverage detected