(t *testing.T)
| 760 | } |
| 761 | |
| 762 | func 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 | |
| 793 | func writeStringToTempFileOrDie(t *testing.T, str string) (pathToFile string) { |
| 794 | file, err := os.CreateTemp("", t.Name()) |
nothing calls this directly
no test coverage detected