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

Function TestSnippets

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

Source from the content-addressed store, hash-verified

760}
761
762func TestSnippets(t *testing.T) {
763 p := testParser(`
764 (common) {
765 gzip foo
766 errors stderr
767 }
768 http://example.com {
769 import common
770 }
771 `)
772 blocks, err := p.parseAll()
773 if err != nil {
774 t.Fatal(err)
775 }
776 if len(blocks) != 1 {
777 t.Fatalf("Expect exactly one server block. Got %d.", len(blocks))
778 }
779 if actual, expected := blocks[0].GetKeysText()[0], "http://example.com"; expected != actual {
780 t.Errorf("Expected server name to be '%s' but was '%s'", expected, actual)
781 }
782 if len(blocks[0].Segments) != 2 {
783 t.Fatalf("Server block should have tokens from import, got: %+v", blocks[0])
784 }
785 if actual, expected := blocks[0].Segments[0][0].Text, "gzip"; expected != actual {
786 t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
787 }
788 if actual, expected := blocks[0].Segments[1][1].Text, "stderr"; expected != actual {
789 t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
790 }
791}
792
793func writeStringToTempFileOrDie(t *testing.T, str string) (pathToFile string) {
794 file, err := os.CreateTemp("", t.Name())

Callers

nothing calls this directly

Calls 3

testParserFunction · 0.85
parseAllMethod · 0.80
GetKeysTextMethod · 0.80

Tested by

no test coverage detected