Created
February 17, 2021 10:01
-
-
Save lockwooddev/4a457ed823c30fb511ca025a3e3f2dab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var robots = ` | |
| # Group 1 | |
| User-agent: Googlebot | |
| Disallow: /nogooglebot/ | |
| # Group 2 | |
| User-agent: * | |
| Allow: / | |
| Sitemap: http://www.example.com/sitemap.xml | |
| Sitemap: http://www.example.com/sitemap2.xml | |
| ` | |
| func TestRobotsClient_Httptest(t *testing.T) { | |
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintln(w, robots) | |
| })) | |
| defer ts.Close() | |
| client := NewRobotsClient() | |
| robotRules, err := client.FetchRobots(ts.URL) | |
| assert.NoError(t, err) | |
| fmt.Println(robotRules) | |
| expectedRobotRules := RobotRules{ | |
| rules: []Rule{ | |
| { | |
| UserAgents: []string{"Googlebot"}, | |
| Disallow: []string{"/nogooglebot/"}, | |
| }, | |
| { | |
| UserAgents: []string{"*"}, | |
| Allow: []string{"/"}, | |
| }, | |
| }, | |
| Sitemaps: []string{ | |
| "http://www.example.com/sitemap.xml", | |
| "http://www.example.com/sitemap2.xml", | |
| }, | |
| } | |
| assert.Equal(t, expectedRobotRules, robotRules) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment