MCPcopy
hub / github.com/caddyserver/caddy / TestEnvironmentReplacement

Function TestEnvironmentReplacement

caddyconfig/caddyfile/parse_test.go:636–730  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

634}
635
636func TestEnvironmentReplacement(t *testing.T) {
637 os.Setenv("FOOBAR", "foobar")
638 os.Setenv("CHAINED", "$FOOBAR")
639
640 for i, test := range []struct {
641 input string
642 expect string
643 }{
644 {
645 input: "",
646 expect: "",
647 },
648 {
649 input: "foo",
650 expect: "foo",
651 },
652 {
653 input: "{$NOT_SET}",
654 expect: "",
655 },
656 {
657 input: "foo{$NOT_SET}bar",
658 expect: "foobar",
659 },
660 {
661 input: "{$FOOBAR}",
662 expect: "foobar",
663 },
664 {
665 input: "foo {$FOOBAR} bar",
666 expect: "foo foobar bar",
667 },
668 {
669 input: "foo{$FOOBAR}bar",
670 expect: "foofoobarbar",
671 },
672 {
673 input: "foo\n{$FOOBAR}\nbar",
674 expect: "foo\nfoobar\nbar",
675 },
676 {
677 input: "{$FOOBAR} {$FOOBAR}",
678 expect: "foobar foobar",
679 },
680 {
681 input: "{$FOOBAR}{$FOOBAR}",
682 expect: "foobarfoobar",
683 },
684 {
685 input: "{$CHAINED}",
686 expect: "$FOOBAR", // should not chain env expands
687 },
688 {
689 input: "{$FOO:default}",
690 expect: "default",
691 },
692 {
693 input: "foo{$BAR:bar}baz",

Callers

nothing calls this directly

Calls 2

replaceEnvVarsFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected