func Benchmark(b *testing.B) { tests, data, err := loadTestFile("testdata/benchmark.txt") if err != nil { b.Fatal(err) } robots := robots.New(bytes.NewReader(data), "foo") b.ResetTimer() j := 0 for i := 0; i < b.N; i++ { if robots.Allow(tests[j].Path) != tests[j].Allow { b.Fatal("benchmark failed") } j = (j + 1) % len(tests) } }
func runTest(t *testing.T, path string) { tests, data, err := loadTestFile(path) if err != nil { t.Fatal(err) } t.Logf("running file %s: %d tests", path, len(tests)) userAgents := make(map[string]*robots.Robots) for _, test := range tests { if _, ok := userAgents[test.UserAgent]; !ok { userAgents[test.UserAgent] = robots.New(bytes.NewReader(data), test.UserAgent) } } for _, test := range tests { if userAgents[test.UserAgent].Allow(test.Path) != test.Allow { t.Errorf("test %v failed", test) } } }