Execute executes a test case and returns an error if occurred Execute the docs at ../README.md if the code stops working for integration.
()
| 19 | // Execute executes a test case and returns an error if occurred |
| 20 | // Execute the docs at ../README.md if the code stops working for integration. |
| 21 | func (h *goIntegrationTest) Execute() error { |
| 22 | var crawledURLs []string |
| 23 | |
| 24 | options := &types.Options{ |
| 25 | MaxDepth: 1, |
| 26 | FieldScope: "rdn", |
| 27 | BodyReadSize: math.MaxInt, |
| 28 | RateLimit: 150, |
| 29 | Verbose: debug, |
| 30 | Strategy: queue.DepthFirst.String(), |
| 31 | OnResult: func(r output.Result) { |
| 32 | crawledURLs = append(crawledURLs, r.Request.URL) |
| 33 | }, |
| 34 | } |
| 35 | crawlerOptions, err := types.NewCrawlerOptions(options) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | defer func() { |
| 40 | if err := crawlerOptions.Close(); err != nil { |
| 41 | fmt.Printf("Error closing crawler options: %v\n", err) |
| 42 | } |
| 43 | }() |
| 44 | crawler, err := standard.New(crawlerOptions) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | defer func() { |
| 49 | if err := crawler.Close(); err != nil { |
| 50 | fmt.Printf("Error closing crawler: %v\n", err) |
| 51 | } |
| 52 | }() |
| 53 | var input = "https://public-firing-range.appspot.com" |
| 54 | err = crawler.Crawl(input) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | if len(crawledURLs) == 0 { |
| 59 | return fmt.Errorf("no URLs crawled") |
| 60 | } |
| 61 | return nil |
| 62 | } |