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

Function TestSnippetAcrossMultipleFiles

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

Source from the content-addressed store, hash-verified

829}
830
831func TestSnippetAcrossMultipleFiles(t *testing.T) {
832 // Make the derived Caddyfile that expects (common) to be defined.
833 fileName := writeStringToTempFileOrDie(t, `
834 http://example.com {
835 import common
836 }
837 `)
838
839 // Parse the root file that defines (common) and then imports the other one.
840 p := testParser(`
841 (common) {
842 gzip foo
843 }
844 import ` + fileName + `
845 `)
846
847 blocks, err := p.parseAll()
848 if err != nil {
849 t.Fatal(err)
850 }
851 if len(blocks) != 1 {
852 t.Fatalf("Expect exactly one server block. Got %d.", len(blocks))
853 }
854 if actual, expected := blocks[0].GetKeysText()[0], "http://example.com"; expected != actual {
855 t.Errorf("Expected server name to be '%s' but was '%s'", expected, actual)
856 }
857 if len(blocks[0].Segments) != 1 {
858 t.Fatalf("Server block should have tokens from import")
859 }
860 if actual, expected := blocks[0].Segments[0][0].Text, "gzip"; expected != actual {
861 t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
862 }
863}
864
865func TestRejectsGlobalMatcher(t *testing.T) {
866 p := testParser(`

Callers

nothing calls this directly

Calls 4

testParserFunction · 0.85
parseAllMethod · 0.80
GetKeysTextMethod · 0.80

Tested by

no test coverage detected